**0**

# W coordinate equals zero during homogenous divide

Started by Ectara, Apr 20 2011 12:25 AM

4 replies to this topic

###
#1
Crossbones+ - Reputation: **3097**

Posted 20 April 2011 - 12:25 AM

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?

###
#2
Crossbones+ - Reputation: **7042**

Posted 20 April 2011 - 01:09 AM

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.

###
#4
Crossbones+ - Reputation: **3097**

Posted 20 April 2011 - 07:35 AM

@haegarrThe problem obviously occurs due to your choice of projection matrix.

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.

@Krypt0nusually 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.

I will attempt better clipping; I usually transform and keep the vertices unclipped for interpolation reasons, but this is unacceptable.

###
#5
Members - Reputation: **100**

Posted 21 April 2011 - 09:46 AM

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.

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.