PDA

View Full Version : Glow with OpenGL



WILL
28-02-2007, 07:06 PM
Hey guys, I'm trying to add a nice nifty ambient effect to the lava in my game, so I was thinking of using the Tron glow effect on all the lava tiles.

I've done some scouring on the net via Google and found this lovely article on the matter:

Real-Time "TRON 2.0" Glow For Low-Spec Hardware (http://collective.valve-erc.com/index.php?doc=1087646312-07733400)

and of course it's older cousin: Real-Time "TRON 2.0" Glow in Half-Life (http://collective.valve-erc.com/index.php?doc=1081854378-22165000)

but... it's very Half-Life Engine specific. And I fear that it doesn't really cover the theory very well at all. So I'd like to get the basic concept of it before I delve into the code, just to make sure if I can make any use of this or not.

So who knows more about this? :)

EDIT:

Ah ha! I knew it... found the article (I remember there being this one somewhere just couldn't remember where.) Real-Time Glow (http://www.gamasutra.com/features/20040526/james_pfv.htm) on Gamasutra.

savage
28-02-2007, 09:59 PM
You might want to download this - http://huru.imukuppi.org/opengl/Advanced_Graphics_Programming_Techniques_Using_Ope nGL.pdf and put it in a safe place.

WILL
01-03-2007, 12:44 AM
Ah... very nice. Thanks Dom! ;)

Sascha Willems
01-03-2007, 03:21 PM
Since I already implemented a glow in one of my older games I'll give you a brief summary of how to do it without needing advanced stuff like shaders etc. :

You need separate meshes or textures for the glow renderpass. E.g. for a building where you want to have only the windows glow that special glow model would be totally black except for the windows that would be colored in the respective glow color. Either do that by setting the material or by applying a special glow texture.

Clear the screen black and render your scene as usual but with only the glow meshes / textures. You should disable all unnecessary rendering states like lighting, shaders, etc. but leave depth test enabled. You now have the glowing part of your scene stored in your backbuffer. Dont' swap the buffers yet!

Now copy the backbuffer into a texture. The size of that texture should be much smaller than the actual size of your game's window to make the glow blurry. Copying into a texture is most easily done with glCopyTexSubImage, but you can also use a pixel buffer or the newly introduced FBOs.

Clear all buffers you're using (color, depth, stencil, etc.) and render your normal game scene.

Switch into orthographic projection via glOrtho and clear the depth buffer.

Enable blending (additive should be best, but maybe try out).

Very simple blur :
Draw a quad with your glow texture applied on top of the whole screen. Due to the fact that your glow texture is much smaller than the actual screen size the linear filtering (don't forget to enable this) will smooth out the texture.

Radial blur :
As above, but draw the quad ontop of your game screen multiple times (maybe 16 times or even more often) and eachtime offset it using sinus and cosinus so the glow get's radial. This looks better but also hurts performance.

Nitrogen
01-03-2007, 07:49 PM
Another nice trick that I've learnt:

- Draw onto your blur texture.

- Instead of drawing the blur texture to the screen, you draw it to another texture. You draw it about 2-4 times but with a VERTICAL offset each time.

- Draw the newly resulting texture onto your screen 2-4 times with a HORIZONTAL offset each time.

This will give you the same effect, if not better than drawing the original 16 or more times.