simple register combiner question

sorry for posting such a simple question - the documentation for register combiners did not yield the secrets i need…

texture unit 0 is a normal 2D/3D texture fetch
texture unit 1 is AR dependent on unit 0, producing R1G1B1A1
texture unit 2 is GB dependent on unit 0, producing R2G2B2A2

i want the final RGBA color to be the AR from the stage 1 fetch, and the GB from the stage 2 fetch.

i.e. R1G2B2A1 -> RGBA

i know there might be a way to do this with CG or RC1.0 using .rgb swizzle notation, but what is the equivalent glFinalCombinerInputNV function call?

anyone?

is there any good documentation for register combiners in general? the specs just don’t lend themselves to intuitive real-world examples.

is there an in-general way to do swizzle type stuff with the combiners?
finalcolor.r = unit1.r
finalcolor.g = unit2.g
finalcolor.b = unit2.b
finalcolor.a = unit1.a
???

check out http://www.delphi3d.net, he’s go a terrain demo that uses register combiners that blends between different textures depending on the alpha values of each vertex. That is if this is what you’re going for.

It’s been a while since I touched these extensions, but I dont recall anything about swizzling with reg_comb (1 and 2)
The kind of swizzling you can do there is sample BLUE from the ALPHA combiner, which is limited.

You should look into NV_texture_shaders. have fun!

Well, perhaps I don’t completely understand your question, but what you ask is pretty obvious: finalColor=(1,0,0,1)*tex1+(0,1,1,0)*tex2

static const float c0[]={0.000000f,1.000000f,1.000000f,0.000000f};
glCombinerStageParameterfvNV(GL_COMBINER0_NV,GL_CONSTANT_COLOR0_NV,c0);
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV,1);
glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION_NV,GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION_NV,GL_DEPENDENT_AR_TEXTURE_2D_NV);
glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE_INPUT_NV,GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE2_ARB);
glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION_NV,GL_DEPENDENT_GB_TEXTURE_2D_NV);
glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE_INPUT_NV,GL_TEXTURE0_ARB);
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_A_NV,GL_TEXTURE1_ARB,GL_SIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV,GL_ALPHA,GL_VARIABLE_A_NV,GL_TEXTURE1_ARB,GL_SIGNED_IDENTITY_NV,GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_B_NV,GL_CONSTANT_COLOR0_NV,GL_UNSIGNED_INVERT_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV,GL_ALPHA,GL_VARIABLE_B_NV,GL_CONSTANT_COLOR0_NV,GL_UNSIGNED_INVERT_NV,GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_C_NV,GL_TEXTURE2_ARB,GL_SIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV,GL_ALPHA,GL_VARIABLE_C_NV,GL_TEXTURE2_ARB,GL_SIGNED_IDENTITY_NV,GL_ALPHA);
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_D_NV,GL_CONSTANT_COLOR0_NV,GL_SIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV,GL_ALPHA,GL_VARIABLE_D_NV,GL_CONSTANT_COLOR0_NV,GL_SIGNED_IDENTITY_NV,GL_ALPHA);
glCombinerOutputNV(GL_COMBINER0_NV,GL_RGB,GL_DISCARD_NV,GL_DISCARD_NV,GL_SPARE0_NV,GL_NONE,GL_NONE,GL_FALSE,GL_FALSE,GL_FALSE);
glCombinerOutputNV(GL_COMBINER0_NV,GL_ALPHA,GL_DISCARD_NV,GL_DISCARD_NV,GL_SPARE0_NV,GL_NONE,GL_NONE,GL_FALSE,GL_FALSE,GL_FALSE);

thanks. this is what i was looking for. i’ll have to try it out.

sometimes it just takes a simple example to get the snowball rolling…

one more thing…

how does the result of combiner 1 get mapped to the final pixel color? is it implicit in the combiner state?

as far as i can tell, each combiner outputs several rgba vectors, so how do you say which is used for the final color. also, is the Final Combiner always used, even if you say you are only using 1 general combiner, or is it implicitly included in the NUM_CONBINERS count?

The final combiner is always active, and is not included in NUM_GENERAL_COMBINERS.

The final combiner is also responsible for mapping register contents to the final fragment color. I think in the default state the final combiner sources from SPARE0_NV (haven’t checked that though, it’s somewhere in the extension spec). So AFAICS h2’s code should work.

i checked the specs and i think you both are right (it’s hard to tell - the specs aren’t exactly crystal clear in this respect).

it would be so lovely if there was a set of docs that gave several example equations to be computed and the corresponding combiner states. i guess this is all moot since we have nvparse and Cg, but i’ve always felt that understanding things at the most basic level helps the understanding at higher levels…

http://oss.sgi.com/projects/ogl-sample/registry/NV/register_combiners.txt

The final combiner is setup initially to implement OpenGL 1.2’s standard color sum and fog stages.

Table NV_register_combiners.6 shows exact setup. If for some reason you want to set output to SPARE0_NV explicitly, add following

glFinalCombinerInputNV(GL_VARIABLE_A_NV,GL_ZERO,GL_UNSIGNED_INVERT_NV,GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV,GL_SPARE0_NV,GL_SIGNED_IDENTITY_NV,GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_C_NV,GL_ZERO,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV,GL_ZERO,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV,GL_SPARE0_NV,GL_SIGNED_IDENTITY_NV,GL_ALPHA);

[This message has been edited by h2 (edited 11-13-2003).]