Jump to content
  • Advertisement
Sign in to follow this  
Haptic

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.

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

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 this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
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.

Share this post


Link to post
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 this post


Link to post
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..

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

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!