Dot3 bumpmaping + lightmaps + glColor3f

Started by
3 comments, last by Daivuk 18 years, 10 months ago
Hi there I have a little prob with my new engine when combining my lightmaps and my dot3 bumpmaping. The prob is I want to set the color of the result with glColor3f, and it doesnt work. Here is what I do in pseudo code : for all lightmaps layer ARB multitexturing layer 0 : Colormaps for the normal map ARB multitexturing layer 1 : The texture normal map ARB multitexturing layer 2 : Modulate with the lightmap (gray levels, GL_LUMINANCE) The result is perfect with multiple lights, now I want to add color to the light. So i put a glColor3f(1,0,0); for example, but the lighting still white!! The problem is more with the combiner GL_COMBINE_RGB that I'm not sure to fully understand lol. Here is the code for this :

glColor3f(1,0,1); // The light color

// Dot3 bumpmaping
eElement::glActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->normalTextureID);
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);

eElement::glActiveTextureARB(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureMat->bumpMap.textureID);
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);

// Lightmap
eElement::glActiveTextureARB(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->textureID);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB,GL_PRIMARY_COLOR);

Thanks for help!
Advertisement
Quote:Original post by Daivuk
eElement::glActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->normalTextureID);
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);
You probably want to change that to...
Element::glActiveTextureARB(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->normalTextureID);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_PRIMARY_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
Otherwise you are telling it to ignore any incoming color and just use for texture's color for texture unit 0. Setting it to modulate and one of the sources to GL_PRIMARY_COLOR tells OpenGL to multiply the incoming color (ie: from glColor*) with the color from source1 (which is the texture in this case).

Check out the spec for GL_ARB_texture_env_combine, it contains everything you need to know for using it.
Ok i understand more now with the site you just gave me, thanks.
But you wrote the code for the texture level0
So me its for the level2, where I want my lightmap getting the primary_color.
So i did this :

eElement::glActiveTextureARB(GL_TEXTURE2);glColor3f(1,0,1); // Magenta, testglEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->textureID);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_PRIMARY_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);



And its not working :(
Now I see the color and the lightmap good, but no more bumpmap lol

[Edited by - Daivuk on June 13, 2005 1:00:35 PM]
Quote:Original post by Daivuk
Ok i understand more now with the site you just gave me, thanks.
But you wrote the code for the texture level0
So me its for the level2, where I want my lightmap getting the primary_color.
So i did this :

*** Source Snippet Removed ***

And its not working :(
And of course, I tried first what you told me to put it on my dot3 level0.
Ah sorry, I thought you were saying that unit0 is your diffuse map, unit1 is your normal map, and unit2 was your lightmap.

Conceptually I was seeing it as you want to modulate the object's color with glColor3f instead of what you want (modulating the light's color). In that case, what you were trying to do is correct but you can't do it because GL_MODULATE only multiplies two sources together so you can't do (previous * lightmap * primary).

I think modulating the diffuse map should have the same result as modulating the lightmap, although with the dot3 I could be wrong (I never really used that since I got into shaders).

Speaking of which, using shaders would make this very simple so if you don't mind requiring shader support I would definitely suggest going that route.

Also, even though you say it's working perfectly without the color you should be setting the source0 and source1 for your texture unit2 as well. Texture environment settings are per unit so it doesn't carry over from the glTexEnv call on texture unit1 (if that's what you were expecting). The defaults are source0 = GL_TEXTURE and source1 = GL_PREVIOUS so that's probably why it's still working. I suppose you could've been counting on them being the defaults, but it's safer to set them to what you want so that you know that's what it is and the state isn't getting messed up somewhere else in your program.

Phew... now onto trying to fix it. The only way I can think of is to make unit0 your diffuse texture and unit1 your normal map and use modulate to multiply the primary color and texture color. Then on unit1 you dot3 with previous and texture, then unit2 modulates with previous and texture. I think that will have the same effect you are looking for, but again I'm not sure if the dot3 will mess with it.

EDIT: Eww, sorry that was such a long and rambling post. I hope that stuff at the end fixes your problem. If not I think the only way to get around it is to use shaders.

EDIT2: Another possibility is to use GL_ATI_texture_env_combine3 or GL_NV_texture_env_combine4, but there's no operation for (arg0 * arg1 * arg2) in any of those, so even if you could mess with it to get what you want it's probably not worth the trouble. Plus they are vendor specific, which you should try to stay as far away from as possible.
No the prob is the dot3 need 2 stages, but now ITS WORKING YEA!!!
I come with a solution with 4 levels :

level0 dot3 with level1
level2 (only promary color) * level1
level3 (lightmap) * level2

(LightmapNormalMap dot3 normalMap) * color * lightmap


eElement::glActiveTextureARB(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->normalTextureID);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);eElement::glActiveTextureARB(GL_TEXTURE1);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, textureMat->bumpMap.textureID);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);eElement::glActiveTextureARB(GL_TEXTURE2);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->textureID);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_PRIMARY_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);eElement::glActiveTextureARB(GL_TEXTURE3);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, ptrLM->textureArray->textureID);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_TEXTURE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);


:D:D
Thanks to lighted me up with the combiners. I understand more now.

This topic is closed to new replies.

Advertisement