Lightmap rendering

Started by
7 comments, last by Flous 22 years, 9 months ago
Hi, I''ve just implemented a lightmap calulator and rendering them, in my engine. The problem is, that when I use a filter other than GL_NEAREST (which looks like crap, as we all know), I get artefacts at the edges of my polygons. What I think is happening, is that the bi-linear filter is wrapping the egdes around for its filturing calculations. So if I have a poly that goes from bright to dark, and I render it with GL_LINEAR or GL_LINEAR_MIPMAP_LINEAR, on the dark side, on the edge, there is a light line, on the light side, there is a dark line. Although this is only a small error, and sometimes not noticable, I would like to know if there is a way to render them without introducing stupid errors like that. Thanks in advance, Danny Lousberg
Advertisement
I think the way to rectify this is to leave a one pixel border around each lightmap. I think this is how most engines get round the problem.
When you are setting up each of your lightmaps, call this:

glTexParamaterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParamaterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

This makes OpenGL not repeat the textures, which means you don''t get the bilinear filtering artefacts around the edges. Ths is OK for lightmaps since you don''t want them to repeat

Has that fixed the problem ??

FatalXC
FatalXC:

Yeah, I've tried that already, and it gives me some black lines around every poly (could be used for hidden line removal with texturmaps I think ).
I downloaded your engine btw, and it looks to me as if you have the same problem (unless these lines are intentional, in which case I appologize )
good work by the way.

BLZBub:

That could work, but I think that's to much of a hack, don't you?
And I'm not quite sure, but I think the problem is created after the texture (lightmap) is uploaded to the card, where I can't touch it.
I'll try and find another way, but perhaps when I'm desperate, I'll give that a shot. thnx anyway

Edited by - Flous on July 22, 2001 8:54:50 AM

Edited by - Flous on July 22, 2001 1:48:42 PM
Ok this is the wierdest thing:

I also use a lightmap however I don''t get the artifect you are talking about. On the other hand I have this problem with my sky. Unless I use GL_NEAREST for the texture, I can see the edges of the sky box.

I don''t know how you are doing your lightmap, but all I do is use glColor4f(shade, shade, shade, 1) where the shade is the lightmap value at the given vertex.

any help on the edge thing would be apreciated.
Owkay, I have found the source of my problem...

It's GL_TEXTURE_BORDER_COLOR that's been giving me headaches...
It seems that when you use GL_CLAMP and any filter other than GL_NEAREST, it takes the border color (default = (0,0,0,0)) as the outer most value for filtering, that is, the driver uses this border when the u and v values go near 0.0f and 1.0f

There is an extension, called GL_EXT_TEXTURE_EDGE_CLAMP which doesn't take the border color into account when clamping the textures, and fixes this problem. Unfortunatly, only Matrox, NVidia and ATI seem to support this extension. (There may be others, but Voodoo²'s for example, don't support it).

Now, what I do then, is rescale my lightmap u,v cöords to like 97.5% of their original value, so these values never reach 0.0 or 1.0, and the border color is never involved in any filtering. I know this is a rather cheap hack, but it's only for legacy hardware, so I'm willing to make that sacrifice.

If anybody knows of a different way to do this, please tell me.

Hope this helps some of you.

Edited by - Flous on July 22, 2001 1:47:42 PM
Flous,

Are each of your lightmaps a sperate texture or are they combind into a few large textures ?? I do mine with one lightmap texture per polygon atm so maybe that is why this works for me.

But the fact that my engine has the same problem probably means that the above is not the problem. I don''t get black lines on my machine, and I don''t think any of the other people who downloaded it did, well they didn''t say so, most people thought the lighting was really good, and black lines around the polygons looks ugly so yeah ... maybe it''s something wierd with your card or drivers. What video card do you have ??

FatalXC
I think you should shift & scale your lightmap coords a little. For ex. if your lightmap size is 16x16 try :

1. Scale your lightmaps coord by 15.0f/16.0f
2. Shift both U and V by -1.0f/32.0f

Hope this helps.

Edited by - dexio on July 22, 2001 9:17:42 PM
Dexio: That''s what I do now, as I said earlier... I rescale them from [0.0f - 1.0f] to [0.025 - 0.975], and this indeed helps.

FatalXC: I''ll send you a screenshot from the lines I see in your engine...
Check it out, and let me know, ok?
I have a Radeon DDR

Btw, I''ve done some research on this, and it seems that Opengl is supposed to take the border color into account when filtering near the edges. Although I only tested the GL_CLAMP implementation on my system, other drivers are supposed to do the same thing. BUT, it seems to be a very tricky thing to do in hardware, and since it''s not very usefull in games, some card-manufacturers may have decided not to implement it, and simply ignore it.

This topic is closed to new replies.

Advertisement