Thanks, it solved the problem
If you want to have a look on my HLSL colored csm sampling functions that use it :
g_CSM_depths[split].x is the minimal depth of the #split map, g_CSM_depths[split+1].x is the maximal depth of the #split map.
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome
Instead of using if statements while looping through split indices get the correct split index by adding up conditional statements for all the split tests. This does away with the need for branching.
For instance, here is what I use for my single-pass CSM function:
cascadeDistances[NUM_CASCADES]; // In the pixel shader splitIndex = 0; for (int i = 0; i < NUM_CASCADES; i++) splitIndex += (linearZ > cascadeDistances[i]); // Get shadow map position projected in light view float4 shadowMapPos = mul(position, lightViewProj[splitIndex]);
Here, linear Z depth is a value between the near and far world unit distances of the entire view frustum, not the splits. The cascadeDistances array is the list of far split planes in world units, listed from smallest to greatest. If linearZ > cascadeDistances, it also follows that linearZ > cascadeDistances is true, therefore splitIndex is 2.
SplitIndex will always be less than the number of cascades, because cascadeDistances[n] is the farthest depth in the view, which linearZ will always be less than.