[SOLVED] 2D 'Light Mapping'

Started by
2 comments, last by Haptic 15 years, 3 months ago
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]
- Haptic
Advertisement
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.
Photobucket

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.
- Haptic
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
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..

Thankyou Kada2k6 and osmanb for your help. I greatly appreciate your time.
- Haptic

This topic is closed to new replies.

Advertisement