Jump to content
  • Advertisement
Sign in to follow this  
spek

Contrast Blur

This topic is 4846 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

Hi, How to make blur/glow in a game? In this case, I'd like the bright parts to have some sort of glow, in case they are in front of a dark background (or vice-versa). For example, a bright white metal object standing on dark grass should have some sort of white glow around it. Just a very small edge though (1,2, maybe 3 pixels). I could make a shader that takes samples out of a 'snapshot' for every pixel and calculates the average color. But a glow of 1 width would already require 8 samples, 2 width 24 samples etc. I think that would be way to slow. It's also possible to render the scene a second time with a little larger scaling/offset and blending activated. But then everything would blur, I'd only like to high-contrast parts to blur. Anyone an idea for a fast implementation? Greetings, Rick

Share this post


Link to post
Share on other sites
Advertisement
hi, well you could do it this way:

1. render the scene to a texture
2. make a fragment shader that contrasts the image something like:

float4 main(float2 uv, uniform sampler2D tex0 : TEXUNIT0)
{
float4 col = tex2D(tex0, uv);
return pow(col,4);
}





And render a quad with the scene texture and apply the shader

3. Copy the screen to another texture. This will have the bright spots bright and everything else darken.
4. Take the darken texture and blur it (there several ways to do this), you could even stretch it.
5. Blend the blurred texture with the scene texture.

You'll get something like this or this .

Of course you can tweak this to suit your needs. Hope this helps.

EDIT: Or you could try doing some HDR lighting but that's another story and will require floating point buffers (GF6+) and a little more computation and work for implementation.

Share this post


Link to post
Share on other sites
Thanks! This didn't came up in my mind. Stretching it would be a cheap way to do it instead of taking lots of samples. I also took a look at HDR, but unfortunately, my card is too old again :|.

Thanks,
Rick

Share this post


Link to post
Share on other sites
Regular blur is 'seperable', basically meaning you can do a straight horizontal blur, then a straight vertical blur and get the equivilent of the box filter over the same area. So the blur of width 1 you gave an example of would only require 4 samples. My (pretty unoptimised) blur runs 32 pixels wide @ 800x600 and is plenty fast enough even on my lousy GF4.

Rendering smaller and scaling up is possible, but much worse quality. Somewhat better is rendering at half resolution and doing a smaller blur. However you tend to get 'missed' pixels if you have lots of high frequency geometry (like chain link fences) and you can get an odd shimmering effect as objects move. Good for slower computers as an option though.

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!