summaryrefslogtreecommitdiffstats
path: root/vertex_deformation.slang
diff options
context:
space:
mode:
Diffstat (limited to 'vertex_deformation.slang')
-rw-r--r--vertex_deformation.slang44
1 files changed, 43 insertions, 1 deletions
diff --git a/vertex_deformation.slang b/vertex_deformation.slang
index 0846991..542281b 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -163,7 +163,7 @@ public float3 axis_align(float3 xyz, no_diff float3 po, no_diff float3 pp, no_di
float3 sxr = cross(s, r);
float3x3 to_rsrxs = float3x3(r, s, sxr);
- // Inverse of orthonormal matrix is just the transpose.
+ // Inverse of orthonormal matrix is just the transpos.
float3x3 to_cart = transpose(to_rsrxs);
// Move key vectors into (r, s, sxr) basis centered at `po`, per the derivation.
@@ -276,6 +276,48 @@ public void tube_to_plane_undeform_normal(
}
[Differentiable]
+public float3 point_align(float3 xyz, no_diff float3 po, no_diff float3 pp, no_diff float3 r, no_diff float t) {
+ // We assume that `s` is orthogonal to `r`, and that `r` is normalized.
+ float3 s = normalize(pp - po);
+ float3 sxr = cross(s, r);
+
+ float3x3 to_rsrxs = float3x3(r, s, sxr);
+ // Inverse of orthonormal matrix is just the transpose.
+ float3x3 to_cart = transpose(to_rsrxs);
+
+ // Move key vectors into (r, s, sxr) basis centered at `po`, per the derivation.
+ float3 xyz_rsrxs = mul(to_rsrxs, xyz - po);
+ float3 pp_rsrxs = mul(to_rsrxs, pp - po);
+
+ float2 v1 = xyz_rsrxs.xy;
+ float v1r = v1.x;
+ float v1s = v1.y;
+
+ float vs = v1.y;
+ float qs = pp_rsrxs.y;
+ float qr = v1.x;
+ float2 q = float2(qr, qs);
+ q *= vs / qs;
+
+ xyz_rsrxs.xy = q;
+
+ // Move back into cartesian space.
+ xyz = mul(to_cart, xyz_rsrxs) + po;
+
+ return xyz;
+}
+
+public void point_align_normal(inout float3 xyz, inout float3 normal, inout float3 tangent, float3 po, float3 pp, float3 r, float t) {
+ R3R3_NORMALS(xyz, normal, tangent, point_align, po, pp, r, t);
+}
+
+public void point_align_undeform_normal(float3 xyz, inout float3 normal, inout float3 tangent, float3 po, float3 pp, float3 r, float t) {
+ R3R3_DECLARE_BASIS_VECTORS(xyz);
+ R3R3_AUTODIFF_BASIS_VECTORS(point_align, po, pp, r, t);
+ R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent);
+}
+
+[Differentiable]
public float3 seal(float3 xyz, no_diff float A, no_diff float k, no_diff float t) {
float x = xyz.x;
float y = xyz.y;