How to pass vertex positions to fragment shader


I’m new to coding glsl for graphics, I hope you’ll forgive my naive question.

I’m in a slightly unusual circumstance in that my shader library is interfacing with another 3rd party library, (long story) the upshot of which is I don’t have access to certain opengl state variables. I can set up a vertex and fragment shader, and call this third party routine which sends the geometry. I.e I cannot specify per-vertex values unless I’m inside a vertex shader.

My aim is to be able to get a tangent vector so that I can perform bump mapping. What I am trying to do at the moment is pass the vertex position to the fragment shader (in a texture coordinate), and then use dFdx & dFdy to find me a tangent.

However, I don’t really understand the transformations I need to get what I want. At the moment my fragment shader normalises calculates dFdx(gl_TexCoord[0]), i.e dFdx(gl_Vertex), and normalises the result.

I get a very nice graduation over x (which basically looks like flat shading), but the colours change as I rotate the camera, which I didn’t expect.
I suspect some of this is because the dFdx and dFdy functions are operating in fragment space. So perhaps my question is how can I get an object space derivative through to my fragment shader?

I welcome your suggestions…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.