Lightmap problem

Just finished my lightmap functions in my engine though there is a big problem; how to render lightmaps on surfaces that is very dark.

Right now I just draw the scene with vertex lighting and then I draw my lightmaps blended with (GL_ONE,GL_ONE).

Do I have to pass the “original” texture again or is there any other way.

Well usually what happens with engines which use lightmaps is that they will brighten up the textures quite a bit then apply the lightmap. Here is a code clip from the aftershock engine doing this:

/* Not really a gamma: prelighten the texture to compensate for
darkening after lightmap application. /
FIXME: should alpha be brightened too? */
if (r_gamma != 1.0)
int i, val;

for (i=0; i<size; ++i)
val = tex[i] * r_gamma;
if (val > 255) val = 255;
tex[i] = val;

Hope that helps some.


I’m not a big fan of lightmaps, but wouldn’t it be better to simulate the diffuse term by multiplying the textures together?

If you are using multitexture, then GL_MODULATE will work and you don’t need to turn on blending. glBlendFunc(GL_DST_COLOR, GL_ZERO);


With lightmapping you DO multiply the lightmaps together. But usually the base texture needs to be brightened up a bit. Otherwise the base texture is a bit dark. This is how all of the quake engines do it. I assume the other engines which does lightmaps do the same thing.


[This message has been edited by SirKnight (edited 07-18-2002).]

Ok, so what you do is to brighten up the textures manually when loading them?

The thing is that I also use vertexlighting.
Surfaces not struck by any vertexlight is nearly black, if I put a lightmap onto this surface the underlying texture wont be visible at all ( since it’s nearly black ).

In my engine everything is black if there is no light, maybe I should do the other way around? To darken the scene where no light is present? Or a combination of both?

Any advice would be helpful.

if you are using lightmaps, you shoudn’t use vertexlighting at all. that’s because your lightmap allready contains the full lighting information and in this way, you darken your polys twice…

Why not combining them?

For some purposes vertexlights are a better choice and for some they are not.

Are you saying that I have to make a choice?

You can try using both together and see if you like what it gives you, I dont think it would be so bad as long as what your lighting up w/ vertex lights are reasonably tesselated, and your using attenuated lights. As a side note, take a look at Quake 3. If you choose vertexlighting in the opetions, notice all the lightmaps are gone? Likewise if you select lightmaps, there is no vertex lighting going on. Lightmapping engines which want to light other objects and to make an entity glow or whatever usually use a dlight. Which is really a fake dynamic light using a lightmap of some sort. Nate Miller has a demo of dlights. It looks pretty good for a fake dynamic light. If you want that kind of thing. His web page is:

Now, I wouldn’t see any harm in using lightmaps with dynamic per-pixel attenuated lights. I think that would work better together than vertex lighting. But thats just me.


[This message has been edited by SirKnight (edited 07-19-2002).]

ok, think I’m getting to understand now =)

What was shooting for was just to use the best lighting for it’s purpose.
As I said before in some situations vertex lighting is better than lightmaps but for some purposes lightmaps would be better.

That’s why I tried to combine them both, but it seems like I have to make a choice here :stuck_out_tongue:

Well, thank you for all your replies. It’s been very helpful.

There is no difference in how you prepare your textures for light maps vs vertex lighting.

Diffuse color textures should be created by artists with full-bright color range (which will look very bright). Then, whatever lighting you use (vertex, map, per-pixel) will dim it down to whatever is appropriate for the fragment being rendered.

If you’re seeing a big difference between light maps and vertex lighting, perhaps your light maps are being generated too dark?