Jump to content
  • Advertisement
Sign in to follow this  
fastcall22

When to do polygon clipping?

This topic is 2986 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

So, I'm writing a software rasterizer in a dos console for kicks and giggles, and everything looks great so far. That is, until I started to view polygons close-up and at extreme angles. I've been avoiding polygon clipping until now, since there wasn't a need for it until now. The tutorial I followed mentions that I can clip in either 2 or 3 dimensions. However, it also states:
Quote:
Objects that are very close will not just fall of the screen, they cause mayhem in the perspective formulas too. At the moment that Z (the depth of a vertex) changes sign, the screen coordinates will do the same, causing polygons to appear as random large nails on your screen. This can be solved by clipping the polygons against a plane, close to Z=0.
... which I assume is the problem I'm observing. But the question is, when do I perform the clipping? At the moment, I'm clipping at z=nearPlane on the triangle level. However, this does not fix the problem, as at the time of the clipping x and y components of the coordinates have already been transformed, and if their z component is, as the tutorial states, close to 0, then it causes "large nails on the screen." So I assume clipping won't help in this case? Also, I'm not very familiar with linear algebra, but I know enough to get around. Is there a reason why OpenGL separates the transformation matrices from the viewport matrices? Will I have to transform the vertices with the transformation matrix first, then perform clipping, then transform the results with the perspective matrix? Or should I perform the clipping before I divide the Vector4 by its w component? Here's how I got it set up so far:
  1. Client supplies vertices and matrices in a OpenGL-immediate-mode fashion
  2. On the call to "end," the vertices supplied by the client are transformed with the final matrix into screen coordinates
  3. Depending on the mode specified by the client at the call to "begin," the vertices are drawn (polygon, triangles, quads)
  4. Per triangle, the polygon is clipped against the z-axis
  5. The final polygon is rendered
Internet cäeks for those who can help me out. Chairs!

Share this post


Link to post
Share on other sites
Advertisement
You clip in clip space -- that is, after transforming by the world and projection matrices, and before the perspective division and the viewport transformation.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!