PDA

View Full Version : Screen Z goes from 0 to 1?



Jambolo
02-26-2002, 07:08 PM
It is written in many places that the Z value of a point is transformed to the range 0 to 1 by the projection matrix. But when I do the math myself, I get -1 to 1. What's up?

Transform the point (0,0,-n ):






| 2n/(r-l) 0 (r+l)/(r-l) 0 | | 0 | | 0 |
| | | | | |
| 0 2n/(t-b) (t+b)/(t-b) 0 | | 0 | | 0 |
| | | | = | |
| 0 0 -(f+n)/(f-n) -2fn/(f-n) | |-n | |-n |
| | | | | |
| 0 0 -1 0 | | 1 | | n |

= (0,0,-1)


(assuming l = -r and t = -b)

Transforming ( 0,0,-f) gives (0,0,1)

Z goes from -1 to 1?!?!? What is the source of my confusion?


[This message has been edited by Jambolo (edited 02-26-2002).]

jefftkd
02-26-2002, 09:19 PM
Originally posted by Jambolo:
the Z value of a point is transformed to the range 0 to 1 by the projection


This is correct. The window coordinates are different from world coordinates. 0.0 is the Z value at the near clipping plane and 1.0 at the far clipping plane.

It also states in the Red book that values outside that range are converted to that range I believe (someone correct me if I am wrong here, please). Which is why your -1 is being returned as a 1.

Jeff

wimmer
02-27-2002, 02:56 AM
See the documentation for glDepthRange. Your math is correct, the projection matrix gives z from -1 to 1, it gets converted afterwards.

Michael

Jambolo
02-27-2002, 08:45 PM
Thanks. I got it now. The viewport transformation (which I completely forgot about) transforms Z from [-1,1] to [0,1].