Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Z-Fighting - expected behaviour?

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Apr 2004
    Location
    Sweden
    Posts
    67

    Z-Fighting - expected behaviour?

    When I optimized my models to triangles strips, I came across an annoying z-fighting problem when drawing the shadow volume front cap. This only occurs when I draw the model with triangle strips (I draw the shadow volume front cap using a triangle list, GL_TRIANGLES). I'll illustrate the problem with a few lines of code:

    Code :
    // vertices
    vec3 v0(-100, 0, -100);
    vec3 v1(-100, 0,  100);
    vec3 v2( 100, 0,  100);
    vec3 v3( 100, 0, -100);
     
    // first pass
    glColor3ub(255,0,0); // Red
    glBegin(GL_TRIANGLE_STRIP);
    glVertex(v0);
    glVertex(v1);
    glVertex(v3);
    glVertex(v2);
    glEnd();
     
    // second pass, no depth write
    glDepthMask(0);
    glDepthFunc(GL_EQUAL);
     
    glColor3ub(255,255,0); // Yellow
    glBegin(GL_TRIANGLES);
    glVertex(v0);
    glVertex(v1);
    glVertex(v2);
    glVertex(v0);
    glVertex(v2);
    glVertex(v3);
    glEnd();
     
    glDepthMask(1);
    glDepthFunc(GL_LESS);
    Result, http://sunray.cplusplus.se/dump/zfight.png
    I'm using a Radeon 9700 Pro with Catalyst 3.8 Beta.

    My question is; is this an expected behaviour?

    -- Sunray

  2. #2
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: Z-Fighting - expected behaviour?

    Try using the same primitive type for both passes. I wouldn't count on invariance among different primitives (it's not in the spec).

  3. #3
    Intern Contributor
    Join Date
    Apr 2004
    Location
    Sweden
    Posts
    67

    Re: Z-Fighting - expected behaviour?

    Yeah, if I use the same primitive it works. But, the problem is that I've to draw the shadow volume caps using triangle strips.. Hmm..

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: Z-Fighting - expected behaviour?

    In general case, triangle strip is not necessarily an optimization. You can get quite the same performance by optimizing your pre t&l cache. And actually, by optimizing it, you would get better results when rendering your shadow volume caps.

    I talked about this in a thread here : http://www.opengl.org/discussion_boa...c;f=3;t=011685

    I forgot about strips some time ago, and it yields the second advantage to have a single draw call / model.

    If you decide to stuck on strips (consider building a pre cache test app before, please), you can try to polygon offset your original mesh.

    SeskaPeel.

Posting Permissions

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