PDA

View Full Version : Volume Clipping



WM
03-18-2002, 09:33 AM
I'm a bit confused about how OpenGL performs clipping on primitives. Does it clip at rasterization time (clips per-fragment against the viewport) or does it use clip planes and do vertex inside/outside plane test?
If 3D clipping (the later approach) is used, there will be a problem. when passing a primitive, say a triangle strip, and it's partially clipped, a new vertices will be added. How does OpenGL take care of this?
Thanks.

Dodger
03-19-2002, 08:18 AM
It does the latter, clipping happens in 3d (clip space, [-1;1]^3). New verts are added internally by the driver/the hardware. You don't have to worry about it, that's one of the things that the GL handles automatically.

knackered
03-19-2002, 08:33 AM
I'm not sure if that is the correct answer.
I believe that it works in the following way:-
- the vertices are transformed into eye space.
- any primitives (tris, tristrips etc.) outside the frustum are ignored (culled, if you will).
- any primitives partially inside the frustum are transformed into clip-space (screen space).
- the rasterizer clips to the scissor region.

It's because you get different results interpolating a normal (you'd have to generate a new vertex AND a new normal if clipping in eye space - this would produce artifacts, as the lighting would be inconsistant with an unclipped triangle).

I think what I say is true, but I'm not 100% sure.

ehart
03-19-2002, 09:32 AM
The way clipping is spec'd to work in GL is as follows, but an implementation is free to do whatever so long as it produces the correct results.

- transform/light vertices using the modelview
- coalesce vertices into primitives (primitive assembly)
- clip the primitives against the eye-space user clip planes
- transform by the projection matrix
- clip the primitives against these contraints in clip-space
-w <= x <= w
-w <= y <= w
-w <= z <= w
- divide by w
- apply the viewport transform
- rasterize the primitive applying scissor

I doubt just about any implementation does this exactly, but it is definitely not uncommon for the clipping to be done on primitivesas specified rather than as a scissor operation. To get polygon clipping for polygon mode line corect, you almost need to do it that way.

- Evan