Jump to content
  • Advertisement
Sign in to follow this  
Biax

OpenGL Bizzare Lightmap Problem

This topic is 3725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I've been working on a simple 3D engine the past few weeks using OpenGL and have started working on calculating dynamic lightmaps. I followed the code outlined in this tutorial. I've modified it to use multiple light sources, account for surface normals (called lambertian I think?). It also uses triangular faces for surfaces rather than quads. Everything in the calculation seems to be working fine, from what I can tell, but the lightmaps aren't being mapped correctly to their faces, they instead come out like in this image. That is using the following coordinates: p_fLightMapCoords[0].x = 0.f; p_fLightMapCoords[0].y = 0.f; p_fLightMapCoords[1].x = 0.f; p_fLightMapCoords[1].y = 1.f; p_fLightMapCoords[2].x = 1.f; p_fLightMapCoords[2].y = 0.f; It appears that each lightmap needs to be rotated within the triangles' vertices. But if I change the mapping coordinates to this: p_fLightMapCoords[2].x = 0.f; p_fLightMapCoords[2].y = 0.f; p_fLightMapCoords[0].x = 0.f; p_fLightMapCoords[0].y = 1.f; p_fLightMapCoords[1].x = 1.f; p_fLightMapCoords[1].y = 0.f; I get these results. It's as if it is now using a different section of the lightmap, which is absolute insane since I didn't actually change any of the coordinates, I just changed the order of them. I've tried building the data in the lightmap bitmap at a 90 degree angle, flipped horizontally, vertically and both, etc, but nothing gives the correct result. I find it extremely puzzling that the mapping info causes such a total change to the lightmap, when in theory it should be completely independent of it. Does anyone have any ideas? [Edited by - Biax on July 7, 2008 9:58:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
I seem to have fixed the problem by systematically trying all combinations of coordinates and flipping the image on the x axis. I still have no idea why I needed to do this, but as long as it works I won't complain.

There are a few little artifacts present in the map, however. These include things like visible seams, and lines of light along edges where there shouldn't be any. Take a look.

It's like the translation of positions to lightmap coordinates suffers a slight round off error or something that causes the lightmap to be `shifted' slightly away from ideal. That's what it seems like to me at this point, anyway...

EDIT: Fixed this too, it's due to bi-linear filtering being turned on.

[Edited by - Biax on July 7, 2008 2:34:58 PM]

Share this post


Link to post
Share on other sites
Can you post screenshots of the fixed seams ? From the last screenshot it doesn`t like it`s just a bilinear filter issue, since that would mean just offset of half texel. The lightmap looks like it`s got much higher resolution.

Although if the resolution is the same as on the bottom quad, it might be the case. It just seems the left and right lightmaps have higher res than the bottom one.

Share this post


Link to post
Share on other sites
Yeah, It would be helpful if you posted pics of the lightmap texture itself, not pics of the room.

Share this post


Link to post
Share on other sites
actually, you need both since it might be a combination of filtering, wrong coords and possibly less/wrong texels

Share this post


Link to post
Share on other sites
This looks very much like you have one lightmap per triangle, and that those walls made up of two triangles don't have their lightmaps aligned properly. It's easiest to fix this with good precision by using only one lightmap per plane, and stretch it over the area covering every triangle sharing that plane. Then let each triangle in the plane use the same lightmap texture, and give them the appropriate lightmap coordinates within the lightmap.
If you have large maps with small triangles sharing the same plane, and large distances between them, you might have to fix this by using more than one lightmap per plane. Perhaps you can use one lightmap for all triangles sharing a plane and touching each other or similar.
In this simple case it would be enough to have just one lightmap per wall, not one per triangle.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!