Jump to content
  • Advertisement
Sign in to follow this  

Variable-radius Gaussian blur in GLSL

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

I wanted to do a simple depth-of-field postprocessing shader, that blurred the image by a value that was related to the depth buffer.  That is, the closer an object is, the more it's blurred.  Most of the Gaussian blur shaders I found were fixed-radius though, so they would blur the entire image by the same amount.
I looked at depth-of-field shaders, but they're a lot more complex than what I'd need, since they typically contain the functionality to blur distant objects more than close objects.  (In layman's terms, my shader should be farsighted, not nearsighted)
I was able to get a decent depth map, where white is close and black is far away, by using the following GLSL vertex shader:
varying float depth;
void main(void)
   gl_Position = ftransform();
   depth = 1.0 / gl_Position.z;
I can tweak the "1.0" value to adjust the falloff.  Now I want to use that depth value to determine the blur radius, or something equivalent.
I found an example of what seems to be what I'd need here:
But I don't really understand it well enough yet to know whether I'm on the right track.  This seems to be a pretty basic shader that I need, so either I'm thinking too hard or not thinking hard enough.  Anyone care to enlighten me?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!