Need help setting blending for lightmapping


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?

Thanks folks :slight_smile:

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.


Hi :slight_smile:

Thanks for your answer! It’s cool getting response here so fast, this is my first posting here…

Anyway, the tex1*(tex2+tex3) thing is exactly what i don’t now how to set up.
I have even looked how id Software made it in QuakeI, but they only use one lightmap stage, so it wasn’t much help either.

Hope you can help :cool:

Here is how I draw my polygons now:

		glClientActiveTextureARB (GL_TEXTURE0_ARB); 
		glActiveTextureARB (GL_TEXTURE0_ARB);
		bind (_texture);
		// static lightmap
		glClientActiveTextureARB (GL_TEXTURE1_ARB); 
		glActiveTextureARB (GL_TEXTURE1_ARB);
		glBlendFunc (GL_ONE, GL_ONE);    			staticLightmap->bind ();

		// dynamic lightmao
		if (isDynamicallyLit())
			glActiveTextureARB(GL_TEXTURE2_ARB);	glClientActiveTextureARB (GL_TEXTURE2_ARB); 
_dynLightmap->bind ();
			glBlendFunc (GL_DST_COLOR, GL_ZERO);

// these are my wraps, but they're fine :)
			::glMultiTexCoord2fARB (GL_TEXTURE0_ARB, u,v);
			::glMultiTexCoord2fARB (GL_TEXTURE1_ARB, u1,v1);
			::glMultiTexCoord2fARB (GL_TEXTURE2_ARB, u2,v2);

glVertex3f ()

Sorry for the terrible code format, but the inputbox is too small for my lines…

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:

unit 0:
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // or GL_MODULATE if you want apply vertex color too

unit 1:

unit 2:

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.


Hey cool, works :slight_smile:

And my Manpage never told me about GL_ADD :stuck_out_tongue:

Anyway, thanks I owe you a beer :slight_smile:

Originally posted by headhunter123:
[b]Hey cool, works :slight_smile:

And my Manpage never told me about GL_ADD :stuck_out_tongue:

Anyway, thanks I owe you a beer :slight_smile: [/b]
This might be because it is exposed by an extension (GL_texture_env_add, i think).