Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Looking for some beginner direction on rendering light sources

This topic is 1465 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 all!


I have a graphics engine which is based on a combination of techniques from the tutorails at: http://ogldev.atspace.co.uk/


My engine features deferred rendering (Non HDR) based on their Deferred Rendering tutorial series (with some tweaks to combine various other techniques). I have a G-buffer with Position, Diffuse and Normal textures. Rendering is sent to an intermediate texture which is blit to the screen at the end of each frame. I am using the stencil buffer to mark pixels inside of light volumes, where lighting calculations are performed. 


Up to this point my lights cast both light and shadow on other objects but there is nothing to display the appearance of the glowing light itself. I have dealt with a fair number of techniques in my experience with OpenGL but never anything that involves drawing a glowing light source.  There are a few things I'd like to achieve. Namely:


1. The light intensity for pixels close to the light source uses the inverse square rule (or something that roughly approximates it). That is: intensity = k / distance^2 for some constant k.

2.  If a light source is obscured by another object, the glow that surrounds the object disappears, even if the "glow radius" would reach outside the occluder.

3. If a pixel is within the "glow radius" of more than one light, the effect is additive.

4. I would like it to be reasonable to perform with a very high number of lights (i.e. 1,000)


These are just preferences (except for 4),  I just want something that looks convincing. The best idea I have right now is:


1. Add an emmisive texture to my G-Buffer. 

2. Render my light sources and fill the emissive texture (the light source model will have its own emissive texture which will mark which pixels are emitting light, and the values in this texture will be copied to the emissive texture in the g-buffer)

3. Make a pass over each light source (making sure to process all pixels within range of its "glow radius"). For each pixel, sample the texels in the emissive texture corresponding to the current pixel, as well as those for neighboring pixels with a small radius. Average the colors in these texels, and use that to add to the intensity of the current pixel. - I know this will achieve some kind of blur but I don't know if it will achieve an inverse square type of drop off in intensity that should make it look convincing.


I am very new to this type of shading so I could use some basic pointers or tutorial recommendations, as well as some basic terminology. I am not sure if "bloom" or "glow" is the term to use for what I'm trying to achieve.


Advice and guidance would be appreciated!


-Mike V.

Edited by mikev

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!