Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Shader fun!

Sign in to follow this  


So, I gave up waiting for FBO, figuring I could try what I wanted to do just by copying from the framebuffer to a texture.

My goal : Single pass Radial blur.
Why single pass? Well, I wanted to combine a radial blur with a filter on the texture as well, but 20 pass with 9 texture reads per fragment per pass seems to make make gfx card cry somewhat [grin]

So, after looking about for the basic theory I found a method which involved taking the distance from the current pixel to the center of the scene, scaling it and using that to read into the scene and then blend it with the pixel at the current location.

Now, this is designed to work from the middle out, accumlating the effect as you move out, however as I cant think of a sane way todo that I decide to accumulate over a couple of frames and use the last frame as input into the next.

So first of all we create a blank texture which will be our store for the last frame, we then draw the scene and copy it to a texture (a render to texture would be pefect here but I'm not mucking about with pbuffers any more).
A screen aligned quad is then drawn with a fragment shader, with the current frame and the last frame textures being used as inputs.

The vertex shader is a simple transform and pass the texture coords to the fragment shader setup, so nowt special there, its the framgment shader where the magic happens.

First thing we do is take a vector from the current fragment to the center of the texture. This is easy as the texture coods are in a [0=>1] domain across the texture, so we know that our current texture coords are our current position, with (0.5,0.5) being the center of the texture.
This value is then scaled (which has a drametic effect on the final output) and used to sample the last frame by subtracting it from the center position.
The current frame is sampled as normal.
The absolute distance between the current position and the middle is worked out and forced into a [0=>1] domain.
The alpha value of the color from the last frame is then scaled and the color is added to the value from the current frame and written out.

Now, currently it satutates far too quickly to be much use as a radial blur, but I'm gonna work on that, however with a scale of 0.5 it gives a cool effect :

Back to playing with it I go, I might try and inverse exp function to adjust the alpha over distance, see if that helps the satutation problem any

edit: So I played some more with the alpha function, didnt fix what I wanted it too, but got some cool looking effects out of it [grin]

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!