1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-05 00:53:36 +08:00

RotateUV, SwirlUV and TwirlUV algorithms updated

This commit is contained in:
Digvijaysinh Gohil 2024-05-30 00:06:38 +05:30
parent 9f8087e91d
commit ce44d78559
3 changed files with 19 additions and 11 deletions

View File

@ -3,8 +3,11 @@ vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees){
if(use_degrees){
_angle = rotation * (3.1415926/180.0);
}
mat2 _rotation = mat2(
vec2(cos(_angle), -sin(_angle)),
vec2(sin(_angle), cos(_angle))
);
vec2 _delta = uv - center;
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
return vec2(_x + center.x, _y + center.y);
_delta = _rotation * _delta;
return _delta + center;
}

View File

@ -1,8 +1,10 @@
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 _delta = uv - center;
float _inverse_length = 1.0 - length(_delta);
float _angle = strength * _inverse_length;
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
return vec2(_x + center.x + offset.x, _y + center.y + offset.y);
float _angle = strength * pow(1. - length(_delta), 3);
mat2 _rotation = mat2(
vec2(cos(_angle), -sin(_angle)),
vec2(sin(_angle), cos(_angle))
);
_delta = _rotation * _delta;
return _delta + center;
}

View File

@ -1,7 +1,10 @@
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 _delta = uv - center;
float _angle = strength * length(_delta);
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
return vec2(_x + center.x + offset.x, _y + center.y + offset.y);
mat2 _rotation = mat2(
vec2(cos(_angle), -sin(_angle)),
vec2(sin(_angle), cos(_angle))
);
_delta = _rotation * _delta;
return _delta + center;
}