How to get per-pixel surface slope directions

Hello, I need to implement a geometry aware gaussian blur filter that blurs along the surfaces (like walls). To do that I need to get the per-pixel vectors that represent the surfaces variation/gradient in screen-space like in this image:

Unfortunately I don’t know how to get these vectors. I supose it can be done by using the dFdx and dFdy GLSL functions to find the per-pixel variation of something but I’m really confused about the details. I’d really appreciate any help.

Thanks in advance.

—João Cabeleira

You need a camera-space vector variation. The vector could be obtained from the depth texture (like in DOF, SSAO & deferred shaders).
Once you have it, the gradients are dFdx & dFdy as you mentioned.
You drawn only one arrow per point, but there are 2 gradient vectors that represent the surface, not 1. This probably means that you don’t understand your needs clearly.

Thanks for your response, I’ll give it a try and should be easy since I already have a depth buffer for deferred rendering.
I just didn’t understand how to get a vector from the depth buffer, are you saying that I should get the pixel depth and then get the dFdx and dFdy values of this depth?

And yes, I’m aware that each surface has 2 vectors that represent it. In fact, I need both of them to perform a separate blur along these two directions. I only mentioned one of the vectors for demonstrating the problem, but I guess I should have explained that.