PDA

View Full Version : specifying alpha range using glAlphaFunc



malancha
03-22-2004, 08:50 PM
Is there any way to set an alpha test function such that it only accepts values lying in a specified range? Right now I'm only able to specify an upper or lower limit using GL_LESS or GL_GREATER.
It doesn't look like there's any such built-in parameter, but I was wondering if anyone's come across a workaround.

Thanks in advance.

dorbie
03-23-2004, 11:55 AM
There is no way to do this, but if you're using a texture you could try some kind of LUT to give you an upper and lower bounds test. You could also try two passes and source & destination, or multitexture and combine the alpha value from each unit to a single value. It really depends on your higher level objectives.

malancha
03-23-2004, 05:38 PM
First off, I'm not using textures. What I'm trying to do is display a translucent volume from a 3-D dataset. I'm keeping all my triangles white, and setting the alpha of each vertex proportional to the corresponding value from the dataset. I need to set upper and lower limits because I have to avoid both the low-valued noise as well as the opacity that can occur when the combined alpha values of overlapping triangles approaches 1.0. Basically, I don't want to see things that are either almost completely transparent or opaque.
I think I've blabbered a little here, I hope it's clear just what I'm trying to achieve.

charliejay
03-23-2004, 11:56 PM
First, a question - do all the vertices of a given triangle have the same Alpha?

Because, if that is the case, you could avoid using the alpha test, and just not draw triangles that fall outside your upper or lower limit.

Even if you can find a computation that effectively gives you a two-valued alpha test, it sounds like you're still going to run into problems with opacity when combined alpha values approach 1.0. Maybe an approach that makes use of the stencil buffer might avoid that?

CJ

zeckensack
03-24-2004, 05:50 AM
!!ARBfp1.0
PARAM stuff=program.env[0];
TEMP boogie;
SUB boogie.x,fragment.color.a,stuff.x;
ABS boogie.x,boogie.x;
ADD boogie,-boogie.x,stuff.y;
KIL boogie;
MOV result.color,fragment.color;
ENDYou need two values in environment constant[0].
[0].x is the average of your minimum and maximum (non-culled) alphas.
[0].y is the range around that average that you want to have visible.

Eg if you want the range 0.2 to 0.5 to be visible, set [0].x to 0.35 and [0].y to 0.15.

*untested*