diff options
| author | yum <yum.food.vr@gmail.com> | 2025-12-14 23:20:36 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-12-14 23:20:36 -0800 |
| commit | 083e299fb8a09c09d93dc4c2d10d5010c50e38ec (patch) | |
| tree | 75d0dd66a9a3684d6711e051c1f851730b4b543a | |
| parent | 86231f011e0593e6bd50616105d13b83e642d25c (diff) | |
rewrite dogshit ai code, make less ass
| -rw-r--r-- | 3ner.shader | 6 | ||||
| -rw-r--r-- | vertex_deformation.slang | 39 |
2 files changed, 21 insertions, 24 deletions
diff --git a/3ner.shader b/3ner.shader index bb14f24..0819f3d 100644 --- a/3ner.shader +++ b/3ner.shader @@ -210,7 +210,7 @@ Shader "yum_food/3ner" _Vertex_Deformation_XZ_Tube_p("p", Vector) = (0, 0, 1) _Vertex_Deformation_XZ_Tube_r("r", Vector) = (0, 0, -1) _Vertex_Deformation_XZ_Tube_s("s", Vector) = (0, 0, -1) - _Vertex_Deformation_XZ_Tube_t("t", Range(-1,1)) = 0 + _Vertex_Deformation_XZ_Tube_t("t", Range(-1,4)) = 0 [HideInInspector] m_end_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0 //endex @@ -220,7 +220,7 @@ Shader "yum_food/3ner" _Vertex_Deformation_YZ_Tube_p("p", Vector) = (0, 0, 1) _Vertex_Deformation_YZ_Tube_r("r", Vector) = (0, 0, -1) _Vertex_Deformation_YZ_Tube_s("s", Vector) = (0, 0, -1) - _Vertex_Deformation_YZ_Tube_t("t", Range(-1,1)) = 0 + _Vertex_Deformation_YZ_Tube_t("t", Range(-1,4)) = 0 [HideInInspector] m_end_Vertex_Deformation_YZ_Tube("YZ Tube", Float) = 0 //endex @@ -230,7 +230,7 @@ Shader "yum_food/3ner" _Vertex_Deformation_XY_Tube_p("p", Vector) = (0, 0, 1) _Vertex_Deformation_XY_Tube_r("r", Vector) = (0, 0, -1) _Vertex_Deformation_XY_Tube_s("s", Vector) = (0, 0, -1) - _Vertex_Deformation_XY_Tube_t("t", Range(-1,1)) = 0 + _Vertex_Deformation_XY_Tube_t("t", Range(-1,4)) = 0 [HideInInspector] m_end_Vertex_Deformation_XY_Tube("XY Tube", Float) = 0 //endex [HideInInspector] m_end_Vertex_Deformation_Tubes("Tubes", Float) = 0 diff --git a/vertex_deformation.slang b/vertex_deformation.slang index dc77516..c193889 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -110,29 +110,26 @@ public float3 plane_to_tube(float3 xyz, // Components in pivot basis: n (neutral axis), b (tangential), h (axial s). float epsilon = 1e-4f; - float r = xyz.x; // neutral-axis coordinate - float s = xyz.y; // axial coordinate along s_cart - float rxs = xyz.z; // tangential coordinate along rxs_cart - - float r0 = length(float2(r, rxs)); // |(r, rxs)| at identity - float r1 = max(abs(r), epsilon); // target radius |r| - - // Directions for identity and wrapped states in the (n, b) plane. - float2 dir0 = float2(r, rxs) / max(r0, epsilon); - float theta_wrap = rxs / r1; // theta = w / r per derivation - float signish = r / r1; // preserves sign of r without branch - float2 dir1 = float2(signish * cos(theta_wrap), sin(theta_wrap)); - - // Shortest-arc angular blend (delta = atan2(cross, dot)) without branchy conditionals. - float dot01 = clamp(dot(dir0, dir1), -1.0f, 1.0f); - float cross01 = dir0.x * dir1.y - dir0.y * dir1.x; - float delta = atan2(cross01, dot01); - float theta0 = atan2(dir0.y, dir0.x); - float theta_p = theta0 + t * delta; + float r = xyz.x; // Lr + float s = xyz.y; // Lv0 x Lr + float rxs = xyz.z; // Lv0 + + // Blend between two vectors: + // v0: vector of length ||Lr + Lv0|| at angle atan2(Lv0, Lr) + // v1: vector of length ||Lr|| at angle ||Lv0|| / ||Lr|| + // Interpolate in polar coordinates to make it wrap nicely. + float radius_src = length(float2(r, rxs)); + float radius_dst = max(abs(r), epsilon); + + float angle_src = atan2(rxs, r); + float angle_dst = rxs / radius_dst; + + float delta = angle_dst - angle_src; + float angle = angle_src + t * delta; // Radial interpolation per derivation. - float radius = dlerp(r0, r1, t); - float2 nb_t = float2(cos(theta_p), sin(theta_p)) * radius; + float radius = dlerp(radius_src, radius_dst, t); + float2 nb_t = float2(cos(angle), sin(angle)) * radius; // Reconstruct with preserved axial component. xyz = float3(nb_t.x, s, nb_t.y); |
