Sign in to follow this  
jcabeleira

Need to find pixel gradient for blur along surface

Recommended Posts

Hello, guys. I need some help for doing a surface dependent blur. What I'm trying to do is for each pixel find these vectors in screen-space to get a blur direction: I've tried doing this in a shader that calculates the screen space position for each pixel and then uses the screen space derivatives (using the dFdx and dFdy instructions) to find the vectors but unfortunately it doesn't work. Could some one explain how could I do this? Or perhaps this whole ideia is wrong and I should use a different method to apply a surface dependent blur (like a blur disk reoriented on the surface?). I'd like to hear your sugestions on how to do this. Thanks in advance.

Share this post


Link to post
Share on other sites
Try giving this a shot:

In the screen vertex shader, take the bottom left UV coordinates and map them to (-1, -1) and the top right to (1, 1) and send these coordinates to the pixel shader.

In the screen pixel shader, take the coordinates and subtract them from (0, 0). Hopefully that works!

Share this post


Link to post
Share on other sites
Thanks for your reply but that doesn't work. Your sugestion would only get a vector from the center of the screen to each pixel, which would work for the walls on the scene of the picture but isn't applicable in a general situation.

Share this post


Link to post
Share on other sites
No, it's not a zoom filter that I need.
What I need is a blur filter that adjusts its size and orientation kernel according to the surface that it is blurring. If a surface is angled obliquely away from the camera then the blur kiernel must get thinner in the correct direction, the kernel overall size should also change according to the distance of the pixel to the camera.

Thanks, anyway.

Share this post


Link to post
Share on other sites
You could use a normal map (sample at least 1 point from it) or a depth map (sample more points - at least 4 - from it and build the right vector). Maybe a simple normal map could help you but if it doesnt, you can use the screen depth map and generate the direction from the depth map. ;)

Share this post


Link to post
Share on other sites

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

Sign in to follow this