How does clipping fit into the pipeline?

Started by
4 comments, last by Geometrian 11 years, 7 months ago
Hello everybody, I'm trying to figure out how to implement clipping in my code. My understanding is that when a triangle crosses a clipping plane (ie the frustum), new vertices are added to avoid disappearing triangles artifacts. This is done on the CPU (correct?), and any object is eligible for clipping. But my question is: doesn't this make GL_STATIC_DRAW flag utopic? I mean, an object standing on the screen border gets clipped every frame, so its vertex data is far from being static (new vertices added and removed continuously).
Moreover, how does it fit with skinned meshes or any other GPU-generated vertices? Anyone got a good reference on clipping? All I've managed to find is either abstract theory or very basic examples.
[ King_DuckZ out-- ]
Advertisement
The GPU clips primitives automatically. AFAIK, there's no way to turn it off.
Manual clipping is only required for software renderers (not GL/D3D).

In GL, after your vertex shader, the transformed vertices are in Normalized Device Coordinates (NDC), which is a cube from (-1,-1,-1) to (1,1,1). Any primitives that clip the edge of this cube are handled appropriately by the GPU's rasterization hardware.
Ok, thanks for clarifying! I can't find it right now, but one of the tutorial I stumbled upon stated that clipping was necessary in order for the rasterizer to remain inside its buffer. Somehow, I understood it was my responsibility to do that, not the hardware's. All the better then, I'll just remove invisible polygons and leave partially visible polygons as they are!
[ King_DuckZ out-- ]

Hello everybody, I'm trying to figure out how to implement clipping in my code. My understanding is that when a triangle crosses a clipping plane (ie the frustum), new vertices are added to avoid disappearing triangles artifacts.

This is how OpenGL is specified - however, no-one actually does it that way (for eons). "Guard bands" are used ( http://en.wikipedia.org/wiki/Guard_band_clipping ). For normal frustum - there are no actual clip-planes used at all (even for near and far plane [i do not know any official names for it tho] - nowadays one can even turn that part off in OpenGL).

Ok, thanks for clarifying! I can't find it right now, but one of the tutorial I stumbled upon stated that clipping was necessary in order for the rasterizer to remain inside its buffer. Somehow, I understood it was my responsibility to do that, not the hardware's. All the better then, I'll just remove invisible polygons and leave partially visible polygons as they are!


A lot of tutorial material is woefully out-of-date - either the tutorial was written sometime back in the 90s, or - if more recent - the person writing it hasn't bothered updating their understanding of things since that time. Back then clipping would certainly have been done on CPU, but by your driver, not by you. Since the advent of consumer-level hardware T&L much of the "knowledge" accumulated at that time is now completely irrelevant (or worse, it may lead the unwary to do awful things in their own code) so always be careful to double-check tutorial sources before you put much weight into what they say.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

In GL, after your vertex shader, the transformed vertices are in Normalized Device Coordinates (NDC), which is a cube from (-1,-1,-1) to (1,1,1). Any primitives that clip the edge of this cube are handled appropriately by the GPU's rasterization hardware.
Not exactly. The transformed vertices are in clip space, which is a 4D space where every 3D point has a w value. Clipping happens here. The perspective divide happens AFTER this (divide everything by w), bringing it to (eventually) NDC.

It's an important distinction because negative w values are behind the camera and so are invisible. If clipping happened after the perspective divide, then vertices behind would be divided by negative w values and suddenly become visible!

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement