Funny, that was actually the purpose of an Effect I submitted to the nVIDIA contest that took place some time ago (no wonder why I didn’t win a thing…).
Actually, I did two versions: one with texture shaders (which was the aim !) and then one with the register combiners (after I realised that it was the most obvious and simple solution…).
Anyway, here is the snippet that sets the RC up:
// Texture 0 - Normal texture//
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,1);
glEnable(GL_TEXTURE_2D);
glEnable(GL_REGISTER_COMBINERS_NV);
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV,2);
float fGreyscale[4]={0.3,0.59,0.11,1};
glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV,fGreyscale);
float fAlpha[4]={0,0,0,fFade};
glCombinerParameterfvNV(GL_CONSTANT_COLOR1_NV,fAlpha);
// Combiner 0 calculates the grey texture //
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_A_NV,GL_TEXTURE0_ARB,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV,GL_RGB,GL_VARIABLE_B_NV,GL_CONSTANT_COLOR0_NV,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glCombinerOutputNV(GL_COMBINER0_NV,GL_RGB,GL_SPARE0_NV,GL_DISCARD_NV,GL_DISCARD_NV,GL_NONE,GL_NONE,GL_TRUE,GL_FALSE,GL_FALSE);
// Combiner 1 interpolates between grey and color //
glCombinerInputNV(GL_COMBINER1_NV,GL_RGB,GL_VARIABLE_A_NV,GL_TEXTURE0_ARB,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV,GL_RGB,GL_VARIABLE_B_NV,GL_CONSTANT_COLOR1_NV,GL_UNSIGNED_IDENTITY_NV,GL_ALPHA);
glCombinerInputNV(GL_COMBINER1_NV,GL_RGB,GL_VARIABLE_C_NV,GL_SPARE0_NV,GL_UNSIGNED_IDENTITY_NV,GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV,GL_RGB,GL_VARIABLE_D_NV,GL_CONSTANT_COLOR1_NV,GL_UNSIGNED_INVERT_NV,GL_ALPHA);
glCombinerOutputNV(GL_COMBINER1_NV,GL_RGB,GL_DISCARD_NV,GL_DISCARD_NV,GL_SPARE1_NV,GL_NONE,GL_NONE,GL_FALSE,GL_FALSE,GL_FALSE);
glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
Hopefully this is enough for you to go on (I don’t remember the effect itself very well but I can have a look if something is missing).
If you want the full source code, I can e-mail it to you.
Regards.
Eric
EDIT: Just remembered that this actually more than you need ! This piece of code also interpolates between the greyscale version and the colored one according to the alpha value of GL_CONSTANT_COLOR1_NV… Anyway, you should be able to remove the useless part !
[This message has been edited by Eric (edited 03-07-2002).]