Need to find pixel gradient for blur along surface

Started by
3 comments, last by snake5 14 years, 1 month ago
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.
Advertisement
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!
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.
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.
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. ;)

This topic is closed to new replies.

Advertisement