summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-12-16 18:06:44 -0800
committeryum <yum.food.vr@gmail.com>2025-12-16 18:06:44 -0800
commita14e29b37e95352d35ba7c8763e2d0fc9fb66803 (patch)
tree4e50cb9550ed143cfc71c2d014e6549eb703c681
parentf3c47133a947581299b1f5a8b82e7233711f096a (diff)
wip, trying to unwrap the torus
-rw-r--r--3ner.shader55
-rw-r--r--features.cginc8
-rw-r--r--globals.cginc43
-rw-r--r--vertex.cginc155
-rw-r--r--vertex_deformation.slang77
5 files changed, 192 insertions, 146 deletions
diff --git a/3ner.shader b/3ner.shader
index d260aff..766091c 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -183,35 +183,44 @@ Shader "yum_food/3ner"
[HideInInspector] m_start_Vertex_Deformation_Tubes("Tubes", Float) = 0
[ThryToggle(_VERTEX_DEFORMATION_TUBES)] _Vertex_Deformation_Tubes_Enabled("Enable", Float) = 0
- //ifex _Vertex_Deformation_XZ_Untube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_XZ_Untube("XZ Untube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_XZ_UNTUBE)] _Vertex_Deformation_XZ_Untube_Enabled("Enable", Float) = 0
- _Vertex_Deformation_XZ_Untube_t("t", Range(-1,1)) = 0
- [HideInInspector] m_end_Vertex_Deformation_XZ_Untube("XZ Untube", Float) = 0
+ //ifex _Vertex_Deformation_Tube_To_Plane_0_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Tube_To_Plane_0("Tube to Plane 0", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_TUBE_TO_PLANE_0)] _Vertex_Deformation_Tube_To_Plane_0_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Tube_To_Plane_0_p("p", Vector) = (0, 0, 0.3183099)
+ _Vertex_Deformation_Tube_To_Plane_0_r("r", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Tube_To_Plane_0_s("s", Vector) = (0, 1, 0)
+ _Vertex_Deformation_Tube_To_Plane_0_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Tube_To_Plane_0("Tube to Plane 0", Float) = 0
//endex
- //ifex _Vertex_Deformation_YZ_Untube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_YZ_Untube("YZ Untube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_YZ_UNTUBE)] _Vertex_Deformation_YZ_Untube_Enabled("Enable", Float) = 0
- _Vertex_Deformation_YZ_Untube_t("t", Range(-1,1)) = 0
- [HideInInspector] m_end_Vertex_Deformation_YZ_Untube("YZ Untube", Float) = 0
+ //ifex _Vertex_Deformation_Tube_To_Plane_1_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Tube_To_Plane_1("Tube to Plane 1", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_TUBE_TO_PLANE_1)] _Vertex_Deformation_Tube_To_Plane_1_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Tube_To_Plane_1_p("p", Vector) = (0, 0, 0.3183099)
+ _Vertex_Deformation_Tube_To_Plane_1_r("r", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Tube_To_Plane_1_s("s", Vector) = (0, 1, 0)
+ _Vertex_Deformation_Tube_To_Plane_1_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Tube_To_Plane_1("Tube to Plane 1", Float) = 0
//endex
- //ifex _Vertex_Deformation_XY_Untube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_XY_Untube("XY Untube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_XY_UNTUBE)] _Vertex_Deformation_XY_Untube_Enabled("Enable", Float) = 0
- _Vertex_Deformation_XY_Untube_t("t", Range(-1,1)) = 0
- [HideInInspector] m_end_Vertex_Deformation_XY_Untube("XY Untube", Float) = 0
+ //ifex _Vertex_Deformation_Plane_To_Tube_0_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Plane_To_Tube_0("Plane to Tube 0", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_PLANE_TO_TUBE_0)] _Vertex_Deformation_Plane_To_Tube_0_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Plane_To_Tube_0_p("p", Vector) = (0, 0, 1)
+ _Vertex_Deformation_Plane_To_Tube_0_r("r", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Plane_To_Tube_0_s("s", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Plane_To_Tube_0_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Plane_To_Tube_0("Plane to Tube 0", Float) = 0
//endex
- //ifex _Vertex_Deformation_Tube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_Plane_To_Tube("Plane to Tube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_PLANE_TO_TUBE)] _Vertex_Deformation_Plane_To_Tube_Enabled("Enable", Float) = 0
- _Vertex_Deformation_Plane_To_Tube_p("p", Vector) = (0, 0, 1)
- _Vertex_Deformation_Plane_To_Tube_r("r", Vector) = (0, 0, -1)
- _Vertex_Deformation_Plane_To_Tube_s("s", Vector) = (0, 0, -1)
- _Vertex_Deformation_Plane_To_Tube_t("t", Range(-1,1)) = 0
- [HideInInspector] m_end_Vertex_Deformation_Plane_To_Tube("Plane to Tube", Float) = 0
+ //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
+ _Vertex_Deformation_Plane_To_Tube_1_p("p", Vector) = (0, 0, 1)
+ _Vertex_Deformation_Plane_To_Tube_1_r("r", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Plane_To_Tube_1_s("s", Vector) = (0, 0, -1)
+ _Vertex_Deformation_Plane_To_Tube_1_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Plane_To_Tube_1("Plane to Tube 1", Float) = 0
//endex
[HideInInspector] m_end_Vertex_Deformation_Tubes("Tubes", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index 5644d37..71fb9b6 100644
--- a/features.cginc
+++ b/features.cginc
@@ -39,10 +39,10 @@
//ifex _Vertex_Deformation_Tubes_Enabled==0
#pragma shader_feature_local _VERTEX_DEFORMATION_TUBES
-#pragma shader_feature_local _VERTEX_DEFORMATION_XZ_UNTUBE
-#pragma shader_feature_local _VERTEX_DEFORMATION_YZ_UNTUBE
-#pragma shader_feature_local _VERTEX_DEFORMATION_XY_UNTUBE
-#pragma shader_feature_local _VERTEX_DEFORMATION_PLANE_TO_TUBE
+#pragma shader_feature_local _VERTEX_DEFORMATION_TUBE_TO_PLANE_0
+#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_PLANE_TO_TUBE_1
//endex
//ifex _Vertex_Deformation_L2_L1_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index 54f58f2..b5d6b21 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -75,22 +75,33 @@ float3 _Cloth_Sheen_Color;
texture2D _Cloth_Sheen_DFG_LUT;
#endif // _CLOTH_SHEEN
-#if defined(_VERTEX_DEFORMATION_XY_UNTUBE)
-float _Vertex_Deformation_XY_Untube_t;
-#endif // _VERTEX_DEFORMATION_XY_UNTUBE
-#if defined(_VERTEX_DEFORMATION_XZ_UNTUBE)
-float _Vertex_Deformation_XZ_Untube_t;
-#endif // _VERTEX_DEFORMATION_XZ_UNTUBE
-#if defined(_VERTEX_DEFORMATION_YZ_UNTUBE)
-float _Vertex_Deformation_YZ_Untube_t;
-#endif // _VERTEX_DEFORMATION_YZ_UNTUBE
-
-#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE)
-float3 _Vertex_Deformation_Plane_To_Tube_p;
-float3 _Vertex_Deformation_Plane_To_Tube_r;
-float3 _Vertex_Deformation_Plane_To_Tube_s;
-float _Vertex_Deformation_Plane_To_Tube_t;
-#endif // _VERTEX_DEFORMATION_PLANE_TO_TUBE
+#if defined(_VERTEX_DEFORMATION_TUBE_TO_PLANE_0)
+float3 _Vertex_Deformation_Tube_To_Plane_0_p;
+float3 _Vertex_Deformation_Tube_To_Plane_0_r;
+float3 _Vertex_Deformation_Tube_To_Plane_0_s;
+float _Vertex_Deformation_Tube_To_Plane_0_t;
+#endif // _VERTEX_DEFORMATION_TUBE_TO_PLANE_0
+
+#if defined(_VERTEX_DEFORMATION_TUBE_TO_PLANE_1)
+float3 _Vertex_Deformation_Tube_To_Plane_1_p;
+float3 _Vertex_Deformation_Tube_To_Plane_1_r;
+float3 _Vertex_Deformation_Tube_To_Plane_1_s;
+float _Vertex_Deformation_Tube_To_Plane_1_t;
+#endif // _VERTEX_DEFORMATION_TUBE_TO_PLANE_1
+
+#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_0)
+float3 _Vertex_Deformation_Plane_To_Tube_0_p;
+float3 _Vertex_Deformation_Plane_To_Tube_0_r;
+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_PLANE_TO_TUBE_1)
+float3 _Vertex_Deformation_Plane_To_Tube_1_p;
+float3 _Vertex_Deformation_Plane_To_Tube_1_r;
+float3 _Vertex_Deformation_Plane_To_Tube_1_s;
+float _Vertex_Deformation_Plane_To_Tube_1_t;
+#endif // _VERTEX_DEFORMATION_PLANE_TO_TUBE_1
#if defined(_VERTEX_DEFORMATION_NORM_CONVERSION)
float _Vertex_Deformation_Norm_Conversion_Input_k;
diff --git a/vertex.cginc b/vertex.cginc
index a5770f2..3d87f35 100644
--- a/vertex.cginc
+++ b/vertex.cginc
@@ -6,74 +6,69 @@
#define FOO(x) (x)
-#if defined(_VERTEX_DEFORMATION_XZ_UNTUBE)
-#define VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE \
- float t = _Vertex_Deformation_XZ_Untube_t
-#define VERTEX_DEFORM_XZ_UNTUBE_POS \
- objPos = tube_to_plane(objPos.xyz, t)
-#define VERTEX_DEFORM_XZ_UNTUBE_NORM \
- tube_to_plane_normal(objPos, objNorm, objTan, t)
+#if defined(_VERTEX_DEFORMATION_TUBE_TO_PLANE_0)
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE \
+ float3 p = _Vertex_Deformation_Tube_To_Plane_0_p; \
+ float3 r = _Vertex_Deformation_Tube_To_Plane_0_r; \
+ float3 s = _Vertex_Deformation_Tube_To_Plane_0_s; \
+ float t = _Vertex_Deformation_Tube_To_Plane_0_t
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_POS \
+ objPos = tube_to_plane(objPos, p, r, s, t)
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_NORM \
+ tube_to_plane_normal(objPos, objNorm, objTan, p, r, s, t)
#else
-#define VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE
-#define VERTEX_DEFORM_XZ_UNTUBE_POS
-#define VERTEX_DEFORM_XZ_UNTUBE_NORM
-#endif // VERTEX_DEFORMATION_XZ_UNTUBE
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_POS
+#define VERTEX_DEFORM_TUBE_TO_PLANE_0_NORM
+#endif // VERTEX_DEFORMATION_TUBE_TO_PLANE_0
-#if defined(_VERTEX_DEFORMATION_YZ_UNTUBE)
-#define VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE \
- float t = _Vertex_Deformation_YZ_Untube_t
-#define VERTEX_DEFORM_YZ_UNTUBE_POS \
- objPos = tube_to_plane(objPos.yxz, t); \
- objPos = objPos.yxz
-#define VERTEX_DEFORM_YZ_UNTUBE_NORM \
- float3 yzPos = objPos.yxz; \
- float3 yzNorm = objNorm.yxz; \
- float3 yzTan = objTan.yxz; \
- tube_to_plane_normal(yzPos, yzNorm, yzTan, t); \
- objPos = yzPos.yxz; \
- objNorm = yzNorm.yxz; \
- objTan = yzTan.yxz
+#if defined(_VERTEX_DEFORMATION_TUBE_TO_PLANE_1)
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE \
+ float3 p = _Vertex_Deformation_Tube_To_Plane_1_p; \
+ float3 r = _Vertex_Deformation_Tube_To_Plane_1_r; \
+ float3 s = _Vertex_Deformation_Tube_To_Plane_1_s; \
+ float t = _Vertex_Deformation_Tube_To_Plane_1_t
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_POS \
+ objPos = tube_to_plane(objPos, p, r, s, t)
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_NORM \
+ tube_to_plane_normal(objPos, objNorm, objTan, p, r, s, t)
#else
-#define VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE
-#define VERTEX_DEFORM_YZ_UNTUBE_POS
-#define VERTEX_DEFORM_YZ_UNTUBE_NORM
-#endif // VERTEX_DEFORMATION_YZ_UNTUBE
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_POS
+#define VERTEX_DEFORM_TUBE_TO_PLANE_1_NORM
+#endif // VERTEX_DEFORMATION_TUBE_TO_PLANE_1
-#if defined(_VERTEX_DEFORMATION_XY_UNTUBE)
-#define VERTEX_DEFORM_XY_UNTUBE_PREAMBLE \
- float t = _Vertex_Deformation_XY_Untube_t
-#define VERTEX_DEFORM_XY_UNTUBE_POS \
- objPos = tube_to_plane(objPos.xzy, t); \
- objPos = objPos.xzy
-#define VERTEX_DEFORM_XY_UNTUBE_NORM \
- float3 xyPos = objPos.xzy; \
- float3 xyNorm = objNorm.xzy; \
- float3 xyTan = objTan.xzy; \
- tube_to_plane_normal(xyPos, xyNorm, xyTan, t); \
- objPos = xyPos.xzy; \
- objNorm = xyNorm.xzy; \
- objTan = xyTan.xzy
+#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_0)
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE \
+ float3 p = _Vertex_Deformation_Plane_To_Tube_0_p; \
+ float3 r = _Vertex_Deformation_Plane_To_Tube_0_r; \
+ float3 s = _Vertex_Deformation_Plane_To_Tube_0_s; \
+ float t = _Vertex_Deformation_Plane_To_Tube_0_t
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_POS \
+ objPos = plane_to_tube(objPos, p, r, s, t)
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM \
+ plane_to_tube_normal(objPos, objNorm, objTan, p, r, s, t)
#else
-#define VERTEX_DEFORM_XY_UNTUBE_PREAMBLE
-#define VERTEX_DEFORM_XY_UNTUBE_POS
-#define VERTEX_DEFORM_XY_UNTUBE_NORM
-#endif // VERTEX_DEFORMATION_XY_UNTUBE
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_POS
+#define VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM
+#endif // VERTEX_DEFORMATION_PLANE_TO_TUBE_0
-#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE)
-#define VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE \
- float3 p = _Vertex_Deformation_Plane_To_Tube_p; \
- float3 r = _Vertex_Deformation_Plane_To_Tube_r; \
- float3 s = _Vertex_Deformation_Plane_To_Tube_s; \
- float t = _Vertex_Deformation_Plane_To_Tube_t
-#define VERTEX_DEFORM_PLANE_TO_TUBE_POS \
- objPos = plane_to_tube(objPos.xyz, p, r, s, t)
-#define VERTEX_DEFORM_PLANE_TO_TUBE_NORM \
- plane_to_tube_normal(objPos.xyz, objNorm, objTan, p, r, s, t)
+#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; \
+ float3 r = _Vertex_Deformation_Plane_To_Tube_1_r; \
+ float3 s = _Vertex_Deformation_Plane_To_Tube_1_s; \
+ float t = _Vertex_Deformation_Plane_To_Tube_1_t
+#define VERTEX_DEFORM_PLANE_TO_TUBE_1_POS \
+ objPos = plane_to_tube(objPos, p, r, s, t)
+#define VERTEX_DEFORM_PLANE_TO_TUBE_1_NORM \
+ plane_to_tube_normal(objPos, objNorm, objTan, p, r, s, t)
#else
-#define VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE
-#define VERTEX_DEFORM_PLANE_TO_TUBE_POS
-#define VERTEX_DEFORM_PLANE_TO_TUBE_NORM
-#endif // VERTEX_DEFORMATION_PLANE_TO_TUBE
+#define VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE
+#define VERTEX_DEFORM_PLANE_TO_TUBE_1_POS
+#define VERTEX_DEFORM_PLANE_TO_TUBE_1_NORM
+#endif // VERTEX_DEFORMATION_PLANE_TO_TUBE_1
#if defined(_VERTEX_DEFORMATION_NORM_CONVERSION)
#define VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE \
@@ -81,7 +76,7 @@
float input_k = _Vertex_Deformation_Norm_Conversion_Input_k; \
float output_k = _Vertex_Deformation_Norm_Conversion_Output_k
#define VERTEX_DEFORM_NORM_CONVERSION_POS \
- objPos = norm_conversion(objPos.xyz, input_k, output_k, t)
+ objPos = norm_conversion(objPos, input_k, output_k, t)
#define VERTEX_DEFORM_NORM_CONVERSION_NORM \
norm_conversion_normal(objPos, objNorm, objTan, input_k, output_k, t)
#else
@@ -96,7 +91,7 @@
float k = _Vertex_Deformation_Seal_k; \
float st = t * _Vertex_Deformation_Seal_t
#define VERTEX_DEFORM_SEAL_POS \
- objPos = seal(objPos.xyz, A, k, st)
+ objPos = seal(objPos, A, k, st)
#define VERTEX_DEFORM_SEAL_NORM \
seal_normal(objPos, objNorm, objTan, A, k, st)
#else
@@ -113,7 +108,7 @@
float3 k = _Vertex_Deformation_Sine_Waves_k; \
float3 omega = _Vertex_Deformation_Sine_Waves_omega
#define VERTEX_DEFORM_SINE_WAVES_POS \
- objPos = sine_wave(objPos.xyz, amplitude, direction, k, omega, st)
+ objPos = sine_wave(objPos, amplitude, direction, k, omega, st)
#define VERTEX_DEFORM_SINE_WAVES_NORM \
sine_wave_normal(objPos, objNorm, objTan, amplitude, direction, k, omega, st)
#else
@@ -144,20 +139,20 @@
void deform(inout float3 objPos) {
const float t = getTime();
{
- VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_UNTUBE_POS;
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_POS;
}
{
- VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_UNTUBE_POS;
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_POS;
}
{
- VERTEX_DEFORM_XY_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XY_UNTUBE_POS;
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_POS;
}
{
- VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE;
- VERTEX_DEFORM_PLANE_TO_TUBE_POS;
+ VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_1_POS;
}
{
VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
@@ -180,20 +175,20 @@ void deform(inout float3 objPos) {
void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTan) {
const float t = getTime();
{
- VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_UNTUBE_NORM;
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_NORM;
}
{
- VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_UNTUBE_NORM;
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_NORM;
}
{
- VERTEX_DEFORM_XY_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XY_UNTUBE_NORM;
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM;
}
{
- VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE;
- VERTEX_DEFORM_PLANE_TO_TUBE_NORM;
+ VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_1_NORM;
}
{
VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
diff --git a/vertex_deformation.slang b/vertex_deformation.slang
index 3118394..aea1b5b 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -97,7 +97,8 @@ float2 project_x_onto_y(float2 x, float2 y) {
// be orthogonal `s_cart`.
[Differentiable]
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) {
+ 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.
@@ -157,39 +158,69 @@ public void plane_to_tube_undeform_normal(float3 xyz, inout float3 normal,
// Maps a tube with circular cross section on the xz plane to a quad on the xy
// plane.
[Differentiable]
-public float3 tube_to_plane(float3 xyz, no_diff float t) {
- float x0 = xyz.x;
- float y0 = xyz.y;
- float z0 = xyz.z;
+public float3 tube_to_plane(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_cart = normalize(r_cart);
+ s_cart = normalize(s_cart);
+ float3 rxs_cart = cross(s_cart, r_cart);
+ float3x3 to_rsrxs = 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);
+
+ // Components in pivot basis: n (neutral axis), b (tangential), h (axial s).
+ float epsilon = 1e-4f;
+ float r = xyz.x; // Lr
+ float s = xyz.y; // Lv0 x Lr
+ float rxs = xyz.z; // Lv0
+ float2 v0 = float2(r, rxs);
- // Tube has 2m circumference.
- // C = pi d = 2 pi r
- // r = C / (2 pi) = 2 / 2 pi = 1 / pi
- float ref_r = RCP_PI;
- float theta = atan2(z0 - ref_r, x0 - ref_r) - PI;
- float r = length(float2(x0, z0));
+ float theta0 = atan2(rxs, r);
+ float Lr = length(v0);
+ float Lv0 = theta0 * Lr;
+ float phi = atan2(Lv0, Lr);
+ float rr = length(float2(Lr, Lv0));
- x0 = x0 + r * cos(theta);
- z0 = z0 - r * sin(theta);
+ // 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 r0 = Lr;
+ float r1 = rr;
- // Equivalent to (1 / (|t| + eps)) * sign(t)
- float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t);
+ float theta1 = phi;
- float x = sin(theta / radius) * (radius * PI_RCP - z0);
- float z = (1.0f - cos(theta / radius)) * (radius * PI_RCP) + cos(theta / radius) * z0;
+ // Interpolate polar coordinates.
+ float radius = dlerp(r0, r1, t);
+ float theta = dlerp(theta0, theta1, t);
- return float3(x, y0, z);
+ // Map into (r, rxs) basis.
+ float2 nb_t = float2(cos(theta), sin(theta)) * radius;
+
+ // Un-project from (r, rxs) plane to full (r, s, rxs) basis.
+ xyz = float3(nb_t.x, s, nb_t.y);
+
+ // Map back to cartesian basis.
+ xyz = mul(to_cart, xyz) + p;
+
+ return xyz;
}
public void tube_to_plane_normal(inout float3 xyz, inout float3 normal,
- inout float3 tangent, float t) {
- R3R3_NORMALS(xyz, normal, tangent, tube_to_plane, t);
+ inout float3 tangent, float3 p, float3 r, float3 s, float t) {
+ R3R3_NORMALS(xyz, normal, tangent, tube_to_plane, p, r, s, t);
}
-public void tube_to_plane_undeform_normal(float3 xyz, inout float3 normal,
- inout float3 tangent, float t) {
+public void tube_to_plane_undeform_normal(
+ float3 xyz, inout float3 normal, inout float3 tangent,
+ float3 p, float3 r, float3 s, float t) {
R3R3_DECLARE_BASIS_VECTORS(xyz);
- R3R3_AUTODIFF_BASIS_VECTORS(tube_to_plane, t);
+ R3R3_AUTODIFF_BASIS_VECTORS(tube_to_plane, p, r, s, t);
R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent);
}