Hi guys, I'm trying to get simple shadow mapping working before I move on to percentage-closer and/or variance methods. I can't seem to get it to work so first I want to make sure I'm making the map correctly.
Here is the pertinent code:
d3d_device->CreateDepthStencilSurface(512,512,D3DFMT_D16,D3DMULTISAMPLE_NONE,0,TRUE,&shadow_depth_surface,NULL);
d3d_device->CreateTexture(512,512,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&shadow_texture,NULL);
D3DXVECTOR3 eye(0.0f, 8.0f, 0.0f);
D3DXVECTOR3 look(8.0f, 0.0f, 8.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&shadow_view_matrix,&eye,&look,&up);
D3DXMatrixPerspectiveFovLH(&shadow_projection_matrix, pi/2.0f, 1.0f, 1.0f, 100.0f);
D3DXMatrixMultiply(&shadow_world_view_projection,&shadow_view_matrix,&shadow_projection_matrix);
Here is the shader:
VS_OUTPUT vertexShader(VS_INPUT input)
{
VS_OUTPUT output;
output.position=mul(input.position,WorldViewProjection);
output.depth=output.position.zw;
return output;
}
float4 pixelShader(VS_OUTPUT input) : COLOR
{
float d=input.depth.x/input.depth.y;
return float4(d,d,d,1);
}
The shadow map seems alright but it's mostly white. Am I using the correct formats when I create the depth surface and texture ? The near clipping value in the projection matrix is very sensitive and makes a huge difference in how the map looks, it's not very satisfying.
I don't think my problem is with the map generation but I want to make sure it's correct before asking about the rest of the algorithm.
Thanks a lot.