When are vertices clipped?

Started by
8 comments, last by Lutz 19 years, 4 months ago
Hey! Is the vertex program executed when I render a triangle which is completely outside the view frustum? My problem: I have some very, very, expensive vertex program and I wonder whether it's worth putting more effort into frustum culling. My considerations: The vertex program has to be executed prior to the clipping stage since otherwise there would be artifacts with polygons which are partially clipped. On the other hand, there might be some "early clipping stage" where triangles are thrown away that are completely off the screen.
Advertisement
Your vertex program is run for every vertex that is passed through
the drawing pipeline to be draw.

So for a simple polygon - 3 vertices, single triangle - your
vertex program will be run 3 times.

These output vertices are then used by the rasteriser to produce
the correct pixels (fragments) to be rendered to the buffer, this
is done by interpolating between the screen space vertices and
emitting a pixel for each point that is inside the framebuffer.

Your best bet for improving performance is to cull triangles that
are outside the view frustum, most modern video cards do recognise
triangles that are completely off screen - but rely on that alone
as a culling method is a bad idea.
MrF.--Code..reboot..code..reboot..sigh!
Quote:Original post by MrFlibble
...most modern video cards do recognise
triangles that are completely off screen - but rely on that alone
as a culling method is a bad idea.

Does that mean that MODERN video cards don't execute the vertex program if the triangle is off screen?
Quote:Does that mean that MODERN video cards don't execute the vertex program if the triangle is off screen?


I'm 99.9% cure they don't.
and if they do, I'd like to know how they can know wether or not a vertex is inside or outside the view frustum, as the vertex program can completely change the vertex position, and make a vertex that previously was outside the frustum be inside...

if your vertex program deforms vertices, you'll have to take into account the maximum possible deformation to generate the GC or object bounding box, and use that to cull the triangle batches you send to the card.
Quote:Original post by Lutz
Does that mean that MODERN video cards don't execute the vertex program if the triangle is off screen?


NO - the vertex program HAS to be run on any vertex in a polygon
you are trying to render, AFTER this the rasterizer will throw
away polygons that are outside the frame buffer area.

Cards can only make the distinction on screen-space vertices,
not on untransformed local space vertices.
MrF.--Code..reboot..code..reboot..sigh!
The best thing you can do is make sure to get the output position written as quickly as possible, because some drivers/cards will quit processing early if they're out of range.

So do all your texture writes after getting the position written.

Well, also, do some large-scale frustum culling :) But you can make it more efficient by writing the output position quickly.

Edit: I'm going to add that I may be remembering the lecture incorrectly, but I swear I remember some nVidia guy say that in a presentation somewhere :)
Clipping is not done in screen space, it's done in the aptly named clip-space (or post-projective space). After the ModelViewProjection transform, you are in clip-space, which is a unit cube for open gl, x,y,z ranging -1...1. for direct3d x,y, ranging -1...1, z ranging 0...1.
Of course clipping happens after vertex program.

Think about it for a second.

What is one thing that you *always* do in a vertex program? You assign vertex.position (even if you are just passing it through). How can you clip properly before vertex program execution if you don't have the correct position?

The only time a vertex program won't get executed on modern hardware is if the vertex already exists in the post transform cache.

You should read some nvidia articles on this subject. If you can reduce sending a large batch of triangles through the pipeline then it is a good idea not to send them. As far as clipping goes, the GPU can handle 100's of millions of vertices a second, so you shouldn't have to worry.
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
Thanks, guys, you are absolutely right.
Of cource, the GPU can't know where the vertex is until it executes the VP.

Sorry, stupid question!

This topic is closed to new replies.

Advertisement