Skip to content

Commit bdbbed8

Browse files
committed
Revise fog blending to fix over-darkening/borders.
This can result in low fog densities being a bit brighter, which may need slight adjustment in your scenes. In exchange, volumetrics now blend smoothly together with the scene and regular fog. Fixes godotengine#101514
1 parent 084d5d4 commit bdbbed8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

servers/rendering/renderer_rd/shaders/environment/sky.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void main() {
281281

282282
if (sky_scene_data.volumetric_fog_enabled) {
283283
vec4 fog = volumetric_fog_process(uv);
284-
frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a * sky_scene_data.volumetric_fog_sky_affect);
284+
frag_color.rgb = frag_color.rgb * (1.0 - fog.a * sky_scene_data.volumetric_fog_sky_affect) + fog.rgb * sky_scene_data.volumetric_fog_sky_affect;
285285
}
286286

287287
if (custom_fog.a > 0.0) {

servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,20 +1443,21 @@ void fragment_shader(in SceneData scene_data) {
14431443
#else
14441444
vec4 volumetric_fog = volumetric_fog_process(screen_uv, -vertex.z);
14451445
#endif
1446+
vec4 res = vec4(0.0);
14461447
if (bool(scene_data.flags & SCENE_DATA_FLAGS_USE_FOG)) {
14471448
//must use the full blending equation here to blend fogs
1448-
vec4 res;
14491449
float sa = 1.0 - volumetric_fog.a;
14501450
res.a = fog.a * sa + volumetric_fog.a;
1451-
if (res.a == 0.0) {
1452-
res.rgb = vec3(0.0);
1453-
} else {
1454-
res.rgb = (fog.rgb * fog.a * sa + volumetric_fog.rgb * volumetric_fog.a) / res.a;
1451+
if (res.a > 0.0) {
1452+
res.rgb = (fog.rgb * fog.a * sa + volumetric_fog.rgb) / res.a;
14551453
}
1456-
fog = res;
14571454
} else {
1458-
fog = volumetric_fog;
1455+
res.a = volumetric_fog.a;
1456+
if (res.a > 0.0) {
1457+
res.rgb = volumetric_fog.rgb / res.a;
1458+
}
14591459
}
1460+
fog = res;
14601461
}
14611462
#endif //!CUSTOM_FOG_USED
14621463

0 commit comments

Comments
 (0)