@@ -124,37 +124,23 @@ void main()
124124 ao,
125125 NoV);
126126
127- uint cascadeIndex = 0 ;
128- for (uint i = 0 ; i < SHADOW_MAP_CASCADE_COUNT - 1 ; ++ i)
129- {
130- if (viewPos.z < shadowUBO.splitDepths[i])
131- {
132- cascadeIndex = i + 1 ;
133- }
134- }
127+
128+ // Obtaining the cascadeIndex below is optimized for SHADOW_MAP_CASCADE_COUNT = 4
129+ vec4 res = step (viewPos.z, shadowUBO.splitDepths);
130+ uint cascadeIndex = uint (res.x + res.y + res.z + res.w);
135131
136132 vec4 shadowPos = biasMat * shadowUBO.lightSpaceMatrices[cascadeIndex] * vec4 (worldPos, 1.0 );
137133
138134 float shadow = ShadowPCF(shadowPos / shadowPos.w, cascadeIndex);
139-
140135 vec3 color = ambient + emissive + (Lo * shadow);
141- // vec3 color = ambient + emissive + (Lo);
142-
143136 fragColor = vec4 (color, 1.0 );
144137
145- /* switch (cascadeIndex)
138+ // For debugging
139+ switch (cascadeIndex)
146140 {
147- case 0:
148- fragColor.rgb *= vec3(1.0f, 0.25f, 0.25f);
149- break;
150- case 1:
151- fragColor.rgb *= vec3(0.25f, 1.0f, 0.25f);
152- break;
153- case 2:
154- fragColor.rgb *= vec3(0.25f, 0.25f, 1.0f);
155- break;
156- case 3:
157- fragColor.rgb *= vec3(1.0f, 0.25f, 0.25f);
158- break;
159- }*/
141+ case 0 : fragColor.rgb *= vec3 (1 .0f, 0 .25f, 0 .25f); break ;
142+ case 1 : fragColor.rgb *= vec3 (0 .25f, 1 .0f, 0 .25f); break ;
143+ case 2 : fragColor.rgb *= vec3 (0 .25f, 0 .25f, 1 .0f); break ;
144+ case 3 : fragColor.rgb *= vec3 (1 .0f, 0 .25f, 0 .25f); break ;
145+ }
160146}
0 commit comments