Skip to content

Commit 7fbf15b

Browse files
authored
Updated atmoshperic scattering implementation to also track directional light intensity (#522)
1 parent 407c9bb commit 7fbf15b

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

Resources/Engine/Materials/Atmosphere.ovmat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
</value>
3232
</uniform>
3333
</uniforms>
34-
<features>DYNAMIC_SUN_POSITION</features>
34+
<features></features>
3535
</root>

Resources/Engine/Shaders/Atmosphere.ovfx

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#feature OUTLINE_PASS
22
#feature PICKING_PASS
3-
#feature DYNAMIC_SUN_POSITION
3+
#feature DISABLE_TRACKING
44

55
#shader vertex
66
#version 450 core
@@ -14,38 +14,55 @@ out VS_OUT
1414
{
1515
vec3 FragPos;
1616
flat vec3 SunPosition;
17+
flat float SunIntensity;
1718
} vs_out;
1819

20+
struct SunInfo
21+
{
22+
vec3 position;
23+
float intensity;
24+
};
25+
1926
uniform vec3 u_SunPosition = vec3(0.0, 0.1, -1.0); // Default sun position
27+
uniform float u_SunIntensity = 22.0; // Sun intensity
2028

21-
// Calculate the sun position based on the first directional light in the scene
22-
vec3 calculateSunPositionFromDirectionalLight()
29+
SunInfo getSunInfo()
2330
{
31+
#if !defined(DISABLE_TRACKING)
32+
// Calculate the sun position based on the first directional light in the scene
2433
for (int i = 0; i < ssbo_Lights.length(); ++i)
2534
{
2635
const mat4 light = ssbo_Lights[i];
2736
const int lightType = int(light[3][0]);
2837

2938
if (lightType == 1)
3039
{
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+
);
3347
}
3448
}
49+
#endif
3550

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+
);
3856
}
3957

4058
void main()
4159
{
4260
vs_out.FragPos = geo_Pos;
4361

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;
4966

5067
gl_Position = ubo_Projection * ubo_View * vec4(ubo_ViewPos + vs_out.FragPos, 1.0);
5168
}
@@ -59,6 +76,7 @@ in VS_OUT
5976
{
6077
vec3 FragPos;
6178
flat vec3 SunPosition;
79+
flat float SunIntensity;
6280
} fs_in;
6381

6482
#if defined(PICKING_PASS)
@@ -69,7 +87,6 @@ uniform vec4 _PickingColor;
6987
uniform vec4 _OutlineColor;
7088
#endif
7189

72-
uniform float u_SunIntensity = 22.0; // Sun intensity
7390
uniform float u_MiePreferredScatteringDirection = 0.758; // Mie preferred scattering direction
7491

7592
const vec3 kRayOrigin = vec3(0.0, 6372e3, 0.0); // Ray origin
@@ -207,7 +224,7 @@ void main()
207224
normalize(fs_in.FragPos), // normalized ray direction
208225
kRayOrigin, // ray origin
209226
fs_in.SunPosition, // position of the sun
210-
u_SunIntensity, // intensity of the sun
227+
fs_in.SunIntensity, // intensity of the sun
211228
kPlanetRadius, // radius of the planet in meters
212229
kAtmosphereRadius, // radius of the atmosphere in meters
213230
kRayleighScattering, // Rayleigh scattering coefficient

Sources/Overload/OvEditor/src/OvEditor/Panels/AssetBrowser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ namespace
490490
material.SetDepthWriting(false);
491491
material.SetBackfaceCulling(false);
492492
material.SetFrontfaceCulling(true);
493-
material.AddFeature("DYNAMIC_SUN_POSITION");
494493
});
495494

496495
BrowserItemContextualMenu::CreateList();

0 commit comments

Comments
 (0)