1
1
#feature OUTLINE_PASS
2
2
#feature PICKING_PASS
3
- #feature DYNAMIC_SUN_POSITION
3
+ #feature DISABLE_TRACKING
4
4
5
5
#shader vertex
6
6
#version 450 core
@@ -14,38 +14,55 @@ out VS_OUT
14
14
{
15
15
vec3 FragPos;
16
16
flat vec3 SunPosition;
17
+ flat float SunIntensity;
17
18
} vs_out;
18
19
20
+ struct SunInfo
21
+ {
22
+ vec3 position;
23
+ float intensity;
24
+ };
25
+
19
26
uniform vec3 u_SunPosition = vec3(0.0, 0.1, -1.0); // Default sun position
27
+ uniform float u_SunIntensity = 22.0; // Sun intensity
20
28
21
- // Calculate the sun position based on the first directional light in the scene
22
- vec3 calculateSunPositionFromDirectionalLight()
29
+ SunInfo getSunInfo()
23
30
{
31
+ #if !defined(DISABLE_TRACKING)
32
+ // Calculate the sun position based on the first directional light in the scene
24
33
for (int i = 0; i < ssbo_Lights.length(); ++i)
25
34
{
26
35
const mat4 light = ssbo_Lights[i];
27
36
const int lightType = int(light[3][0]);
28
37
29
38
if (lightType == 1)
30
39
{
31
- vec3 lightDirection = -light[1].xyz;
32
- return normalize(lightDirection);
40
+ const vec3 lightDirection = -light[1].xyz;
41
+ const float lightIntensity = light[3][3];
42
+
43
+ return SunInfo(
44
+ normalize(lightDirection),
45
+ u_SunIntensity * lightIntensity
46
+ );
33
47
}
34
48
}
49
+ #endif
35
50
36
- // If no directional light is found, use the sun position uniform
37
- return u_SunPosition;
51
+ // If no directional light is found, use the provided settings as-is
52
+ return SunInfo(
53
+ u_SunPosition,
54
+ u_SunIntensity
55
+ );
38
56
}
39
57
40
58
void main()
41
59
{
42
60
vs_out.FragPos = geo_Pos;
43
61
44
- #if defined(DYNAMIC_SUN_POSITION)
45
- vs_out.SunPosition = calculateSunPositionFromDirectionalLight();
46
- #else
47
- vs_out.SunPosition = u_SunPosition;
48
- #endif
62
+ SunInfo sunInfo = getSunInfo();
63
+
64
+ vs_out.SunPosition = sunInfo.position;
65
+ vs_out.SunIntensity = sunInfo.intensity;
49
66
50
67
gl_Position = ubo_Projection * ubo_View * vec4(ubo_ViewPos + vs_out.FragPos, 1.0);
51
68
}
@@ -59,6 +76,7 @@ in VS_OUT
59
76
{
60
77
vec3 FragPos;
61
78
flat vec3 SunPosition;
79
+ flat float SunIntensity;
62
80
} fs_in;
63
81
64
82
#if defined(PICKING_PASS)
@@ -69,7 +87,6 @@ uniform vec4 _PickingColor;
69
87
uniform vec4 _OutlineColor;
70
88
#endif
71
89
72
- uniform float u_SunIntensity = 22.0; // Sun intensity
73
90
uniform float u_MiePreferredScatteringDirection = 0.758; // Mie preferred scattering direction
74
91
75
92
const vec3 kRayOrigin = vec3(0.0, 6372e3, 0.0); // Ray origin
@@ -207,7 +224,7 @@ void main()
207
224
normalize(fs_in.FragPos), // normalized ray direction
208
225
kRayOrigin, // ray origin
209
226
fs_in.SunPosition, // position of the sun
210
- u_SunIntensity, // intensity of the sun
227
+ fs_in.SunIntensity, // intensity of the sun
211
228
kPlanetRadius, // radius of the planet in meters
212
229
kAtmosphereRadius, // radius of the atmosphere in meters
213
230
kRayleighScattering, // Rayleigh scattering coefficient
0 commit comments