Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCC Ricers

Posted 20 September 2012 - 09:24 PM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :
....

PS :
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 Posted Image


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[1], it also follows that linearZ > cascadeDistances[0] 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.

#1CC Ricers

Posted 20 September 2012 - 09:23 PM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :
....

PS :
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 Posted Image


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.

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[1], it also follows that linearZ > cascadeDistances[0] 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.

PARTNERS