summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.shader10
-rw-r--r--features.cginc1
-rw-r--r--globals.cginc7
-rw-r--r--vertex.cginc24
-rw-r--r--vertex_deformation.slang44
5 files changed, 85 insertions, 1 deletions
diff --git a/3ner.shader b/3ner.shader
index eadde89..caf1809 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -223,6 +223,16 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Vertex_Deformation_Plane_To_Tube_0("Plane to Tube 0", Float) = 0
//endex
+ //ifex _Vertex_Deformation_Point_Align_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Point_Align("Point Align", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_POINT_ALIGN)] _Vertex_Deformation_Point_Align_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Point_Align_po("po", Vector) = (0, 0, 0)
+ _Vertex_Deformation_Point_Align_pp("pp", Vector) = (0, 0, 1)
+ _Vertex_Deformation_Point_Align_r("r", Vector) = (0, 1, 0)
+ _Vertex_Deformation_Point_Align_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Point_Align("Point Align", Float) = 0
+ //endex
+
//ifex _Vertex_Deformation_Plane_To_Tube_1_Enabled==0
[HideInInspector] m_start_Vertex_Deformation_Plane_To_Tube_1("Plane to Tube 1", Float) = 0
[ThryToggle(_VERTEX_DEFORMATION_PLANE_TO_TUBE_1)] _Vertex_Deformation_Plane_To_Tube_1_Enabled("Enable", Float) = 0
diff --git a/features.cginc b/features.cginc
index 6dbff87..f5d547f 100644
--- a/features.cginc
+++ b/features.cginc
@@ -43,6 +43,7 @@
#pragma shader_feature_local _VERTEX_DEFORMATION_AXIS_ALIGN
#pragma shader_feature_local _VERTEX_DEFORMATION_TUBE_TO_PLANE_1
#pragma shader_feature_local _VERTEX_DEFORMATION_PLANE_TO_TUBE_0
+#pragma shader_feature_local _VERTEX_DEFORMATION_POINT_ALIGN
#pragma shader_feature_local _VERTEX_DEFORMATION_PLANE_TO_TUBE_1
//endex
diff --git a/globals.cginc b/globals.cginc
index 21d9889..f872847 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -103,6 +103,13 @@ float3 _Vertex_Deformation_Plane_To_Tube_0_s;
float _Vertex_Deformation_Plane_To_Tube_0_t;
#endif // _VERTEX_DEFORMATION_PLANE_TO_TUBE_0
+#if defined(_VERTEX_DEFORMATION_POINT_ALIGN)
+float3 _Vertex_Deformation_Point_Align_po;
+float3 _Vertex_Deformation_Point_Align_pp;
+float3 _Vertex_Deformation_Point_Align_r;
+float _Vertex_Deformation_Point_Align_t;
+#endif // _VERTEX_DEFORMATION_POINT_ALIGN
+
#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_1)
float3 _Vertex_Deformation_Plane_To_Tube_1_p;
float3 _Vertex_Deformation_Plane_To_Tube_1_r;
diff --git a/vertex.cginc b/vertex.cginc
index 67565d9..40c283f 100644
--- a/vertex.cginc
+++ b/vertex.cginc
@@ -70,6 +70,22 @@
#define VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM
#endif // VERTEX_DEFORMATION_PLANE_TO_TUBE_0
+#if defined(_VERTEX_DEFORMATION_POINT_ALIGN)
+#define VERTEX_DEFORM_POINT_ALIGN_PREAMBLE \
+ float3 po = _Vertex_Deformation_Point_Align_po; \
+ float3 pp = _Vertex_Deformation_Point_Align_pp; \
+ float3 r = _Vertex_Deformation_Point_Align_r; \
+ float t = _Vertex_Deformation_Point_Align_t
+#define VERTEX_DEFORM_POINT_ALIGN_POS \
+ objPos = point_align(objPos, po, pp, r, t)
+#define VERTEX_DEFORM_POINT_ALIGN_NORM \
+ point_align_normal(objPos, objNorm, objTan, po, pp, r, t)
+#else
+#define VERTEX_DEFORM_POINT_ALIGN_PREAMBLE
+#define VERTEX_DEFORM_POINT_ALIGN_POS
+#define VERTEX_DEFORM_POINT_ALIGN_NORM
+#endif // VERTEX_DEFORMATION_POINT_ALIGN
+
#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_1)
#define VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE \
float3 p = _Vertex_Deformation_Plane_To_Tube_1_p; \
@@ -171,6 +187,10 @@ void deform(inout float3 objPos) {
VERTEX_DEFORM_PLANE_TO_TUBE_0_POS;
}
{
+ VERTEX_DEFORM_POINT_ALIGN_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_POS;
+ }
+ {
VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE;
VERTEX_DEFORM_PLANE_TO_TUBE_1_POS;
}
@@ -211,6 +231,10 @@ void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTa
VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM;
}
{
+ VERTEX_DEFORM_POINT_ALIGN_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_NORM;
+ }
+ {
VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE;
VERTEX_DEFORM_PLANE_TO_TUBE_1_NORM;
}
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;