Jump to content
  • Advertisement
Sign in to follow this  
MrJNewt

Creating a 2D light map with a FBO?

This topic is 3666 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'm working on a 2D side-scrolling platformer and would like some advice on my implementation of dynamic lighting/shadowing. I'm taking the old-school approach of drawing everything as a quad with the sprite textures stretched across it. Each sprite also has an array of vectors that define a convex hull that defines how the object will interact with both other objects and light. I also have the technique for generating shadow geometry (thanks to OrangyTang's soft shadow method described in the articles section of this site). My question is: how should I handle the rendering of the light & shadow map and then blend it with my normal rendering pass? Essentially, I'd like the color (and alpha) values in the lightmap to modulate the rendered sprites. My current thought is to render the lightmap to a FBO, render my scene to the backbuffer, then blend the lightmap in. Should I switch it around? Or can I skip the FBO and use some of sort blending that will work out as described below? The blending rule needs to work out to something like this: If the sprite pixel's alpha is 0, the sprite pixel's final alpha is 0 (transparent parts of the quad are not drawn); Otherwise the end alpha should be lightmap's alpha (or some combination of lightmap and sprite). I would also really like to blend colors, but this is somewhat less important. Any suggestions from someone more seasoned than I? Edit: Clarified blend function objective. [Edited by - MrJNewt on November 26, 2008 3:22:09 PM]

Share this post


Link to post
Share on other sites
Advertisement
After thinking some more on the problem, I think I have a solution if someone can supply me with the proper glBlendFunc and glBlendEquation values.
I'll render my lightmap to the backbuffer. Alpha of 1 is fully illuminated, 0 is completely dark, with intermediate values. Then I'll set the blending up so that all incoming pixels have their RBGA values _multiplied_ by the values already on the backbuffer. If either the lightmap or sprite has a pixel with an alpha of 0, the final pixel will have an alpha of 0.

If anyone knows the appropriate settings to perform this multiplying effect, I'd appreciate it. While this should work for my sprites (the pixels of which should have an alpha of either 0 or 1), will this seriously screw up colors?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!