Jump to content

  • Log In with Google      Sign In   
  • Create Account


How does clipping fit into the pipeline?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 King_DuckZ   Members   -  Reputation: 128

Like
0Likes
Like

Posted 21 September 2012 - 06:07 AM

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-- ]

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 29733

Like
0Likes
Like

Posted 21 September 2012 - 06:16 AM

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.

#3 King_DuckZ   Members   -  Reputation: 128

Like
0Likes
Like

Posted 21 September 2012 - 06:51 AM

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!

Edited by King_DuckZ, 21 September 2012 - 06:53 AM.

[ King_DuckZ out-- ]

#4 tanzanite7   Members   -  Reputation: 1246

Like
0Likes
Like

Posted 22 September 2012 - 12:42 PM

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).

#5 mhagain   Crossbones+   -  Reputation: 7866

Like
0Likes
Like

Posted 22 September 2012 - 01:34 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 Geometrian   Crossbones+   -  Reputation: 1503

Like
1Likes
Like

Posted 22 September 2012 - 08:26 PM

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!
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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS