2D normal map rotation


I’m new with GLSL shader.
For a small project with the SFML (who is based on OpenGL), i try to add a normal map on my textures to make a better light effect.
For that, i have wrote a shader, who work fine, but i still have a problem.

When the render of a sprite is not transformed, i have the result that i wanted, but if i add a rotation on my sprite the normal don’t rotate.
For simple shapes, i can use the transform of the object to change the normal.

But this way don’t work on “complex” objects, like a tilemap.
Here i have the same border on the top and left of the block, but rotated. You can see that the light look to be facing the 2 tiles but normaly it’s just up.
Is there a way to know the transformation of an UV in the fragment shader ?
If not, is there a workaround ?

Here you can found the fragment shader that i use for the tilemap

Thanks for your help

You can apply the dFdx() and dFdy() pseudo-functions to the texture coordinates. That gives you the transformation from screen coordinates to texture coordinates. You can use that to obtain a transformation to or from other coordinate systems.

If you’re using OpenGL ES, you need the OES_standard_derivatives extension.

If i understand well, theses functions allow you to get the others pixel of the fragment, and with that i can found the transform of the current ?

But, what if the current pixel is on the border of a tile, and the others on the fragment is on a other tile ?

The implementation will calculate values for the surrounding fragments if these are necessary to calculate differences. The values will be based upon the vertex shader outputs for the current primitive.

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