Skip to content

Commit b1ea48d

Browse files
authored
Merge pull request #99536 from lawnjelly/faster_shadow_fade
[3.x] Ameliorate performance regression due to directional shadow `fade_start`
2 parents f75abbb + 4c930bb commit b1ea48d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/gles3/rasterizer_scene_gles3.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,10 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform
27992799
const float fade_start = li->light_ptr->param[VS::LIGHT_PARAM_SHADOW_FADE_START];
28002800
// Using 1.0 would break `smoothstep()` in the shader.
28012801
ubo_data.fade_from = -ubo_data.shadow_split_offsets[shadow_count - 1] * MIN(fade_start, 0.999);
2802-
ubo_data.fade_to = -ubo_data.shadow_split_offsets[shadow_count - 1];
2802+
2803+
// To prevent the need for a fade to, store the fade to in the final split offset.
2804+
// It will either be the same as before, or the maximum split offset.
2805+
ubo_data.shadow_split_offsets[3] = ubo_data.shadow_split_offsets[shadow_count - 1];
28032806
}
28042807

28052808
glBindBuffer(GL_UNIFORM_BUFFER, state.directional_ubo);

drivers/gles3/rasterizer_scene_gles3.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
592592
float shadow_split_offsets[4];
593593

594594
float fade_from;
595-
float fade_to;
596-
float pad[2];
595+
float pad[3];
597596
};
598597

599598
struct LightInstance : public RID_Data {

drivers/gles3/shaders/scene.glsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ layout(std140) uniform DirectionalLightData { //ubo:3
148148
mediump vec4 shadow_split_offsets;
149149

150150
mediump float fade_from;
151-
mediump float fade_to;
152-
mediump vec2 pad;
151+
mediump vec3 pad;
153152
};
154153

155154
#endif //ubershader-skip
@@ -848,8 +847,7 @@ layout(std140) uniform DirectionalLightData {
848847
mediump vec4 shadow_split_offsets;
849848

850849
mediump float fade_from;
851-
mediump float fade_to;
852-
mediump vec2 pad;
850+
mediump vec3 pad;
853851
};
854852

855853
uniform highp sampler2DShadow directional_shadow; // texunit:-5
@@ -2292,7 +2290,7 @@ FRAGMENT_SHADER_CODE
22922290
shadow = min(shadow, contact_shadow);
22932291
}
22942292
#endif //ubershader-runtime
2295-
float pssm_fade = smoothstep(fade_from, fade_to, vertex.z);
2293+
float pssm_fade = smoothstep(fade_from, -shadow_split_offsets.w, vertex.z);
22962294
light_attenuation = mix(mix(shadow_color_contact.rgb, vec3(1.0), shadow), vec3(1.0), pssm_fade);
22972295
}
22982296

0 commit comments

Comments
 (0)