Near/far clipping in a software rasterizer

Started by
15 comments, last by iMalc 17 years, 2 months ago
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.
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.
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.
Try checking depth(Z) per pixel, not per vertex, then eliminating pixels that have a depth of <
Crap, forgot to login; anyways, it'd be good to loop up 'Z-Buffering'--it solves the problem you're talking about.
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.
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
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.
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.
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.

This topic is closed to new replies.

Advertisement