Clipping in projective space

Started by
1 comment, last by krisiun 15 years, 5 months ago
Hi, I'm writing some code to find the screen space bouding rect of a 3d bounding box (for copying from current rt to refraction texture). So I just take 8 vertices, transform with wvp and calculate this rect. The only problem is then a transformed vertex in homogeneous space has w < 0. Then you can't just divide by /w to get the screen space coords, you need to do some clipping. Of course I can just clip my bouding box in world/view space and later transform by viewProjection/projecton matrix. But I'd like to understand why my post projection clipping code doesn't work. Ok, so my question is: should I find the intersecion of the w = nearPlane plane and some edge, or is it some other plane? Or in other words, is a vertex with w < nearPlane before the near plane (non visible)? I'm using directx, it has w from 0 to farPlane. So it looks like that this plane should be at w = 0. But it doesn't make any sense, because a point with w = 0 is in infinity.
Advertisement
In a typical perspective transform, the W component after the transform is just the ±Z value before the transform (in view space). So to answer your question, if W is less than the near plane value then yes, it was behind the near plane. A W of 0 means the vertex was on top of the camera, which is always behind the near plane, and will surely be clipped away.

If you're performing the clipping manually, remember that a vertex is inside the post-perspective cube (in DirectX) when -W ≤ X ≤ W, -W ≤ Y ≤ W, and 0 ≤ Z ≤ W. These can be expanded into six conditions, one for each pair of adjacent inequalities. Each inequality translates to a clipping plane (six for a cube):

[1,0,0,1]
[-1,0,0,1]
[0,1,0,1]
[0,-1,0,1]
[0,0,1,0]
[0,0,-1,1]

Those are just the normals, all the distances will be zero.

It's also possible that you don't really need to be doing all this clipping and can just find the conservative bounds on the near plane even when the box is behind the near plane or beyond the far plane.
Thanks.

What do mean by finding conservative bounds?

Do You mean that I don't have to clip by all the 6 planes and only near (or near and far) plane is enought?

This topic is closed to new replies.

Advertisement