I have been searching the web for days for an answer to this, but I apparently cannot find what I need to, or I am overlooking the answer and not knowing it.
I have the issue of projective-aliasing happening with the terrain in my game, and apparently I need to use a slope-scale bias as well to calculate the shadow.
I know that the algorithm is:
m*SLOPESCALE + DEPTHBIAS
\Where m = max( | ?z/?x | , | ?z/?y | )
But apparently I am uncertain how to implement this inside of an HLSL shader. I already use a depth bias, I just need to compute the slope-scale bias as well.
Here is my code:
To render the shadow map:
technique Technique0Shadow
{
pass Pass0
{
Lighting = False;
CullMode = NONE;
VertexShader = compile vs_2_0 VS_Shadow();
PixelShader = compile ps_2_0 PS_Shadow();
}
}
shadowType VS_Shadow( vertex IN )
{
shadowType OUT;
OUT.position = mul( worldViewProj, float4(IN.position, 1) );
OUT.fDepth.z = OUT.position.z;
return OUT;
}
pixel PS_Shadow( shadowType IN )
{
pixel OUT;
OUT.color = float4(IN.fDepth.z,IN.fDepth.z,IN.fDepth.z,1.0f);
return OUT;
} And here is the HLSL code for rendering the shadow onto the terrain ( edited for simplicity )
Vertex Shader:
fragment TerrainVS_Shadow( vertex IN )
{
fragment OUT;
OUT.color = float4(IN.color.r,IN.color.g,IN.color.b,IN.color.a);
OUT.hposition = mul( worldViewProj, float4(IN.position, 1) );
OUT.vProjCoord = mul( float4(IN.position, 1), g_matTexture );
OUT.vProjCoord2 = mul( float4(IN.position, 1), g_matTexture2 );
float4 posWorld = mul(float4(IN.position, 1), worldMat);
OUT.distCalc = posWorld;
return OUT;
} pixel shader, the depth bias is 0.0005f;
pixel TerrainPS_Shadow( fragment IN )
{
pixel OUT;
if ( IN.vProjCoord.x/IN.vProjCoord.w < 1.0f && IN.vProjCoord.x/IN.vProjCoord.w > 0.0f && IN.vProjCoord.y/IN.vProjCoord.w < 1.0f && IN.vProjCoord.y/IN.vProjCoord.w > 0.0f )
{
fShadowTerm = tex2Dproj( ShadowSampler, IN.vProjCoord ) < (IN.vProjCoord.z - 0.005f) ? 0.4f : 1.0f;
}
OUT.color = float4(0,0,0,fShadowTerm );
return OUT;
} My question is, how do I implement the slope-scale bias into my code as well? How do I add the equation: m*SLOPESCALE + DEPTHBIAS as the overall bias so I can eliminate my projective-aliasing?
Thanks for any info you can give!