views:

132

answers:

2

Lets say I've implemented in openGL a crude model viewer with shading which renders a series of blocks, such that I have something that looks like this.

http://i.imgur.com/TsF7K.jpg

Whenever I rotate my model to the side, it causes an unwanted jagged effect along any surface with a steep viewing angle.

http://i.imgur.com/Bgl9o.jpg

I'm pretty sure this is due to the polygon offset I used to prevent z-fighting between the model and the wireframe, however I'm not able to find the factor/unit parameters in openGL which prevent this unwanted effect.

  1. what are the best values of factor and unit for glPolygonOffset to prevent this?

  2. would implementing anti-aliasing alleviate the problem? is the trade off in performance trivial/significant?

  3. is this perhaps a shading issue? should i try a solution along this line of thought?

+1  A: 

Chances are that you're getting z-fighting at steep angles ( i.e when all points have very similar z values ) because
1) You're z-buffer resolution is too low i.e you've set a 16-bit z buffer - try changing the resolution to 32-bit
2) Your model is very small i.e all your points are too close together. You could try scaling up the model.

Using a fixed offset will give inconsistent results because most z-buffer schemes are biased to give higher-resolution the closer you are to the near clip plan i.e you need a smaller offset the closer you are to the near clip plane.

Here's a gamedev article that discusses the problem in more depth

Note that anti-aliasing and changing shader are unlikely to help much here ( unless you did some funky custom pixel shader to modulate the z-values but that seems an overkill to me though I'm no expert on pixel/fragment shaders so it may be doable)

zebrabox
+3  A: 

That doesnt look like Z-fighting to me..

If you are drawing the flat shaded objects and then some GL_LINES over it, those lines will produce that effect because they are not antialiased.

Why not just apply a grid texture over your objects? That way you can take advantage of OpenGL's texture filtering. You can try to:

  • Enable MIN_ and MAG_ filtering on this texture.
  • Create the texture with mipmaps using gluBuild2DMipmaps. (see Generating Mipmaps)
  • Enable Anisotropic Filtering? (see this page)
Mikepote