PDA

View Full Version : Using env_dot3 with colored lights



RickA
01-29-2007, 12:27 PM
As a fallback path for my app, I'm attempting to implement colored per-pixel lighting using the env_dot3 extension and texture combiners. I have the basic full-white env_dot3 working with three textures:


// Normalizing cubemap
glActiveTexture(GL_TEXTURE0);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, normalizationCubeMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

// Normal map
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);

// Diffuse texture
glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
I'm having problems multiplying the output of the last step with the lighting color. I think adding the following should work:



// Multiply with light color
glActiveTexture(GL_TEXTURE3);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &light.colorDiffuse.x) // light.colorDiffuse is vec4f
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);However, this doesn't seem to do anything at all. What am I missing? I already have this working with GLSL, but would like to get this to work also if possible.

CrazyButcher
01-29-2007, 01:02 PM
have you bound some dummy texture to unit3? else the combiner wouldnt be used.

halo
01-29-2007, 01:55 PM
I think this is impossible. I was not able to figure this out a long while back.

dorbie
01-29-2007, 06:51 PM
Yea as butcher says you need to enable that unit, and maybe just reuse an earlier image for the bind. It won't be fetched. It should work in principal.

Dunno why halo says it can't be done. It's just a shame you have to burn a combiner to do this kind of thing, makes you develop an appreciation for fragment shaders.