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.
[ATTACH=CONFIG]1514[/ATTACH]
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
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.
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.