Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

W coordinate equals zero during homogenous divide

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Ectara   Members   

3097
Like
0Likes
Like

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 haegarr   Members   

7369
Like
0Likes
Like

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.

#3 Krypt0n   Members   

4706
Like
0Likes
Like

Posted 20 April 2011 - 02:34 AM

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.



#4 Ectara   Members   

3097
Like
-1Likes
Like

Posted 20 April 2011 - 07:35 AM

The problem obviously occurs due to your choice of projection matrix.

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

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

#5 WedgeMan   Members   

100
Like
0Likes
Like

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.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.