PDA

View Full Version : Transparency and hardware acceleration



Pody
08-15-2004, 10:58 PM
Hi,
I'm drawing an object twice with alpha blending enabled (on the second draw pass) in order to have a transparent environment mapping on it.
I noticed that with hardware acceleration disabled the transparent drawing has big problems...
Is this a software limitation of OpenGL or am I doing something wrong?
Thanks for you time

You can see the pictures here:
Hardware accel. enabled:
http://it.geocities.com/toddler_78/envmap2.gif
Hardware accel. disabled:
http://it.geocities.com/toddler_78/envmap1.gif

The code I'm using is the following:

drawPrimitive(shape); //draw the solid object

glDepthFunc(GL_LEQUAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texNames[currentTexture]);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);

drawPrimitive(shape); //draw the transparent object with environment mapping on it

glDepthFunc(GL_LESS);
glDisable(GL_BLEND);

ZbuffeR
08-16-2004, 02:01 PM
The problem here is known as "z-fighting", two polygons fighting for the z. The software implementation seem to have slightly different z for each type of primitive. You may try using more permitive z test (less or equal instead of strict less), or disabling depth test for second pass (or better, clear it between passes), or using polygon offset.

I believe that according to the spec, the same polygon should be rasterized the same way. Maybe try with Mesa GL software implementation ?

dorbie
08-16-2004, 06:31 PM
Yup, this is a classic problem of z invariance (or the lack of invariance) leading to z fighting. ZbuffeR is correct OpenGL does not guarantee that if you change state (like turning texturing on and off) that the depth values on the same primitive will match the earlier renderings. Most hardware today does offer z invariance even though it doesn't have to. You could use glOffsetPolygon, enable texturing and use a white modulating texture or do as ZbuffeR suggests & try Mesa for software OpenGL, no guarantees there either.

Pody
08-16-2004, 09:44 PM
Thanks a lot!
Using glPolygonOffset() solves the problem :)
Ciao