I want to set the last texture unit to the normal map and blend it with the result of the previous texture units, in a way such that the normal map both lightens and darkens the texture.
I am trying to do it like this, but my normal maps come out almost full black. Every vertex in the color array is set to (196,196,255), just for testing, so I know the vertex colors aren’t a problem:
If you set the normal map to the last texture unit in the way you do, you are doing dot3 operation between normal map and color result from the previous texture units interpreted as vector. The resulting nonsense greyscale value is used as final color.
You need to set the normal map dot3 operation to the first unit and modulate its output with whatever the other texture units are doing.
I set the bumpmap up on texture unit 0, like this:
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_SRC_COLOR
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE
Like this, I can’t see the bumpmap, even when I turn off all other texture units. I had tried several other variations, keeping the normal map on texture unit 0.
Okay, I got it to work using this:
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE
I found that I got the most correct lighting by setting the blue value to 192 (halfway between 128 and 255) and using a mod2x blend on the next texture unit using “glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,2.0”. This made the normal map brighten and darken the texture.
Looks like you got it, there was some dodgy advice given earlier, you need to do your DOT3 first then modulate. If you use crossbar it’s slightly less of an issue but the point is you need to get your DOT3 result THEN do something with it like modulate another texture, taking anything other than meaningful vectors into a DOT3 will produce garbage.
It looks to me like he is just drawing on the cubemap to move lights around. This is like a dynamic lightmap, but even more limited, since it will only work on a box-shape room with the camera in the center.