I am trying to get a simple depth shadow mapping algorithm incorporated into my surface lighting shader (2x2 percentage closer filtering). My engine performs an initial depth-only pass, rendering from the light's perspective, then uses the depth map as a shader resource for the next lighting pass. The scene that I have set up is just the classic teapot model with
a directional light. What I'm getting is the model looks split through
the center along a plane perpendicular to the direction of the light.
The side facing the light receives the regular surface lighting. The
other side is totally black. There is no shadow casting occurring, only
the split between surface lighting and black. No shadow-casting between different parts of the model occurs. As far as I can tell, the shader code for the PCF function is ok (I followed the Direct3D9 sample for shadow mapping):
#define DEPTH_MAP_SIZE 800 // size in texels (assume a 1:1 aspect ratio)
#define SHADOW_EPSILON 0.00005f
SamplerState SamShadow
{
Filter = MIN_MAG_MIP_POINT;
AddressU = Clamp;
AddressV = Clamp;
};
float PCF_Filter( Texture2D txDepthMap, float3 coords ) // coords.xy = light's projection space (x,y), coords.z = light's proj space z / w
{
float2 texelPos = coords.xy * DEPTH_MAP_SIZE;
float2 lerps = frac( texelPos );
float offset = 1.0f/DEPTH_MAP_SIZE;
float sourceDepths[4];
sourceDepths[0] = txDepthMap.Sample( SamShadow, coords.xy ) + SHADOW_EPSILON;
sourceDepths[1] = txDepthMap.Sample( SamShadow, coords.xy + float2(offset,0)) + SHADOW_EPSILON;
sourceDepths[2] = txDepthMap.Sample( SamShadow, coords.xy + float2(0,offset)) + SHADOW_EPSILON;
sourceDepths[3] = txDepthMap.Sample( SamShadow, coords.xy + float2(offset,offset)) + SHADOW_EPSILON;
float sourceValues[4];
sourceValues[0] = (sourceDepths[0] < coords.z)? 0.0f : 1.0f;
sourceValues[1] = (sourceDepths[1] < coords.z)? 0.0f : 1.0f;
sourceValues[2] = (sourceDepths[2] < coords.z)? 0.0f : 1.0f;
sourceValues[3] = (sourceDepths[3] < coords.z)? 0.0f : 1.0f;
//iterpolate the source values
float lightAmount = lerp( lerp(sourceValues[0], sourceValues[1], lerps.x),
lerp(sourceValues[2], sourceValues[3], lerps.x),
lerps.y );
return lightAmount;
}
In my BRDF lighting function, lightAmount is multiplied by the final pixel color (r,g,b) right before fresnel reflectivity is applied. Is this an issue with the light projection space depth values? Or am I overlooking something? Plz help!