I am rendering static lightmaps on my 3D scene as well as dynamic lightmaps.
So when I render my polygons, I set the normal texture on stage0, stage1 is my static lightmap, and on stage2 comes the dynamic lightmaps.
This works really fine, blending the texture with the static lightmap is really nice, but I can’t
get the renderstate for stage1 right.
The objects seem to get darker when light shines on them, not brighter as they should be.
Which states do I have to set for the second stage when I want two staged lightmapping?
what exactly do you mean with “stage”? texture unit?
the formula you have to compute is tex1*(tex2+tex3), with tex1 being the color map and tex2/tex3 the light maps.
In a fragment program, this would be extremely simple. But I guess you are using standard OpenGL multitexturing. I think it is also possible to do with the texture_env_combine extension, which your graphics board will support if it has four texture units.
I am not sure about how to do it with standard OpenGL multitexturing but it should be possible as well. But look for GL_TEXTURE_ENV_COMBINE, this will definitely do it.
Your code is wrong… You can’t setup BlendFunc per texture unit. BlendFunc are applyed only to framebuffer. You have to use reg combiners for that. You can’t setup multitexture for result = vertex_color * tex0 * (tex1 + tex2).
If you reverse formula like result = (vertex_color * tex0 + tex1) * tex2 you can use multitexture,
but tex0 and tex1 are lightmaps and tex2 are material texture. In this case you could do following setup:
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // or GL_MODULATE if you want apply vertex color too
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Multitexture setup use formula: result = ((((vertex_color env0 tex0) env1 tex1) env2 tex2) envN texN) where env0…envN are texture_env_mode for unit 0…N and tex0…texN are textures for units 0…N.