From 4357506e64784f84ada8d84caade8172a4f89a79 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 15 Oct 2020 21:59:08 +0200 Subject: Fix "fixed" fog drawing in front of volumetric fog with a sky background This closes #42820. Co-authored-by: Clay John --- .../rasterizer_rd/shaders/scene_high_end.glsl | 18 ++++++++++-------- servers/rendering/rasterizer_rd/shaders/sky.glsl | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl b/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl index e11f3983c5..be34473892 100644 --- a/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl +++ b/servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl @@ -2726,14 +2726,15 @@ FRAGMENT_SHADER_CODE specular_buffer = vec4(specular_light, metallic); #endif - if (scene_data.volumetric_fog_enabled) { - vec4 fog = volumetric_fog_process(screen_uv, -vertex.z); + // Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky. + if (scene_data.fog_enabled) { + vec4 fog = fog_process(vertex); diffuse_buffer.rgb = mix(diffuse_buffer.rgb, fog.rgb, fog.a); specular_buffer.rgb = mix(specular_buffer.rgb, vec3(0.0), fog.a); } - if (scene_data.fog_enabled) { - vec4 fog = fog_process(vertex); + if (scene_data.volumetric_fog_enabled) { + vec4 fog = volumetric_fog_process(screen_uv, -vertex.z); diffuse_buffer.rgb = mix(diffuse_buffer.rgb, fog.rgb, fog.a); specular_buffer.rgb = mix(specular_buffer.rgb, vec3(0.0), fog.a); } @@ -2747,13 +2748,14 @@ FRAGMENT_SHADER_CODE //frag_color = vec4(1.0); #endif //USE_NO_SHADING - if (scene_data.volumetric_fog_enabled) { - vec4 fog = volumetric_fog_process(screen_uv, -vertex.z); + // Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky. + if (scene_data.fog_enabled) { + vec4 fog = fog_process(vertex); frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a); } - if (scene_data.fog_enabled) { - vec4 fog = fog_process(vertex); + if (scene_data.volumetric_fog_enabled) { + vec4 fog = volumetric_fog_process(screen_uv, -vertex.z); frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a); } diff --git a/servers/rendering/rasterizer_rd/shaders/sky.glsl b/servers/rendering/rasterizer_rd/shaders/sky.glsl index 7b6de6a555..7711f683ae 100644 --- a/servers/rendering/rasterizer_rd/shaders/sky.glsl +++ b/servers/rendering/rasterizer_rd/shaders/sky.glsl @@ -223,13 +223,14 @@ FRAGMENT_SHADER_CODE #if !defined(DISABLE_FOG) && !defined(USE_CUBEMAP_PASS) - if (scene_data.volumetric_fog_enabled) { - vec4 fog = volumetric_fog_process(uv); + // Draw "fixed" fog before volumetric fog to ensure volumetric fog can appear in front of the sky. + if (scene_data.fog_enabled) { + vec4 fog = fog_process(cube_normal); frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a); } - if (scene_data.fog_enabled) { - vec4 fog = fog_process(cube_normal); + if (scene_data.volumetric_fog_enabled) { + vec4 fog = volumetric_fog_process(uv); frag_color.rgb = mix(frag_color.rgb, fog.rgb, fog.a); } -- cgit v1.2.3