Skip to main content
gamedev.net
🔒 Locked

Lightmap bleeding

Started by gorgorath 4 replies 1.2k views
Original Post
gorgorath
gorgorath
aaaaargh... i can't seem to fix it: http://home.hccnet.nl/pj.holverda/vaag.JPG my first version of the lightmap generator, stored all lightmaps in individual lightmaps ( one for each polygon ) But after reading about the expensive calls of texture binding i've decided to store them into one( 512*512 pixels in my case ) larger lightmap image. This all worked well. But the lightmap bleeding still occurs even though my u, v ( or S, T ) coordinates never exceeded the [0....1] bounds, i even tested them and it don't seem to happen. What could be the cause of this, ain't I'm calculating my S,T coordinates correctly( which seems to be odd, since the shadows on the geometry appears correctly ) or is it another problem since i basically stretch the lightmaps across the polygon( lightmaps on a abitrary surface can be adjusted, from 2 World-Units a lumel to 128 World Units a Lumel ) so anyone can help me out here This is my Lightmap code (JAVA )(clamping is not necessary): public void lightmapCoordinates( LightmapRectangle rect, BSPFace face ) { float s, t, s_offset, t_offset, new_s, new_t; float lightmapDimension = (float) Config.LIGHTMAP_DIMENSION; //loop through vertices, adjust their s,t coordinates for ( int i = 0; i < face.getNumberVertices(); i++ ) { s = face.getVertices().getS(); t = face.getVertices().getT(); if( s < 0.0f) { s = 0.0f; } else if( s > 1.0f ) { s = 1.0f; } if( t < 0.0f ) { t = 0.0f; } else if( t > 1.0f ) { t = 1.0f ; } s_offset = rect.getLeft() + s * rect.getWidth(); t_offset = rect.getTop() + t * rect.getHeight(); //todo speed up (use bit-shift since dimension are power of 2) new_s = s_offset / lightmapDimension; new_t = t_offset / lightmapDimension; face.getVertices().setLightmapCoordinates(new_s, new_t); } } Cheers, Paul
Cosmic Keys to my Creations & Times
Jan-Lieuwe
Jan-Lieuwe
You probably have filtering on. In that case the neighbouring pixels in the texture are also sampled. What might help is to slightly enlarge each of the lightmaps in your 512x512 texture. Or you could repeat the edge pixels.

This will prevent the filter from sampling outside the lightmap.

I think I've seen a tutorial on flipcode which also mentions this problem.

/searching google...

http://www.flipcode.com/articles/article_lightmapping.shtml
ParadigmShift
ParadigmShift
Not sure exactly what you're doing there, gorgorath, but if by "bleeding" you mean pixels from one poly bleeding onto another poly, then it's likely that your polys are being placed too close together in the lightmap. For a 512x512 lightmap, your polys should have at least a 1/512 gap between them in ST space, and a similar gap from the edge.

I see Jan-Lieuwe brought up the filtering issue. To combat this you need a bigger gap and you need to fill the gap with texels which are similar in color to the border of the poly, via "smearing". These issues should be addressed in any good tutorial on lightmapping.

-Tom
"E-mail is for geeks and pedophiles." -Cruel Intentions
mikeman
mikeman
I'll answer this assuming your texture coordinates are correct, because there is no way for me to know if they really are.

First I would suggest to set the wrapping mode to GL_CLAMP_TO_EDGE, just in case. Second, do you use mipmaps? Mipmapping could work when the lightmaps were stored individually, but since you're using a single 512x512 texture, the downsampling for generating the mipmaps will definately cause bleeding. I just use GL_LINEAR for filtering, and everything looks fine. I suppose you could also generate mipmaps for each individual lightmap, and then pack them all together again to build the "big" mipmaps. I would suggest just using GL_LINEAR though.
gorgorath
gorgorath
EDIT: after first 'whitening' larger image it turned out that the mip-mapping was creating the bleeds :) thnks again



hmmm, thanks for the replies, but i still haven't been able to fix it,

http://home.hccnet.nl/pj.holverda/night_merry_christmas.JPG

look at the screenshot above( the lightmaps are extremly high-res '4 World-Units-to-lumel' ) The edges seemed to be almost gone, but they are still there only smaller.

@ParadigmShift:

The bleeding occurs not between different polygons, it's just seems ( to me ) that the lightmap is wrapped( only 1 pixel ) on the polygon itself. Because I had when i stored each lightmap individually.

@ all: Is it really necessary to generated mip-maps for lightmaps, since they're scaled pretty much? I don't think it make that much of a difference( maybe in terms of memory wise it would be useful though )




Paul
Cosmic Keys to my Creations & Times
gorgorath
gorgorath
I've got it all solved, added some extra space to my lightmaps and it work like a charm.

http://home.hccnet.nl/pj.holverda/lightmap_versie_5.jpg

One question still, is it really necessary to add 1 pixel to each lightmap bound( in combination with mip-mapping ), since it's wasted space?

cheers

Paul
Cosmic Keys to my Creations & Times

Topic Locked

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

Sign in to reply to this topic.