Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Line Z-fighting workaround

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Newbie
    Join Date
    Nov 2012

    Line Z-fighting workaround

    Like I may have mentioned in my previous questions, I'm working on rendering a relatively high poly "model".

    Functionally, it's generated terrain from a square heightmap image, a few hundred pixels to a side. Since it's the only 3D object in the scene (everything else is 2D GUI elements that ignore the depth buffer) I decided to use glPolygonOffset to draw its wireframe.

    Now, I want to draw another set of lines on top of the wireframe. Each member of this set of lines (they make up a contour line, if you're wondering) is guaranteed to be coplanar to one of the triangles that make up the terrain; however, this also means that the lines can interfere (z-fighting) with the wireframe. As a workaround, I draw these extra lines into the stencil buffer, then, after drawing the wireframe, painting the lines back on via stencil.

    Now, I'm wondering if it's possible to utilize the 8 bits of the stencil buffer for more features. As it stands, I don't get any antialiasing from the stencil buffer -- the test seems to only be on or off, so the lines appear thick (where the partial alpha gets drawn as solid).

    My main purpose is to be able to draw multiple contours of different colors, so I was wondering if it was possible to do some bitwise tests. If it's not possible, can I use other methods (textures perhaps?) to replicate this masking behavior? Antialiasing would be preferred, but not an absolute necessity.

    EDIT: I seem to have left out that I'm currently handling the multiple color issue by simply overwriting the stencil buffer with a different value, then checking for equality later. This method works "well enough", but I feel it's inelegant and could use improvement, hence the thread.
    Last edited by Aestivae; 12-21-2012 at 05:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts