🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Glow/bloom effect

Started by
30 comments, last by kaysik 19 years, 4 months ago
I'm not sure what it needs in terms of resources, but AFAIK the best and most realistic way of doing this is to use HDR and render the entire screen to a texture, blur everything a lot and render the blurred texture as a quad over the screen (with low alpha).

Con :
- needs HDR, which can be expensive and not every board supports it
pro :
+ uses HDR that can be used for other things as well (future ready)
+ very simple - blur and blend. You can even keep the original texture as the "glow-free" image.
+ the most realistic
+ no need to mark glowing parts

Note: the DX SDK HDR example was so cpu/gpu intensive that the temp alarm went off when I tried it. It was hot in the room, but still... I'm not sure if it could be used in a game.
Advertisement
you'd need two buffers for this though right? How do you get openGL to render to somewhere else than the back buffer but still use the back buffer's z values?

1) Render normal scene
2) Render to some other buffer useing z from step 1
3) Blue other buffer
4) Blend blured buffer over normal scene

Anyone got a little bit of code (or even just some function names that I can look up) to help with rending to random buffers useing the current back z-buffer? The rest should be easy once thats done though so I'm hoping to get this working soon.
Quote: Original post by frostburn
I'm not sure what it needs in terms of resources, but AFAIK the best and most realistic way of doing this is to use HDR
Yes - the techniques we've been talking about in this thread are sometimes called "fake HDR."

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Quote: Original post by superpig
Quote: Original post by MikeyO
What about rendering the entire scene to a texture, then only blurring the parts of the image that are 'bright' enough? Is that possible?
Yes - instead of rendering 'glow sources' into a buffer, you render the entire scene (usually the backbuffer as a textured quad), performing a luminance extraction. It requires a pixel shader, but it's easy to do. A very basic luminance extraction would be to dot3 each pixel against (0.3, 0.3, 0.3).


Since it will not cost you more time I suggest you to use (0.3, 0.58, 0.12) as they are the coefficient needed to get the Y luminosity in a RGB pixel (Paul Bourke refers it as the "pure B&W translation for RGB"). If you can use more time in the pixel shader then it may be interesting to compute the real luminance (pseudocode, do not compute the hue and saturation; BTW he may be hue for additional glow effects since it is the real tint of the glow):
mymin = min(r,g,b);mymax = max(r,g,b);luminance = (mymin + mymax) / 2;


Regards,
Someone added a glow effect to the Half-Life engine using Shaders.

To get the bright spots for blurring he multiplied a texture-quad of the framebuffer with itself. Bright spots get brighter, dark spots get even darker. Very cheap effect and it does the job as you can see in the screenshots.

Check it out here:

http://collective.valve-erc.com/index.php?go=tron1

I implemented the effect and it works great.

cheers
Quote: Original post by Emmanuel Deloget
Since it will not cost you more time I suggest you to use (0.3, 0.58, 0.12) as they are the coefficient needed to get the Y luminosity in a RGB pixel (Paul Bourke refers it as the "pure B&W translation for RGB").
Yeah - though in truth it's slightly different for different display devices (i.e. computer monitor vs. PAL tv vs. NTSC tv). Your constants are better than a simple average though.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I still can't get this to work without rendering the geometry.
Can you guys check if this pseudocode is correct ?


1.Render scene normally
2.Enable p-buffer, resize viewport to (0,0,128,128);
3.glDepthFunc(GL_GEQUAL);
4.render glow materials
5.copy materials to texture
6.glDepthFunc(GL_LESS);
7.Disable p-buffer, resize vieport to original size
8.blur texture in fragment shader
9.render quad over the screen with the texture


This process is not working at all, it seems there is z-fighing over the glow surfaces, and it's not occluded by the geometry.

thanks
bump bump
donno if somei=one mentioned this
http://opengl.nutty.org/effects/index.html
Why are you setting the z function backwards to GEQUAL? That will not play nice.

Do you mean LEQUAL?

This topic is closed to new replies.

Advertisement