3
\$\begingroup\$

I am rendering shadow maps to cubemaps (just rendering raw depth buffer) then projecting them to the scene to do omni-directional shadow mapping.
The cubemap is sampled by the light direction vector on each fragment:

float3 lightvector = pos3D.xyz-lightPos.xyz;
float shadowmap = xTextureSh.Sample(Sampler,lightvector).r;

If I compare the shadowmap value to the lightvector length which is the distance from the fragment to the light, I get wrong results because that distance is in world space units, whereas the shadowmap values are not, they are normalized values.
My question is, how could I normalize the length of the light vector the same way the shadow map is normalized? I don't access the shadow view matrix in the fragment shader to do a W division on it, because I would need to send 6 matrices there and I switched to cubemaps exactly to avoid that. I do know hovewer the far clip distance to the shadow cameras, if it counts.

Previously I tried to multiply the shadow map value with the camera far clip distance reading this presentation (on the 30th page), but had no luck. What am I missing?

\$\endgroup\$
1
\$\begingroup\$

I couldn't find a way to do this, I write the distance instead in SV_DEPTH so I can compare the values. It requires a few additional constants so it is not as nice as I wanted it to be, so I am still interested in case anyone could solve this an other way.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.