color leak on lightmap edges

I have made some lightmap tests, the small lightmaps I used are packed into one big bitmap. And I found at the edge of polygons, some color “leak” into each other, specially at an edge of a bright polygon and a dark polygon(I hope I can make it clear by this, English is not my tongue). I know this is because the polygons have different lightmaps, and the pixels are blend at the edge because of linear filtering. How can I avoid this effect?

You could use a texture clamp instead of repeat for the wrap, but if you are using a single texture for many light maps they you will have to pad the image to avoid the leak, as the MIP map minifies you may see the problem resurface.

First of all, do not use mipmapping for your lightmaps. For obvious reasons, the texels of different lightmaps will blend together if you do it.

Texture clamping will not be of any help since it only work at the boundary of the texture, and all the small lightmaps are packed inside the same texture.

There are generally 2 solutions to that problem:

  1. You can make sure that two adjacent faces end up with two adjacent lightmaps in the pack. Pretty tricky to do.

  2. Duplicate the pixels around the small lightmaps. This eventually add a 2 pixels border to each small lightmap (for example, a 16x12 lightmap becomes 18x14). Generally, you do not relatively loose a lot of space, except if you are using very small lightmaps. The advantage is that it’s pretty easy/fast to implement.

Y.

I definately don’t recommend using one lightmap per poly, that increases resources (textures, bus transfers and the like) dramatically. The standard accepted practice that most people seem to use is to pad the projected poly’s. To be more clear when you project multiple polygons onto your lightmap plane (usually a world plane) you must check for overlap and if necessary create multiple light maps to correct for this. By padding I simply mean that a lightmap should contain 3 possible values. Lit texels, unlit texels and padding texels (often called sanding texels) that surround the polygons so that when blending occurs one poly will not grab another poly’s light. Its that simple, usually its part of the sorting and overlap tests. Its just one of those things you have to do. As for mipmapping I don’t recommend mipmapping light maps as they are usually very low res at least when mapped onto the polygon. I use no mipmapping with nice filtering.

Happy Coding.

This is actually easy to fix. Just make sure you are creating the smaller lightmaps (the ones you will put into a larger texture) large enough to cover the entire surface area of the polygon. The most important thing you have to do though, is make sure you align your UV’s so that they are centered at the texel centers. If you don’t do this, filtering will grab the color from one of the neighboring lightmap texels, which is what you don’t want.