PDA

View Full Version : Linearized depth for shadowmap



LaBasX2
09-23-2007, 04:04 PM
Hello,

for improving precision of my shadow maps I would like to use linear depth distribution of the z-buffer. I have tried to modify the projection matrix like this, also playing around with different signs:

mp[10] = 1 / (far - near)
mp[14] = -n / (far - near)

Additionally I am premultiplying the transformed z with w in the vertex shader but it doesn't seem to work. Has anyone done this before?

Thanks a lot!

Trenki
09-24-2007, 01:48 AM
I think you shouldn't modify the projection matrix at all as the outcome of multiplying the vertices with this matrix will be used for proper clipping. Changing it will only get you into trouble later on. Instead compute the linear depth value in the vertex shader based on camera and vertex position and store this into a floating point render target. I think with proper scaling into the [0, 1) range it would also be possible to use an RGBA8 target with some packing and unpacking.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]