summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-12-14 15:16:11 -0800
committeryum <yum.food.vr@gmail.com>2025-12-14 15:16:13 -0800
commit86231f011e0593e6bd50616105d13b83e642d25c (patch)
tree93735dcf47c337bd7280b0302134fce49eeb5d47
parent220aaf68d67538dbc1e5d3a0488498a59a9ee95b (diff)
shitty ai code, preparing to rewrite
-rw-r--r--3ner.shader2
-rw-r--r--vertex_deformation.slang69
2 files changed, 36 insertions, 35 deletions
diff --git a/3ner.shader b/3ner.shader
index 249f02b..bb14f24 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -209,7 +209,7 @@ Shader "yum_food/3ner"
[ThryToggle(_VERTEX_DEFORMATION_XZ_TUBE)] _Vertex_Deformation_XZ_Tube_Enabled("Enable", Float) = 0
_Vertex_Deformation_XZ_Tube_p("p", Vector) = (0, 0, 1)
_Vertex_Deformation_XZ_Tube_r("r", Vector) = (0, 0, -1)
- _Vertex_Deformation_XZ_Tube_r("s", Vector) = (0, 0, -1)
+ _Vertex_Deformation_XZ_Tube_s("s", Vector) = (0, 0, -1)
_Vertex_Deformation_XZ_Tube_t("t", Range(-1,1)) = 0
[HideInInspector] m_end_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0
//endex
diff --git a/vertex_deformation.slang b/vertex_deformation.slang
index f22e71f..dc77516 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -94,50 +94,51 @@ float2 project_x_onto_y(float2 x, float2 y) {
// Maps a 2x2 quad on the xy plane to a tube. The circular cross section
// is on the xz plane.
[Differentiable]
-public float3 plane_to_tube(float3 xyz, no_diff float3 p, no_diff float3 r, no_diff float3 s, no_diff float t) {
- xyz = 0;
+public float3 plane_to_tube(float3 xyz,
+ no_diff float3 p, no_diff float3 r_cart, no_diff float3 s_cart, no_diff float t) {
// Convert from cartesian to (r, s, r x s) space.
// Ensure orthonormal basis vectors.
// TODO remove normalize, do at higher level of stack.
- r = normalize(r);
- s = normalize(s);
- float3 rxs = cross(r, s);
- float3x3 to_rsrxs = transpose(float3x3(r, s, rxs));
+ r_cart = normalize(r_cart);
+ s_cart = normalize(s_cart);
+ float3 rxs_cart = cross(s_cart, r_cart);
+ float3x3 to_rsrxs = transpose(float3x3(r_cart, s_cart, rxs_cart));
float3x3 to_cart = inverse(to_rsrxs, determinant(to_rsrxs));
// Translate origin to `p` then change into (r, s, r x s) basis.
xyz = mul(to_rsrxs, xyz - p);
- // Project onto (r, r x s) plane.
- float2 v0 = xyz.xz;
-
- float2 v0_hat = normalize(v0);
- float2 Lr = float2(v0.x, 0);
- float2 Lv0 = float2(0, v0.y);
- float Lr_norm = abs(Lr.x);
- float Lv0_norm = abs(Lv0.y);
- float epsilon = 1e-4;
- float theta = Lv0_norm / (Lr_norm + epsilon);
- float phi = atan2(Lv0_norm, Lr_norm);
- float theta_p = lerp(theta, phi, t);
- float2x2 rot = float2x2(
- cos(theta_p), -sin(theta_p),
- sin(theta_p), cos(theta_p));
-
- // float2(1, 0) is written as `r` in (2) in the notes. We just rewrite it
- // here since we're in the rotated frame.
- // We also don't have to add p since again we're in the rotated and
- // translated frame.
- float2 v = mul(rot, dlerp(float2(1, 0) * Lv0_norm, Lr, t));
-
- // Un-project.
- xyz.xz = v.xy;
+ // 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
- // Move back into cartesian basis.
- xyz = mul(to_cart, xyz);
+ 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;
- // Translate p back away from origin.
- xyz += p;
+ // Radial interpolation per derivation.
+ float radius = dlerp(r0, r1, t);
+ float2 nb_t = float2(cos(theta_p), sin(theta_p)) * radius;
+
+ // Reconstruct with preserved axial component.
+ xyz = float3(nb_t.x, s, nb_t.y);
+
+ // Move back into cartesian basis.
+ xyz = mul(to_cart, xyz) + p;
return xyz;
}