Tutorial: Killing z-fighting in a stock Quake engine
Posted: Sat Oct 25, 2008 9:53 am
I have hated this problem for ages and tonight wanted for myself to solve the problem in my own engine project.
--
The area near the Quad secret on E1M1 is notorious for flickering or changing appearance from various angles even with some previous called "z-fighting fixes" that don't really do the job.
The only engine I've tried with a proper z-fighting fix is:
ezQuake (I confess I have not tested FTE for this)
There are a number of engines with ALMOST a proper z-fighting fix. The closest in the almost category is Qrack. However, I get an outline in the start map atrium as a side-effect.
I still get various types of weirdness in the E1M1 area with:
DarkPlaces, FitzQuake, aguirRe Quake, QMB and every other GL engine I've ever used and thought to look for the problem.
Qrack side effect, not in ezQuake:
I don't like trading a fix in one area for a problem in another eventually I tried to identify the difference between the Qrack and ezQuake fix.
I've tried the ezQuake fix in 2 engines with the same result of a perfect solution (gl_ztrick 0 is required, some engines don't even support gl_ztrick 1 anymore).
-----
Here is the ezQuake fix:
z-fighting fix step 1: in gl_vidnt.c .. or sometimes vid_wgl.c or vid_commongl.c or vid_gl<operating sys>.c
1. Goto GL_INIT or the equivalent
2. You will see OpenGL code resembling the following ...
1. Find void R_DrawEntitiesOnList (void)
2. Locate " case mod_brush:"
3. After that, but before the "break;", insert:
I'm rather weak in a lot of the OpenGL calls and the .bsp stuff to quite understand why Qrack's method produces the start map line and ezQuake's only slightly different method doesn't.
I'm guessing that Qrack's use of 1 vs. 0.05 makes the difference in seeing the line, but I'm not 100% certain?
--
The area near the Quad secret on E1M1 is notorious for flickering or changing appearance from various angles even with some previous called "z-fighting fixes" that don't really do the job.
The only engine I've tried with a proper z-fighting fix is:
ezQuake (I confess I have not tested FTE for this)
There are a number of engines with ALMOST a proper z-fighting fix. The closest in the almost category is Qrack. However, I get an outline in the start map atrium as a side-effect.
I still get various types of weirdness in the E1M1 area with:
DarkPlaces, FitzQuake, aguirRe Quake, QMB and every other GL engine I've ever used and thought to look for the problem.
Qrack side effect, not in ezQuake:
I don't like trading a fix in one area for a problem in another eventually I tried to identify the difference between the Qrack and ezQuake fix.
I've tried the ezQuake fix in 2 engines with the same result of a perfect solution (gl_ztrick 0 is required, some engines don't even support gl_ztrick 1 anymore).
-----
Here is the ezQuake fix:
z-fighting fix step 1: in gl_vidnt.c .. or sometimes vid_wgl.c or vid_commongl.c or vid_gl<operating sys>.c
1. Goto GL_INIT or the equivalent
2. You will see OpenGL code resembling the following ...
3. Add after the glAlphaFunc line (although it really doesn't matter)glClearColor (0.15,0.15,0.15,0);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
z-fighting fix step 2: in gl_rmain.c// Get rid of Z-fighting for textures by offsetting the
// drawing of entity models compared to normal polygons.
// (Only works if gl_ztrick is turned off)
glPolygonOffset(0.05, 0);
1. Find void R_DrawEntitiesOnList (void)
2. Locate " case mod_brush:"
3. After that, but before the "break;", insert:
Code: Select all
// Get rid of Z-fighting for textures by offsetting the
// drawing of entity models compared to normal polygons.
// (Only works if gl_ztrick is turned off)
if(!gl_ztrick.value)
{
glEnable(GL_POLYGON_OFFSET_FILL);
}
R_DrawBrushModel (currententity);
if(!gl_ztrick.value)
{
glDisable(GL_POLYGON_OFFSET_FILL);
}
break;
I'm guessing that Qrack's use of 1 vs. 0.05 makes the difference in seeing the line, but I'm not 100% certain?