PDA

View Full Version : Z-Fighting - expected behaviour?



Sunray
08-01-2004, 05:27 AM
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:


// 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

plasmonster
08-01-2004, 10:12 AM
Try using the same primitive type for both passes. I wouldn't count on invariance among different primitives (it's not in the spec).

Sunray
08-02-2004, 12:43 AM
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..

SeskaPeel
08-02-2004, 04:28 AM
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_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;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.