Clipping in clip space

Started by
3 comments, last by Zipster 17 years, 1 month ago
I'm trying to make sure I have the vertex transformation pipeline straight in my mind. 1) The clipping after the projection but before the homogeneous divide is where I am not sure: I think that the W value of each vertex is compared to another max W value to determine if the point should be clipped. If so, what is that max W value? (Or is each of (x/w), (y/w), and (z/w) compared to 1.0?) Since it happens in the hardware, it's been hard to find info.
Quote:OpenGL FAQ: Clip Coordinates result from transforming Eye Coordinates by the Projection matrix. Clip Coordinate space ranges from -Wc to Wc in all three axes, where Wc is the Clip Coordinate W value. OpenGL clips all coordinates outside this range.
What is Wc? Here is a flow chart I am trying to get right.. Image Hosted by ImageShack.us 2 more related questions: 2) Am I correct that Z and W do not matter once we are in NDC (IF I don't care about depth buffering)? 3) What value does the depth buffer store, (Z/W)? Thanks. [Edited by - discman1028 on March 4, 2007 10:41:05 PM]
--== discman1028 ==--
Advertisement
I found my F.S. Hill, Jr Computer Graphics book, which did a great job of explaining, I highly recommend. I think I understand everything, except for the part circled in red below.

I realize why they chose [-1, 1] as the mapping for what they call the "pseudodepth", since the range provides a good dynamic range of depth values, since the "pseudodepth" is not linear. But why must it be mapped to [0, 1] before it is stored in the depth buffer?

Image Hosted by ImageShack.us

[Edited by - discman1028 on March 5, 2007 12:43:00 AM]
--== discman1028 ==--
Quote:Original post by discman1028
I realize why they chose [-1, 1] as the mapping for what they call the "pseudodepth", since the range provides a good dynamic range of depth values, since the "pseudodepth" is not linear. But why must it be mapped to [0, 1] before it is stored in the depth buffer?

It's just a convention I imagine, so that you have all non-negative values for the coordinates. They could just have easily made the Z-range in NDC be [0,1] instead of [-1,1] and avoided this extra transformation, but that's just the way things are :)
Quote:2) Am I correct that Z and W do not matter once we are in NDC (IF I don't care about depth buffering)?

I think so. There's a well known trick when rendering skyboxes last (to avoid fillrate waste on something that is probably barely visible a lot of the time) that makes use of this.

1. Clear depth buffer to 1
2. Render scene without skybox (so all parts of scene that the sky will fill have a depth of 1 [as they are untouched])
3. Set ZFunc to less or equal & turn off z writes
4. Render the skybox, but use a vertex shader that places the clip space z co-ord into w, so that after the post-proj divide z will always equal ~1

When I switched between the traditional & new technique, there seemed to be a very slight discrepancy (I was toggling between the two using a key press) but it was virtually unnoticeable. It was like changing between 89 and 90 fov or something. Maybe I had some other variable that changed between the techniques.

Given what I observed, I would say that the depth buffer does indeed store z/w. It's not the easiest thing to understand, really.
Yes, the depth buffer stores Z/W, unless otherwise modified by the fragment shader. This is one of the reasons why you experience Z-fighting if your near/far parameters are ill-conditioned, since Z/W is non-linear and all your precision is near the viewer while fragments far away from the viewer have to fight for those precision bits.

Quote:1. Clear depth buffer to 1
2. Render scene without skybox (so all parts of scene that the sky will fill have a depth of 1 [as they are untouched])
3. Set ZFunc to less or equal & turn off z writes
4. Render the skybox, but use a vertex shader that places the clip space z co-ord into w, so that after the post-proj divide z will always equal ~1

You might be safer using the stencil buffer so you don't have to rely on imprecise division and comparison. But that's just me :)

This topic is closed to new replies.

Advertisement