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?