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.
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.
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.
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?
You need two values in environment constant.
.x is the average of your minimum and maximum (non-culled) alphas.
.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 .x to 0.35 and .y to 0.15.