PDA

View Full Version : depth bounds



Poons
09-19-2005, 05:45 AM
i have a (maybe not so advanced) problem with glDepthBoundsExt.

when using glDepthBoundsExt i have to pass values between [0,1]. in my implementation i calculate the intersection point of a frustum plane with a straight line (defined by the light source and a vertex from the object).

how can i transform those z-values to the range [0,1]?

thanks!

Nikolai Timofeev
09-19-2005, 06:08 AM
Transform object's point (your intersection)
Po = (Xo,Yo,Zo,1) by camera transform matrix (view * projection) to get point's clip coordinate Pc = (Xc, Yc, Zc, W).

The point's normalized device coordinate are then
Xd = Xc / W ; //[-1,1]
Yd = Yc / W ; //[-1,1]
Zd = Zc / W ; //[-1,1]

Since Z in range [0,1] :
wanted Z = Zd * 0.5 + 0.5; // put it within required range

Poons
09-19-2005, 11:01 AM
thanks for your answer!