PDA

View Full Version : singlepass lighting question



02-15-2003, 04:38 PM
I've been working from a demo that does perpixel lighting in one pass and i've gotten it working but now i'm trying to add a constant ambient color to the equation..i might as well just throw the code up and see if someone can help

(i have gloss stored in diffuse's alpha)

code:
------------------------------------------
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, bump);

//Unit 1 - normalisation cube map
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalize_cubemap_id);

//Unit 2 - normalisation cube map
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalize_cubemap_id);

//Unit 3 - decal texture
glActiveTextureARB(GL_TEXTURE3_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, decal);

glActiveTextureARB(GL_TEXTURE0_ARB);

//Set up Register combiners
//3 general combiners
glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV , 4);

glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, gdlAmbient);


//combiner 0 does tex0.rgb dot tex1.rgb -> spare0.rgb,
/tex0.rgb dot tex2.rgb -> spare1.rgb
glCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB,
GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_TEXTURE1_ARB,
GL_EXPAND_NORMAL_NV, GL_RGB);

glCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE0_ARB,
GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV( GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_TEXTURE2_ARB,
GL_EXPAND_NORMAL_NV, GL_RGB);


glCombinerOutputNV( GL_COMBINER0_NV, GL_RGB, GL_SPARE0_NV, GL_SPARE1_NV, GL_DISCARD_NV,
GL_NONE, GL_NONE, GL_TRUE, GL_TRUE, GL_FALSE);




//combiner 1 does spare1.rgb * spare1.rgb -> spare1.rgb
//spare0.rgb * tex3.rgb -> spare0.rgb

glCombinerInputNV( GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV( GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);


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_TEXTURE3_ARB,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);



glCombinerOutputNV( GL_COMBINER1_NV, GL_RGB, GL_SPARE1_NV, GL_SPARE0_NV, GL_DISCARD_NV,
GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);


//combiner 2 does spare1.rgb * spare1.rgb -> spare1.rgb
glCombinerInputNV( GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV( GL_COMBINER2_NV, GL_RGB, GL_VARIABLE_B_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);




glCombinerOutputNV( GL_COMBINER2_NV, GL_RGB, GL_SPARE1_NV, GL_DISCARD_NV, GL_DISCARD_NV,
GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);

//combiner 3 does spare1.rgb * spare1.rgb -> spare1.rgb
glCombinerInputNV( GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);

glCombinerInputNV( GL_COMBINER3_NV, GL_RGB, GL_VARIABLE_B_NV, GL_SPARE1_NV,
GL_UNSIGNED_IDENTITY_NV, GL_RGB);



glCombinerOutputNV( GL_COMBINER3_NV, GL_RGB, GL_SPARE1_NV, GL_DISCARD_NV, GL_DISCARD_NV,
GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);


//final combiner outputs spare1.rgb*spare1.rgb*tex0.a+spare0.rgb
//First do spare1.rgb*spare1.rgb in EF multiplier
glFinalCombinerInputNV(GL_VARIABLE_E_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_F_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);

//Now do rest

glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_E_TIMES_F_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_TEXTURE3_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);


glEnable(GL_REGISTER_COMBINERS_NV);