Skip to content

Commit 08f9cba

Browse files
authored
Merge pull request #98614 from DarioSamo/soft-shadow-samples-fix
Fix soft shadows by increasing the bit count for specialization constants.
2 parents a308047 + 427ba09 commit 08f9cba

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ class SceneShaderForwardClustered {
108108
uint32_t projector_use_mipmaps : 1;
109109
uint32_t use_depth_fog : 1;
110110
uint32_t use_lightmap_bicubic_filter : 1;
111-
uint32_t soft_shadow_samples : 4;
112-
uint32_t penumbra_shadow_samples : 4;
113-
uint32_t directional_soft_shadow_samples : 4;
114-
uint32_t directional_penumbra_shadow_samples : 4;
111+
uint32_t soft_shadow_samples : 6;
112+
uint32_t penumbra_shadow_samples : 6;
113+
uint32_t directional_soft_shadow_samples : 6;
114+
uint32_t directional_penumbra_shadow_samples : 6;
115115
};
116116

117117
uint32_t packed_0;

servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ void SceneShaderForwardMobile::ShaderData::_create_pipeline(PipelineKey p_pipeli
322322
specialization_constants.push_back(sc);
323323

324324
sc.constant_id = 1;
325-
sc.float_value = p_pipeline_key.shader_specialization.packed_1;
325+
sc.int_value = p_pipeline_key.shader_specialization.packed_1;
326+
sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT;
327+
specialization_constants.push_back(sc);
328+
329+
sc.constant_id = 2;
330+
sc.float_value = p_pipeline_key.shader_specialization.packed_2;
326331
sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT;
327332
specialization_constants.push_back(sc);
328333

servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,23 @@ class SceneShaderForwardMobile {
7474
uint32_t use_depth_fog : 1;
7575
uint32_t is_multimesh : 1;
7676
uint32_t use_lightmap_bicubic_filter : 1;
77-
uint32_t pad : 2;
78-
uint32_t soft_shadow_samples : 4;
79-
uint32_t penumbra_shadow_samples : 4;
80-
uint32_t directional_soft_shadow_samples : 4;
81-
uint32_t directional_penumbra_shadow_samples : 4;
77+
uint32_t soft_shadow_samples : 6;
78+
uint32_t penumbra_shadow_samples : 6;
79+
uint32_t directional_soft_shadow_samples : 6;
8280
};
8381

8482
uint32_t packed_0;
8583
};
8684

8785
union {
88-
float luminance_multiplier;
89-
float packed_1;
86+
uint32_t directional_penumbra_shadow_samples : 6;
87+
uint32_t packed_1;
9088
};
9189

92-
uint32_t packed_2;
90+
union {
91+
float luminance_multiplier;
92+
float packed_2;
93+
};
9394
};
9495

9596
struct UbershaderConstants {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ bool sc_use_lightmap_bicubic_filter() {
107107
}
108108

109109
uint sc_soft_shadow_samples() {
110-
return (sc_packed_0() >> 8) & 15U;
110+
return (sc_packed_0() >> 8) & 63U;
111111
}
112112

113113
uint sc_penumbra_shadow_samples() {
114-
return (sc_packed_0() >> 12) & 15U;
114+
return (sc_packed_0() >> 14) & 63U;
115115
}
116116

117117
uint sc_directional_soft_shadow_samples() {
118-
return (sc_packed_0() >> 16) & 15U;
118+
return (sc_packed_0() >> 20) & 63U;
119119
}
120120

121121
uint sc_directional_penumbra_shadow_samples() {
122-
return (sc_packed_0() >> 20) & 15U;
122+
return (sc_packed_0() >> 26) & 63U;
123123
}
124124

125125
float sc_luminance_multiplier() {

servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile_inc.glsl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ layout(push_constant, std430) uniform DrawCall {
2222
uint pad;
2323
#ifdef UBERSHADER
2424
uint sc_packed_0;
25-
float sc_packed_1;
26-
uint sc_packed_2;
25+
uint sc_packed_1;
26+
float sc_packed_2;
2727
uint uc_packed_0;
2828
#endif
2929
}
@@ -42,10 +42,14 @@ uint sc_packed_0() {
4242
return draw_call.sc_packed_0;
4343
}
4444

45-
float sc_packed_1() {
45+
uint sc_packed_1() {
4646
return draw_call.sc_packed_1;
4747
}
4848

49+
float sc_packed_2() {
50+
return draw_call.sc_packed_2;
51+
}
52+
4953
uint uc_cull_mode() {
5054
return (draw_call.uc_packed_0 >> 0) & 3U;
5155
}
@@ -54,16 +58,21 @@ uint uc_cull_mode() {
5458

5559
// Pull the constants from the pipeline's specialization constants.
5660
layout(constant_id = 0) const uint pso_sc_packed_0 = 0;
57-
layout(constant_id = 1) const float pso_sc_packed_1 = 2.0;
61+
layout(constant_id = 1) const uint pso_sc_packed_1 = 0;
62+
layout(constant_id = 2) const float pso_sc_packed_2 = 2.0;
5863

5964
uint sc_packed_0() {
6065
return pso_sc_packed_0;
6166
}
6267

63-
float sc_packed_1() {
68+
uint sc_packed_1() {
6469
return pso_sc_packed_1;
6570
}
6671

72+
float sc_packed_2() {
73+
return pso_sc_packed_2;
74+
}
75+
6776
#endif
6877

6978
bool sc_use_light_projector() {
@@ -123,23 +132,23 @@ bool sc_use_lightmap_bicubic_filter() {
123132
}
124133

125134
uint sc_soft_shadow_samples() {
126-
return (sc_packed_0() >> 16) & 15U;
135+
return (sc_packed_0() >> 14) & 63U;
127136
}
128137

129138
uint sc_penumbra_shadow_samples() {
130-
return (sc_packed_0() >> 20) & 15U;
139+
return (sc_packed_0() >> 20) & 63U;
131140
}
132141

133142
uint sc_directional_soft_shadow_samples() {
134-
return (sc_packed_0() >> 24) & 15U;
143+
return (sc_packed_0() >> 26) & 63U;
135144
}
136145

137146
uint sc_directional_penumbra_shadow_samples() {
138-
return (sc_packed_0() >> 28) & 15U;
147+
return (sc_packed_1() >> 0) & 63U;
139148
}
140149

141150
float sc_luminance_multiplier() {
142-
return sc_packed_1();
151+
return sc_packed_2();
143152
}
144153

145154
/* Set 0: Base Pass (never changes) */

0 commit comments

Comments
 (0)