Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualriuthamus

Posted 13 February 2013 - 05:24 PM

We have been trying to get cascaded shadow maps working from MJP's sample but I can't seem to get it working right. All I get is a diagonal area of shadow across the ground regardless of which direction I look or where the light is. From my debugging of the shader, it seems like the problem is that the shader that builds the occlusion map is sampling the cascade map from the wrong point. I've gone over the code several times and can't see what would be causing the issue.

 

gallery_1_8_26705.png

gallery_1_8_189040.png


This is the part of the shader that calculates the texture coordinate which seems to be wrong:
 

// Reconstruct
view-space position from the depth buffer
float pixelDepth =
DepthMap.Sample(DepthMapSampler, input.TexCoord).r;
float4 position =
float4(pixelDepth * input.FrustumCornerVS, 1.0f);

// Determine the depth
of the pixel with respect to the light
float4x4 inverseLVP = mul(InverseView,
lightViewProjection);
float4 positionLight = mul(position,
inverseLVP);

float lightDepth = (positionLight.z /
positionLight.w);

// Transform from light space to shadow map texture
space.
float2 shadowTexCoord = 0.5 * positionLight.xy / positionLight.w +
float2(0.5f, 0.5f);
shadowTexCoord.x = shadowTexCoord.x / SPLITS +
offset;
shadowTexCoord.y = 1.0f - shadowTexCoord.y;

// Offset the
coordinate by half a texel so we sample it correctly
shadowTexCoord += (0.5f
/ ShadowMapSize);

 

Any help with this would be greatly appreciated, thanks in advance.


#2riuthamus

Posted 13 February 2013 - 05:18 PM

We have been trying to get cascaded shadow maps working from MJP's sample but I can't seem to get it working right. All I get is a diagonal area of shadow across the ground regardless of which direction I look or where the light is. From my debugging of the shader, it seems like the problem is that the shader that builds the occusion map is sampling the cascade map from the wrong point. I've gone over the code several times and can't see what would be causing the issue.

This is the part of the shader that calculates the texture coordinate which seems to be wrong:
 

// Reconstruct
view-space position from the depth buffer
float pixelDepth =
DepthMap.Sample(DepthMapSampler, input.TexCoord).r;
float4 position =
float4(pixelDepth * input.FrustumCornerVS, 1.0f);

// Determine the depth
of the pixel with respect to the light
float4x4 inverseLVP = mul(InverseView,
lightViewProjection);
float4 positionLight = mul(position,
inverseLVP);

float lightDepth = (positionLight.z /
positionLight.w);

// Transform from light space to shadow map texture
space.
float2 shadowTexCoord = 0.5 * positionLight.xy / positionLight.w +
float2(0.5f, 0.5f);
shadowTexCoord.x = shadowTexCoord.x / SPLITS +
offset;
shadowTexCoord.y = 1.0f - shadowTexCoord.y;

// Offset the
coordinate by half a texel so we sample it correctly
shadowTexCoord += (0.5f
/ ShadowMapSize);

 

Any help with this would be greatly appreciated, thanks in advance.


#1riuthamus

Posted 13 February 2013 - 05:17 PM

We have been trying to get cascaded shadow maps working from MJP's sample but I can't seem to get it working right. All I get is a diagonal
area of shadow across the ground regardless of which direction I look or where the light is. From my debugging of the shader, it seems like the problem is that the shader that builds the occusion map is sampling the cascade map from the wrong point. I've gone over the code several times and can't see what would be causing the issue.

This is the part of the shader that calculates the texture coordinate which seems to be wrong:

// Reconstruct
view-space position from the depth buffer
float pixelDepth =
DepthMap.Sample(DepthMapSampler, input.TexCoord).r;
float4 position =
float4(pixelDepth * input.FrustumCornerVS, 1.0f);

// Determine the depth
of the pixel with respect to the light
float4x4 inverseLVP = mul(InverseView,
lightViewProjection);
float4 positionLight = mul(position,
inverseLVP);

float lightDepth = (positionLight.z /
positionLight.w);

// Transform from light space to shadow map texture
space.
float2 shadowTexCoord = 0.5 * positionLight.xy / positionLight.w +
float2(0.5f, 0.5f);
shadowTexCoord.x = shadowTexCoord.x / SPLITS +
offset;
shadowTexCoord.y = 1.0f - shadowTexCoord.y;

// Offset the
coordinate by half a texel so we sample it correctly
shadowTexCoord += (0.5f
/ ShadowMapSize);

 

Any help with this would be greatly appreciated, thanks in advance.


PARTNERS