OpenGL [SOLVED] 2D 'Light Mapping'

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

Recommended Posts

Hey all, I am working on a 2D tile based game. I am interested in using lightmaps instead of the inbuilt OpenGL Lighting for both versatility and efficiency. An example application is creating a circle of light around a campfire. I have created some lightmaps in Photoshop (white, with an alpha channel) and am blending this onto my terrain. This doesn't work how I thought it would - instead of 'brightening' things, it makes them appear pale and dull. It is making things whiter as opposed to making them a brighter version of the present colour (which is sort of logical, given hindsight). I've messed around with the glBlendFunc parameters but cannot find a suitable combination. The best that I have come across is:
     glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
But it is still too pale. So my question: Can I adjust colours with a lightmap, so that things get brighter and not just paler? Cheers, [Edited by - Haptic on January 17, 2009 8:46:41 PM]

Share on other sites
Hidden
Try with the settings GL_SRC_ALPHA and GL_ONE instead for glBlendFunc()

Also, play around with glColor4f(). Especially the last parameter - which is opacity - should be experimented with.

Good luck!

Kada2k6: Thankyou for the prompt reply, it's much appreciated. I have played around with both the alpha levels and the settings you offered but they still do not work as I would like. It is still quite obviously pale.

I have created a picture to demonstrate what I mean.

I would like the colour in the ellipse to be as cose as possible to the 'Daylight' colour. As you can see, currently it is pale and almost blurred. This is also the best result I could get.

Share on other sites
It's going to be hard to do. Normal light-mapping actually makes things darker, not lighter -- by just multiplying the color of lightmap with the diffuse color of the texture. In particular, if your underlying tiles are already heavily saturated, there is basically no way to make them brighter without washing out the color.

If you want to go down this route, then you could build things in a similar way to how normal lightmapping works. In that case, all of your normal (unlit) textures (tiles) need to be created VERY bright. Essentially, they should be authored as if they are at "maximum" brightness. Then, all of your lightmaps can contain color information about the lights themselves. You can even paint in color to your lights (like your campfire, which could be orange/yellow). Blend by multiplying the two textures together:

glBlendFunc(GL_ZERO, GL_SRC_COLOR); // I think? My GL / fixed function is rusty

Share on other sites
Solved it!

osmanb: Your use of GL_SRC_COLOR reminded me that I hadn't looked as far into COLOR as I had ALPHA for some reason, so thanks =P.

 	glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);

Pretty obvious in the end..

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• Forum Statistics

• Total Topics
632631
• Total Posts
3007538
• Who's Online (See full list)

There are no registered users currently online

×