It works as I want it to, but there is 1 problem. and its when I change the Transform.scale.
The script is meant to be used as a refraction, so it also scales with the sprite size and the screen size.
Here is what it looks like in the game.
This sprites have the scale of 3, 1 and 0.5
You really should be using Unity’s built in functions for manipulating normals, as shown in the example page I linked to. Just naively rotating two components of the normal map using the object to world matrix will mean having to extract the scale out of the matrix which is very costly.
If you’re looking to use this for refraction what you really want is the screen space normal, not world space (though for 2d stuff they’re often the same for directional vectors).
Try this:
half3 objectNormal = UnpackNormal(tex2d(_Tex, uv)); // assumes you’re using a texture imported as a normal map
half3 viewNormal = normalize(mul(UNITY_MATRIX_IT_MV, objectNormal)); // transform normal from object space to view space
Then use the .xy from viewNormal. Technically this isn’t really correct either, but it’ll kind of work with sprites since the normal map is kind of in object space. If the sprite / mesh gets batched the above will stop working properly.
im having this same problem rotating a normal map using shader graph, i’ve tried unpack normal node and rotate about axis Z, but the result is not looking correct (in any of the axis), maybe im missing something? i made it work using a triplanar node like the screen attached, but i cannot make it work for 2D texture.