PDA

View Full Version : Masking (and the order of rendering objects)



BlinX
02-27-2004, 08:34 AM
I have a problem with masking & depth, if I draw masked triangles/quads behind each and donít draw them in de right order the masked objects arenít visible.

I have tried the code from the NEHE masking tutorial and code loading a image to a texture with an alpha channel.

This is how it's supposed to look
http://www.blinx.nl/opengl/good.jpg

This is what happens if the
http://www.blinx.nl/opengl/bad.jpg

As you can see the front object isnít transparent anymore..

What I have tried is enabling / disabling the following options:

glDepthMask(true);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);

Iíve already found a kind of a solution and that is writing a custom depth testing function, I donít think thatís the best solutionÖ has anyone got a better way of solving this problem??

ZbuffeR
02-27-2004, 12:20 PM
In fact, apart from additive transparency, (almost) all blending modes are order dependant. There are a lot of people trying hard to do "order-independent transparency" (just Google for it) but it is often slow and complex.

So you do have to pre-sort your transparent faces, and draw them back to front, after drawing all opaque geometry.

zeckensack
02-27-2004, 12:33 PM
In this case, you may be able to get away with alpha test.

glAlphaFunc(GL_GREATER,0.5f);
glEnable(GL_ALPHA_TEST);

Alpha test, unlike blending, produces hard transitions aka aliasing, and it defeats multisampling (which is now the preferred way to reduce aliasing).

An edge that is alpha tested and blended may or may not block what is rendered behind it, depending on rendering order. If you don't like that, you can turn off blending (this will further sharpen the edges though).


[This message has been edited by zeckensack (edited 02-27-2004).]

BlinX
02-27-2004, 12:49 PM
Yes!! that works thanx alot guys !!