How do I prevent jagged edges from appearing along the surfaces of my 3d model?

Let's say I have implemented a crude shaded model viewer in openGL that displays a series of blocks, so I have something similar to this.

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

Whenever I turn 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 sure this is due to the polygon offset I used to prevent z-battles between model and wireframe, however I cannot find the factor / unit parameters in openGL that prevent this unwanted effect.

  • What are the best factor and unit values ​​for glPolygonOffset to prevent this?

  • will implement anti-aliasing to fix the problem? is this performance tradeoff trivial / meaningful?

  • Could it be a shading issue? should i try a solution along this line of thought?

+2


source to share


2 answers


It doesn't look like a Z fight to me.

If you draw flat shaded objects and then some GL_LINES over it, those lines will create this effect because they are not anti-aliased.



Why not just apply a mesh texture to your objects? This way you can use OpenGL texture filtering. You may try:

  • Enable filtering MIN_ and MAG_ on this texture.
  • Create a texture with mipmaps using gluBuild2DMipmaps. (see Creating Mipmaps )
  • Enable Anisotropic Filtering? (see this page )
+3


source


Most likely you get a z-battle at steep corners (i.e. when all points have very similar z-values) because
1) You have too bad a resolution for the z-buffer if you set a 16-bit z-buffer - try change resolution to 32-bit
2) Your model is very small and all your points are too close together. You can try expanding the model.

Using a fixed offset will give inconsistent results because most z-buffer circuits are biased to provide a higher resolution the closer you are to the closest plane of the clip. ie you need less offset the closer you are to the plane of the nearest clip.



Here's a gamedev article that goes into more detail

Note that anti-aliasing and changing shaders is unlikely to help you here (unless you made some funky custom pixel shader to modulate z values, but that seems overkill to me, although I'm not an expert on pixel / fragment shaders so it can be doable)

+1


source







All Articles