How does lightmapping actually work??

Blitz3D Forums/Blitz3D Programming/How does lightmapping actually work??

bytecode77(Posted 2007) [#1]
hm, i would be interested in making a good lightmapper, but there are a couple of questions i do not understand...

1. how does the lightmapper recognize a "surface" - you know what i mean...
2. how are the final images stored in the lightmap image file? how are they sorted?

you know me - i like doing that, i'm a demo scener myself. and open source, too :)
anyway... awaiting your answers, but i can not promise, that i understand this ;)
bye


Gabriel(Posted 2007) [#2]
I don't think I understand either question.

What's a surface? You mean several triangles which have an identical surface normal? Or several triangles which have smoothed edges between them ( like an entire sphere would be one surface? )

You mean how are the sections packed together? From memory, I think the quick and dirty method is to sort by width as the first key and height as the second key ( the second key being the one you use when you get two items with the same first key ) and then zig zag back and forth across the texture, left to right, right to left, filling in images as you go, in each case going through the list in sorted order until you find the widest image which will fit.


bytecode77(Posted 2007) [#3]
a surface is a bunch of gapless polygons facing into the same direction.

and i mean this with the sorting algorithm



Gabriel(Posted 2007) [#4]
Well you're going to spot "surfaces" by starting with one triangle and then finding all triangles which share at least one vertex with that starting triangle or any of the other triangles you've decided are part of that surface and have the same surface normal. If you want to lightmap smooth curves, you will want to disregard the surface normal requirement.

I already answered the sorting algorithm. I'm sure there are lots of ways of doing it, some better than others, but the width sort I mentioned worked pretty well for me.


bytecode77(Posted 2007) [#5]
hm. is there a working sample in the forums (i can understand ;D )?


Gabriel(Posted 2007) [#6]
There's a complete lightmapper in the code archives. I don't know if you'll understand it or not. I couldn't make much sense of it, but I'm not very good at reading other people's code, so perhaps you'll do better than me.

http://www.blitzbasic.com/codearcs/codearcs.php?code=794


bytecode77(Posted 2007) [#7]
hm thats what i was talking about; i cant read peoples code so good, too. especially code that long :(


Wings(Posted 2007) [#8]
I am laning for voidrpg.
1) using normal lighning.
2) using vertex color to add more Dark surface from trees.

the problem with my method is that is verry verry not detailed at all.


bytecode77(Posted 2007) [#9]
* devils child shuts his mouth tight


jfk EO-11110(Posted 2007) [#10]
I had a little lightmapper project in this forum section, it even supported GI. There was a little Bug with sawtheeth rounding problems with masked Textures, may be solved somehow. Plus, the speed was miserable.

However, it worked.

First all tris are unwelded. THen every triangle is UVmapped, just watched from above it (aligned to the triangle normals), so there's optimal UVmapping. Then the tris on the UVmap should be sorted and aligned in an optimized way.

If you once got the UVmapping done, the rest is easy IMHO. Simply check every texel. if it can see the lights, add a certain value (eg. -distance*lightcolor) to a light-parameter for each texel. finally draw this texels light-parameter to the lightmap.

BTW here's the mentioned thread:
http://www.blitzbasic.com/Community/posts.php?topic=71137#796234

And I never said that this is how lightmapping actually works :)


Gillissie(Posted 2007) [#11]
Hey jfk, the link to your lightmapper Slim Shady doesn't seem to have anything to download except music.
http://www.melog.ch/slimshady/


jfk EO-11110(Posted 2007) [#12]
Yeah, strange. thanks for reporting, will try to fix it. Could be a bug in a ftp client that I recently used. Or maybe I dropped something by accident and didn't notice.
EDIT - ok I hopefully fixed it. I have no idea how the file was copied to that folder.


bytecode77(Posted 2007) [#13]
hm 1.500 lines of code... will need time to check this through. thanks a lot! :)


chwaga(Posted 2007) [#14]
while you two are on the topic of slimshady, how can I get a lightmap of over 2048 x 2048 resolution?? Cause I've got a huge building I want light-mapped, but with the max 2048 resolution, It looks kinda crappy. (PS: Devil's child, if you make that lightmapper, let me know )


Naughty Alien(Posted 2007) [#15]
..try to use multiple lightmaps...


Pete Carter(Posted 2007) [#16]
anything over 2048x2048 will be incompatable with most graphics cards like Naughty alien says use multiple light maps.


chwaga(Posted 2007) [#17]
k


bytecode77(Posted 2007) [#18]
i would set the maximum of a texture size to 1024x1024. thats a good deal for every gfx card. to 512x512 on older games


chwaga(Posted 2007) [#19]
I figured out the problem, It was the lumel's thanks