Fast algorithm to get distance to the light

My fragment shader changes z coordinate of the fragment.
In order to implement shadows I need to get distance to the light source from that new fragment position.
Anyone has an idea how to do that not putting to much stress on GPU ?

Actually, this is strange. Shadow buffers (usually) use a world space position transformed to light projection space, but this is calculated per vertex and passed as a texture coordinate. If you want to modify your depth, that means that you modify your geometry position when rendering the depth buffer, correct? If that is not the case, you need not modify the distance to the light.

Anyhow, to answer to your question, a simple solution is defer the world space position by your fragment coordinates and the inverse projection matrix.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.