PDA

View Full Version : Old problem.



MrShoe
06-24-2002, 11:22 PM
This is my problem:
I have a billboarded quad with a texture on it. The black pixels of the texture are given an alpha value of 0.0 and the rest are 1.0, then i turn on alpha blending with function GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
This will make the black parts of the quad transparent.

Now, say i want to have this quad and another similar quad rotating around a certain point. I will begin to get artefacts as the quads rotate around this point because of the transparent parts of the quad blocking out the quad behind it even though they are meant to be transparent, but it still remains transparent to all pother geometry. I know this is a problem with depth sorting, but is there are simple way to fix this other that sorting MANUALLY the quads??

JML
06-24-2002, 11:39 PM
For on/off alpha features you can use the alphatest feature. The fragments failing the test will be rejected and thus not update the screen buffer (including depth buffer).

Jean-Marc.

Jan
06-25-2002, 05:39 AM
I had the same problem some days ago. Itīs quite easy to solve.

Either you sort your objects by depth, which would always work, but is quite much work especially in particle-systems,
OR you disable depth-writing. This means that depth-values are calculated and compared to each other, but when you actually draw an object, its depth-values are not written to the depth-buffer. Therefore every other object will be drawn upon it but in particle-systems you usually donīt see this. So if it does not matter for your program, if the objects are not drawn in the correct order, you could use this.

You can do this with glDepthMask (GL_FALSE).

Hope that helps you.
Jan.

MrShoe
06-25-2002, 04:24 PM
Yes, but if i set the depth mask to 0 then there will be depth sorting problems. eg: the billboard that is really behind another billboard will sometimes be rendered in front of the front billboard-a depth sorting problem.

I think the first reply solution is the correct one. Is it simply glEnable(GL_ALPHA_TEST);
And this will simply ignore the texels of the texture with 0 alpha value?

JML
06-25-2002, 09:03 PM
Originally posted by MrShoe:
I think the first reply solution is the correct one. Is it simply glEnable(GL_ALPHA_TEST);
And this will simply ignore the texels of the texture with 0 alpha value?

Almost. First you have to set the test value to use and the type of comparison with glAlphaTest( func, ref). Func is one of GL_NEVER, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_ALWAYS or GL_NOTEQUAL; ref can be anything from 0.0 to 1.0.
Then you enable the test with glEnable( GL_APLHA_TEST).

HTH

Jean-Marc.

MrShoe
06-25-2002, 09:43 PM
Thanks alot...