Skip to main content
GameDev.net gamedev.net
🔒 Locked

Converting depth value to linear value

Started by Starfox Jul 11, 2006 at 5:13 AM 5 replies 1k views
Original Post
Starfox
Starfox
How can I convert the depth value, [0, 1], to a linear value in the same range [0, 1]? My feeble math skills says this'll absolutely need the near ad far clip plane distances, but other than that I've no idea. I'd appreciate any help. TIA [Edited by - Starfox on July 11, 2006 5:53:23 AM]
vokuhila
vokuhila
Hm not sure if I got your question right.
I would simply calculate the distance to the near plane and divide by (dist_far-dist_near). Then you have linear distance in [0,1].

If you want to convert your existing depth values to the linear range, i won't be able to help.
Starfox
Starfox
I need to avoid rerendering the scene, or changing the vertex shader. I need to strictly read the z value at this pixel and output a linear (W-buffer-like) value.
Lopez
Lopez
Is it just 1 piexls depth you need?

Coluna
Coluna
Well, u can try this

a=-far/(far-near)
b=-far*near/(far-near)
Z=(a*z+b)/-z

where 'z' is your z value read from z-buffer, and 'Z' is your real distance...

but if somebody knows how to do that with infinite far plane, please tell me!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.