For point lights, you can't use the depth for comparision. Quadratic distance from the light source works well here and is just as fast. Be sure to set up proper view and projection matrices when rendering into the shadow map. FOV should be exactly 90°, width-to-height-relation exactly 1.0f, direction and up vectors as described in the (DX/OGL) docs. No need for projected cubemap lookup, a simple cubemap lookup will do. Just be sure to scale down the distance so it stays inside the 0..1 range.
Example shaders could look like this:
Shadow pass, Vertex Shader
...// transform vertex positionvout.position = mul( MODELVIEWPROJ, vin.position);// scaled vertex position is also light vectorvout.shadowdir = vout.position * (1 / YOUR_LIGHT_RANGE);...
And the pixel shader calculates the shadow depth from that direction vector
float4 ps( const PixelIn pin) : COLOR0{ // store quadratic distance to surface in the shadow map. return dot( pin.shadowdir, pin.shadowdir);}
You might possibly run into precision problem when using a simple A8R8G8B8 texture. R32F or R16F, if available, work fine.
The scene vertex shader part is simple:
...// transform light dir into tangent space. // Just keep the (scaled) length of the vector for depth comparision.vout.lightdir = mul( worldToTangentSpace, (worldPos - LIGHTPOS) * (1 / YOUR_LIGHT_RANGE));...
The comparision in the pixel shader is straight forward then:
... // fetch shadow distance from cubemap float shadowDistance = texCUBE( TexShadow, pin.lightdir); // compare against quadratic length of the light vector float shadow_term = (shadowDistance > dot( pin.lightdir, pin.lightdir)) ? 1.0f : 0.0f; ...
That's all about it. Good luck.
Bye, Thomas
[edit] Format, comments.