Jump to content
  • Advertisement
Sign in to follow this  
noVum

Near/far clipping in a software rasterizer

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, I'm currently writing a little software-based triangle rasterizer and everything is going alright, besides having a problem clipping polygons that are in front of the near plane. What's the correct method of doing this? Clipping Z in the homogenous clipspace is not working, because vertices will sometimes go to infinity-values if they lie on z=0 in camera space. Do I need to clip against the w-value? That would be much more complex, because w can't be interpolated linearly in screenspace.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Clipping Z in the homogenous clipspace is not working, because vertices will sometimes go to infinity-values if they lie on z=0 in camera space.
After the perspective division, just clip z values outside the (-1,1) range. You can specifically look for the case where pre-division w=0 and discard those as well.

Share this post


Link to post
Share on other sites
What do you mean by "discard" them. I can't just not draw the entire triangle if one of the vertices lies on e.g. (0,0,0) in camera-space.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try checking depth(Z) per pixel, not per vertex, then eliminating pixels that have a depth of <

Share this post


Link to post
Share on other sites
No it does NOT (and I'm already using it). It does not, because the vertex coordinates go to infinity even before drawing the triangle itself if the vertex lies on the camera-plane.

Share this post


Link to post
Share on other sites
Quote:
Original post by noVum
What do you mean by "discard" them. I can't just not draw the entire triangle if one of the vertices lies on e.g. (0,0,0) in camera-space.


From my understanding you generate new vertices at the edge. Don't quote me on that though :S

Share this post


Link to post
Share on other sites
Quote:
Original post by noVum
What do you mean by "discard" them. I can't just not draw the entire triangle if one of the vertices lies on e.g. (0,0,0) in camera-space.

If one of your vertices is at 0,0,0 at camera space, the triangle is not visible. Consider a triangle with one of the vertices in the middle of your eye (0,0,0 in camera space). Definitionally, the triangle is entirely perpendicular to your view direction and is thus not visile.

Share this post


Link to post
Share on other sites
Then take (2,3,0) or something else. It doesn't matter as long as it lies on the camera plane. Besides that I'm not convinced that a triangle that has (0,0,0) as one of it vertices is always not visible. Makes no sense to me.

Share this post


Link to post
Share on other sites
Quote:
Then take (2,3,0) or something else. It doesn't matter as long as it lies on the camera plane.
Not a problem, because clipping is done before the perspective division. So the values haven't gone to infinity yet. The 0,0,0 thing is really just an extra early-out.
Quote:
Besides that I'm not convinced that a triangle that has (0,0,0) as one of it vertices is always not visible. Makes no sense to me.
Hm... not sure how to convince you of this. Try to think of a counterexample.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!