Hi all,

does anyone know a sample implementation of lightmaps. I’m still quite confused how to generate the lightmap itself, and how to blend it with the original texture.

Thank you in advance,

Daniel Palomo van Es

can’t tell you about generating lightmaps, you may wanna check out quake or half life sdk sources. but assuming you have lightmaps already generated, to apply them:

// not using multi texture
bind texture
texcoords for texture
render poly
bind lightmap
set blend func to GL_ZERO, GL_SRC_COLOR
set blend on
texcoords for lightmap
render poly
set blend off

// using ARB_MULTI extension (way faster)
bind texture
bind lightmap

glMultiTexCoord2fvARB GL_TEXTURE0_ARB,texture
glMultiTexCoord2fvARB GL_TEXTURE1_ARB,lightmap

render poly


that helps a lot. Now left only the generation of lightmaps themselves…


To generate light maps, you basically have
to assign light maps to your geometry, then
run through each pixel of each light map,
inverse-mapping that pixel to a point in
geometry, and ray-trace from that point to
all the available lights to determine their
intensity at the point in question.

Now, there are tricks you can pull to make
this go faster, such as using low resolution
for the light maps (fewer points to trace per
poly, and less texture memory used) and not
tracing to lights which are too far away to
have any perceptible impact. In a portal
engine, you could also approximate the amount
of light emitted by each portal (from the
room beyond) and check for visibility of the
portal instead of lights within that room.

Umm… yeah, there’s a reason light map
compilers are sometimes slow, especially if
they’re accurate :slight_smile: