My problem is that not a single pixel ends up lit. If I turn the logic that determines if a pixel should get lit (dist1 < dist2) around (dist1 > dist2), everything is lit, not a single pixel lies in the shadow.
The shadow map is a cube map that I create with the following properties:
D3DXCreateCubeTexture ( window->GetDevice ( ), 1024, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R32F, D3DPOOL_DEFAULT, &shadow_map );
This is what one of the six faces of my shadow map looks like:
Screenshot taken with the help of NVidia's PerfHUD tool...
I simply take the z-component of the pixel in screen-space in the pixel shader and divide it by the far plane (which is the light's radius) in order to create my shadow map. I'm aware of the fact that most implementations don't store linear depth like that for precision reasons, but I'm not quite there yet. That looks correct to me, the other faces of the shadow map look okay like that as well.
Now, this is what I do in the shader I use when I render a sphere as a point light (which works 100% fine for diffuse and specular lighting - just the shadows won't work):
[source lang="cpp"]
texture tex_shadow;
samplerCUBE smp_shadow = sampler_state
{
Texture = <tex_shadow>;
AddressU = CLAMP;
AddressV = CLAMP;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};
// ...
// in the pixel shader:
// both world_position and light_position are float3s and in world space, they are both used to calculate diffuse and
// specular lighting before these lines so I know they are fine and they are not altered in any way throughout the shader
float3 light_to_pixel = world_position - light_position;
float shadow_map_depth = texCUBE ( smp_shadow, normalize ( light_to_pixel ) ).r;
float shadow_factor = length ( light_to_pixel ) < ( shadow_map_depth + 0.05f );
[/source]
I got that code snippet from a post by MJP around here somewhere I believe. I understand the method behind it.
This is how I send the shadow (cube) map to the point light shader:
shader_point_light->effect->SetTexture ( "tex_shadow", shadow_map );
Note 1: 0.05f is a random shadow bias guess, -0.05f as well as different values do not make a difference. But, if I add a very high value to shadow_map_depth such as 50.0f, I get this result:
This leads me to believe shadow_map_depth (ie. the call to texCUBE) might always return 0 for all pixels maybe?
NOTE 2: Unfortunately, PIX (which I would usually use to debug shaders) is crashing on me every time I click "Debug Pixel Shader" in a pixel's history. It used to work fine for me [s]until I took an arrow to the knee [/s]but now for whatever reason it doesn't anymore. I am not aware of any other means of debugging shaders. I am running the d3d9 debug libraries on maximum level and I don't have any functions failing or any other relevant reports!
Any ideas what could be going wrong here? I have read and followed several papers on the matter but have not found a solution to my problem so far. What am I missing? If there's something more you need or want to see, let me know and I'll post it! Thanks ahead of time as always!