Skip to main content
gamedev.net
🔒 Locked

Lightmap UVcoords

Started by visla 6 replies 1.8k views
Original Post
visla
visla
Ok. I want to make lightmaps in my engine. How do I make uv coords for lightmaps. Is planar mapping sufficient for all cases or is there any better way. In my editor you put some objects and lights into scene and after finishing you can make lightmaps for all objects in world. So I need to know what is the best method to get UV coords of each vertex for lightmap.
If you don`t do something, something will do, something to you!
reiko
reiko
Coming up with UVs for lightmaps is a nontrivial problem, and requires a bit of effort. The best approach I know of is:

1) Chop your scene into groups of roughly co-planar polygons.

2) Choose a planar mapping for each group which gives roughly the same amount of lightmap texture space per area for all polygons (can be done by just taking an average normal and scaling as needed)

3) Project each group into UV space using these mappings

4) The hardest part: rearrange the groups so that they fit onto the fewest lightmap textures possible, without any overlaps, and leaving as little unused space as possible.

Step (4) is often done by simple random "does it fit here?" tests until either the space is filled up or a given time elapses.

Then you can do all your lighting calculations to generate the lightmaps.

Hope that helps.
Daaark
Daaark
You could take alook at the fluid studios radiosity processor. It's free , and it comes with source. You could either learn from it, or just have it lightmap your scene as is.

Clicky
Enrico
Enrico
Here are some links, that cover texture coordinate generation with lightmaps:

http://www.flipcode.com/articles/article_lightmaps.shtml
http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64423
http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64483
http://www.alsprogrammingresource.com/lightmapping_tutorial.html
--
JakeM
JakeM
I've looked into this a long time ago, and they all use the same method.
Simply drop the largest x,y,z component, and use the remaining two as the
projected UV coordinates. That's the easy part.
blackpawn
blackpawn
yeah my packer is focused on rectangles and not general shapes. it worked great for the lightmaps i was making and i've also used it successfully for dynamically packing font glyphs and rasterized font strings and combining many textures into atlases. i even at one point hacked it into the quake3 tools to test against the algorithm they were using and it cut the number of lightmap textures required for a map down quite a bit.

if you're packing arbitrary shapes and it's all offline there are many other algorithms out there that will stack things tetris style and try all the rotations etc. D3DX has the UVAtlas stuff now to pack charts from a mesh which you could use as well.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.