# Optimal method for clipping (software rasterizer)

This topic is 3956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

For fastest results, should the clipping be done in Object space or Clip space? Also, is transforming (/ projecting) all vertices the fastest way to go or some algorithm is used to filter and transform only vertices that belong to one or more front facing triangles? Thanks in advance.

##### Share on other sites
You normally do the clipping in clip space. For this to happen you have to transform the vertices into clip space first. Normally you would rely on the user to only supply the geometry which will eventually end up within the frustum. The user could do frustum culling to determine which geometry to actually send into the pipeline. It is not your responsibibity.

Also backface culling is normally done in screen space, that is after all transforms and clipping.

##### Share on other sites
Clipping in Clip space would simplify the plane equations, but would require transforming all vertices to clip space. For a closed shape, approximately 20-40% of vertices would be part of only back faced triangles and transforming them is not really required. So this is where the confusion is: is it possible to have an implementation that is faster where clipping is done in object space?

Also, back face culling done in clip space would require clipping of triangles that are eventually discarded. Wouldn't this be slower than back face culling in object space?

Thanks.

##### Share on other sites
You could probably do the backface culling before the clipping which would save you from clipping triangles that would end up invisible anyway.

Backface culling in object space is a whole other story though. A simple formula might give you convincing results but will eventually cull too many or too few triangles. For instance taking a simple dot product between the view vector to the triangle (would have to be computed per triangle => expensive) and the triangle surface normal (would also have to be computed, since the vertex normals can be arbitrary => expensive) and doing a "if (dp < 0) discard" would NOT give correct results when using a perspective transform.

Doing backface culling in object space will generally be a lot more expensive than doing it in clip space or screen space (where it is normally done). And since this is for a software renderer doing per triangle backface culling will not give the best performance either. There are some hierarchical or clustered backface culling algorithms which can cull many triangles at once. The book "Real-Time Rendering, 2nd Edition" has some resources on this and maybe you can also find something on the book's website.

##### Share on other sites
Quote:
 Original post by TrenkiBackface culling in object space is a whole other story though. A simple formula might give you convincing results but will eventually cull too many or too few triangles. For instance taking a simple dot product between the view vector to the triangle (would have to be computed per triangle => expensive) and the triangle surface normal (would also have to be computed, since the vertex normals can be arbitrary => expensive) and doing a "if (dp < 0) discard" would NOT give correct results when using a perspective transform.

I see what you mean.
Would back face culling in clip space involve the same steps? ie take the cross product of two edges and check the sign of z component?

Quote:
 Original post by Trenkifor a software renderer doing per triangle backface culling will not give the best performance either. There are some hierarchical or clustered backface culling algorithms which can cull many triangles at once. The book "Real-Time Rendering, 2nd Edition" has some resources on this and maybe you can also find something on the book's website.

Thanks for point out this book. Btw, which hierarchical / clustered backface culling algorithm would you recommend?

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013442
×