Sign in to follow this  
Lutz

When are vertices clipped?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this