mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
RotateUV, SwirlUV and TwirlUV algorithms updated
This commit is contained in:
parent
9f8087e91d
commit
ce44d78559
@ -3,8 +3,11 @@ vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees){
|
|||||||
if(use_degrees){
|
if(use_degrees){
|
||||||
_angle = rotation * (3.1415926/180.0);
|
_angle = rotation * (3.1415926/180.0);
|
||||||
}
|
}
|
||||||
|
mat2 _rotation = mat2(
|
||||||
|
vec2(cos(_angle), -sin(_angle)),
|
||||||
|
vec2(sin(_angle), cos(_angle))
|
||||||
|
);
|
||||||
vec2 _delta = uv - center;
|
vec2 _delta = uv - center;
|
||||||
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
|
_delta = _rotation * _delta;
|
||||||
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
|
return _delta + center;
|
||||||
return vec2(_x + center.x, _y + center.y);
|
|
||||||
}
|
}
|
@ -1,8 +1,10 @@
|
|||||||
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||||
vec2 _delta = uv - center;
|
vec2 _delta = uv - center;
|
||||||
float _inverse_length = 1.0 - length(_delta);
|
float _angle = strength * pow(1. - length(_delta), 3);
|
||||||
float _angle = strength * _inverse_length;
|
mat2 _rotation = mat2(
|
||||||
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
|
vec2(cos(_angle), -sin(_angle)),
|
||||||
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
|
vec2(sin(_angle), cos(_angle))
|
||||||
return vec2(_x + center.x + offset.x, _y + center.y + offset.y);
|
);
|
||||||
|
_delta = _rotation * _delta;
|
||||||
|
return _delta + center;
|
||||||
}
|
}
|
@ -1,7 +1,10 @@
|
|||||||
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
|
||||||
vec2 _delta = uv - center;
|
vec2 _delta = uv - center;
|
||||||
float _angle = strength * length(_delta);
|
float _angle = strength * length(_delta);
|
||||||
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
|
mat2 _rotation = mat2(
|
||||||
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
|
vec2(cos(_angle), -sin(_angle)),
|
||||||
return vec2(_x + center.x + offset.x, _y + center.y + offset.y);
|
vec2(sin(_angle), cos(_angle))
|
||||||
|
);
|
||||||
|
_delta = _rotation * _delta;
|
||||||
|
return _delta + center;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user