W coordinate equals zero during homogenous divide

Started by
3 comments, last by WedgeMan 12 years, 12 months ago
I have an issue in my software renderer where if a polygon straddles the near clipping plane, there's a chance that one of the vertices will have a w coordinate of zero after the matrix transformation. I know that in OpenGL, this problem doesn't occur, with the same exact scene. Is there any technique to avoid this issue?
Advertisement
The problem obviously occurs due to your choice of projection matrix. You haven't told anything about that matrix, but you know that OpenGL's corresponding projection matrix doesn't have this issue, so my suggestion is to analyze OpenGL's matrix (it is publicly available n the internet) and compare its way of doing things with yours.
usually you don't draw until z is zero, but just to the near clipping plane, which is in some distance to 0.

obviously, simplest way to solve that is probably to clip your triangles on the near plane before you divide by w.

The problem obviously occurs due to your choice of projection matrix.[/quote]
@haegarr
The problem is not my projection matrix; I've compared them several times while writing the renderer, and researched it. Not to mention, it's nonzero after the projection matrix multiply, but after the modelview matrix multiply, which places the polygon on/near the near plane, the w coordinate becomes zero. The problem obviously lies elsewhere.

perspective(50.0f, 1.33333f, 0.1f, 500.0f), which works fine everywhere else.

usually you don't draw until z is zero, but just to the near clipping plane, which is in some distance to 0.obviously, simplest way to solve that is probably to clip your triangles on the near plane before you divide by w.[/quote]
@Krypt0n
I will attempt better clipping; I usually transform and keep the vertices unclipped for interpolation reasons, but this is unacceptable.
I had this problem as well recently implementing a software renderer. It has nothing to do with your projection matrix specifically, it has to do with all projection matrices in general.

You simply need to implement clipping on your triangles so that they can't go past the near clip plane. You won't get divide by 0 issues then.

This topic is closed to new replies.

Advertisement