PDA

View Full Version : Lightmapping



DPalomo
11-14-2000, 11:34 PM
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

beavis
11-15-2000, 02:27 AM
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)
glActiveTextureARB(GL_TEXTURE0_ARB);
bind texture
glActiveTextureARB(GL_TEXTURE1_ARB);
bind lightmap

glMultiTexCoord2fvARB GL_TEXTURE0_ARB,texture
glMultiTexCoord2fvARB GL_TEXTURE1_ARB,lightmap

render poly

DPalomo
11-15-2000, 04:05 AM
Thanx,

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

Daniel

11-15-2000, 06:32 PM
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 :-)