From ce44d7855947323239e5426e821a62e99ba20af8 Mon Sep 17 00:00:00 2001 From: Digvijaysinh Gohil Date: Thu, 30 May 2024 00:06:38 +0530 Subject: [PATCH] RotateUV, SwirlUV and TwirlUV algorithms updated --- addons/ShaderLib/UV/RotateUV.gdshaderinc | 9 ++++++--- addons/ShaderLib/UV/SwirlUV.gdshaderinc | 12 +++++++----- addons/ShaderLib/UV/TwirlUV.gdshaderinc | 9 ++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/addons/ShaderLib/UV/RotateUV.gdshaderinc b/addons/ShaderLib/UV/RotateUV.gdshaderinc index 519acf3..3569d18 100644 --- a/addons/ShaderLib/UV/RotateUV.gdshaderinc +++ b/addons/ShaderLib/UV/RotateUV.gdshaderinc @@ -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; } \ No newline at end of file diff --git a/addons/ShaderLib/UV/SwirlUV.gdshaderinc b/addons/ShaderLib/UV/SwirlUV.gdshaderinc index e277554..e776d71 100644 --- a/addons/ShaderLib/UV/SwirlUV.gdshaderinc +++ b/addons/ShaderLib/UV/SwirlUV.gdshaderinc @@ -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; } \ No newline at end of file diff --git a/addons/ShaderLib/UV/TwirlUV.gdshaderinc b/addons/ShaderLib/UV/TwirlUV.gdshaderinc index 50c04a7..e4f492f 100644 --- a/addons/ShaderLib/UV/TwirlUV.gdshaderinc +++ b/addons/ShaderLib/UV/TwirlUV.gdshaderinc @@ -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; } \ No newline at end of file