PDA

View Full Version : change register combiner's mux operator

kon
05-03-2002, 01:06 AM
Hi,

having an RGBA texture, I want to render only the parts which are in an alpha range of [a,b]. Two pass algorithm is working (using glAlphaFunc) but I want to do it in a single pass.
By using the register combiners' mux operations this could be done, but the mux selects A*B or C*D by comparing spare0's alpha to 0.5. So, my question is how to map the a and b so that they can be used in the mux operator, instead of 0.5?
Or is there another one pass algorithm to do it?

Thanks
kon

/edit adding/subtracting the difference of a,b and 0.5 to the texture's alpha values is possible but it takes a register combiner and I've got only two of them and these are needed for the two muxs!

[This message has been edited by kon (edited 05-03-2002).]

davepermen
05-03-2002, 05:26 AM
well.. if alpha < min, set out.alpha to 0
else set out.alpha to unsigned(max - alpha)

result: 0 in out.alpha if alpha > max, 0 in out.alpha if alpha < min..
check against 0 in the alphatest and you-re fine out..

alpha<min == alpha-min<0 == alpha-min+.5<.5
== alpha + (1-min) - .5 < .5

you have to calculate this in the general combiner 0, and store in spare0.alpha (with some nice bias and such this goes well.. spare0.alpha = unsigned_identity(alpha)+unsigned_invert(min) biased by .5)

calc (in the color combiner 0 for example unsigned(max - alpha) and store this in some spare0.rgb for example..

then in the second combiner alpha you can do the mux against spare0.alpha, and return eighter 0 or spare0.rgb.

glAlphaTest(GL_NOTEQUAL,0);

everything nonzero alpha will be okay..

hope that helped, cause i'm little confused myself.. long time no coding in the rc's anymore..

LordKronos
05-03-2002, 05:48 AM
I'm assuming you intend the a and b to be constants (not something pulled from a texture or anything). If so, just set the alpha test to only accept pixels with an alpha value >= a. Then all you need to do is configure the register combiners to output an alpha of 0 for pixels that have an alpha value > b, or the actual alpha value otherwise. You can do this as follows:

combiner 1: calculate b - alpha + .5 and output to spare0.alpha

combiner 2: make A*B = alpha, make C*D = zero, and the mux will select the correct one for you. Output the result as the spare0.alpha

final combiner: select spare0.alpha as your output alpha

Hopefully that is enough description. If you need actual code let me know and I can probably try to put it together.

LordKronos
05-03-2002, 05:50 AM
Originally posted by davepermen:
hope that helped, cause i'm little confused myself

You're not the only one confused by that http://www.opengl.org/discussion_boards/ubb/smile.gif

kon
05-03-2002, 06:50 AM
Ah, thanks I'll give it try this weekend! I'm not that much confused anymore!

kon