Jump to content
  • Advertisement
Sign in to follow this  
Aqua Costa

PCSS problem

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive implemented CSM with PCSS but there is a problem with it:

csm.png
I still have some improvements to do but I wanted to fix this error first...

Shader code:

SHADOW_EPSILON = 0.003f
SMAP_DX = 1.0f / 1024.0f;

float4 positionWS = float4(gEyePosW + pIn.viewRay * depth, 1.0f);

positionLightHS = mul(positionWS, gLightView);

for(int x = 0; x < 5; x++)
{
if(depth * 10000 <= gCascadesEnd[x])
{
positionLightHS = mul(positionLightHS, gLightProj[x]);
positionLightHS.xyz /= positionLightHS.w;
positionLightHS.xy = positionLightHS.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
positionLightHS.x /= 4;
float2 cascadeOffset = float2((x/4.0f), 0.0f);
positionLightHS.xy += cascadeOffset;

break;
}
}

float depthS = positionLightHS.z;

// Sample shadow map to get nearest depth to light.
float s0 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy).r;
float s1 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX, 0)).r;
float s2 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, SMAP_DX)).r;
float s3 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX, SMAP_DX)).r;
float s4 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX, 0)).r;
float s5 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, -SMAP_DX)).r;
float s6 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX, SMAP_DX)).r;
float s7 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX, -SMAP_DX)).r;
float s8 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX, -SMAP_DX)).r;

// Is the pixel depth <= shadow map value?
float result0 = depthS <= s0 + SHADOW_EPSILON;
float result1 = depthS <= s1 + SHADOW_EPSILON;
float result2 = depthS <= s2 + SHADOW_EPSILON;
float result3 = depthS <= s3 + SHADOW_EPSILON;
float result4 = depthS <= s4 + SHADOW_EPSILON;
float result5 = depthS <= s5 + SHADOW_EPSILON;
float result6 = depthS <= s6 + SHADOW_EPSILON;
float result7 = depthS <= s7 + SHADOW_EPSILON;
float result8 = depthS <= s8 + SHADOW_EPSILON;
shadowFactor = (result0 + result1 + result2 + result3 + result4 + result5 + result6 + result7 + result8) / 9;


Any idead about what might be causing that aliasing?

Share this post


Link to post
Share on other sites
Advertisement
Well I fixed it with a little change in the shader...

Since I'm using a cascaded shadow map with 4 cascades, when I sample the shadow map I must divide the shadow map texel size by the number of cascades, but just on the x coordinate...
So:

float s0 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy).r;
float s1 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, 0)).r;
float s2 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, SMAP_DX)).r;
float s3 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, SMAP_DX)).r;
float s4 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, 0)).r;
float s5 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, -SMAP_DX)).r;
float s6 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, SMAP_DX)).r;
float s7 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, -SMAP_DX)).r;
float s8 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, -SMAP_DX)).r;

Share this post


Link to post
Share on other sites
Hidden

Well I fixed it with a little change in the shader...

Since I'm using a cascaded shadow map with 4 cascades, when I sample the shadow map I must divide the shadow map texel size by the number of cascades, but just on the x coordinate...
So:

float s0 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy).r;
float s1 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, 0)).r;
float s2 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, SMAP_DX)).r;
float s3 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, SMAP_DX)).r;
float s4 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, 0)).r;
float s5 = gShadowMap.Sample(gTriPointSam, positionLightHS + float2(0, -SMAP_DX)).r;
float s6 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, SMAP_DX)).r;
float s7 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(SMAP_DX/4, -SMAP_DX)).r;
float s8 = gShadowMap.Sample(gTriPointSam, positionLightHS.xy + float2(-SMAP_DX/4, -SMAP_DX)).r;

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!