summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-12-15 14:20:40 -0800
committeryum <yum.food.vr@gmail.com>2025-12-15 14:20:40 -0800
commitf3c47133a947581299b1f5a8b82e7233711f096a (patch)
treeaeb77cd9f1be96da0b0adc37bf5f509a67cb1684
parent083e299fb8a09c09d93dc4c2d10d5010c50e38ec (diff)
more tube-plane simplifications
-rw-r--r--3ner.shader36
-rw-r--r--features.cginc4
-rw-r--r--globals.cginc24
-rw-r--r--vertex.cginc305
-rw-r--r--vertex_deformation.slang30
5 files changed, 47 insertions, 352 deletions
diff --git a/3ner.shader b/3ner.shader
index 0819f3d..d260aff 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -204,34 +204,14 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Vertex_Deformation_XY_Untube("XY Untube", Float) = 0
//endex
- //ifex _Vertex_Deformation_XZ_Tube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0
- [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_s("s", Vector) = (0, 0, -1)
- _Vertex_Deformation_XZ_Tube_t("t", Range(-1,4)) = 0
- [HideInInspector] m_end_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0
- //endex
-
- //ifex _Vertex_Deformation_YZ_Tube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_YZ_Tube("YZ Tube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_YZ_TUBE)] _Vertex_Deformation_YZ_Tube_Enabled("Enable", Float) = 0
- _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,4)) = 0
- [HideInInspector] m_end_Vertex_Deformation_YZ_Tube("YZ Tube", Float) = 0
- //endex
-
- //ifex _Vertex_Deformation_XY_Tube_Enabled==0
- [HideInInspector] m_start_Vertex_Deformation_XY_Tube("XY Tube", Float) = 0
- [ThryToggle(_VERTEX_DEFORMATION_XY_TUBE)] _Vertex_Deformation_XY_Tube_Enabled("Enable", Float) = 0
- _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,4)) = 0
- [HideInInspector] m_end_Vertex_Deformation_XY_Tube("XY Tube", Float) = 0
+ //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
//endex
[HideInInspector] m_end_Vertex_Deformation_Tubes("Tubes", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index af52b18..5644d37 100644
--- a/features.cginc
+++ b/features.cginc
@@ -42,9 +42,7 @@
#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_XZ_TUBE
-#pragma shader_feature_local _VERTEX_DEFORMATION_YZ_TUBE
-#pragma shader_feature_local _VERTEX_DEFORMATION_XY_TUBE
+#pragma shader_feature_local _VERTEX_DEFORMATION_PLANE_TO_TUBE
//endex
//ifex _Vertex_Deformation_L2_L1_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index c838091..54f58f2 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -85,24 +85,12 @@ float _Vertex_Deformation_XZ_Untube_t;
float _Vertex_Deformation_YZ_Untube_t;
#endif // _VERTEX_DEFORMATION_YZ_UNTUBE
-#if defined(_VERTEX_DEFORMATION_XY_TUBE)
-float3 _Vertex_Deformation_XY_Tube_p;
-float3 _Vertex_Deformation_XY_Tube_r;
-float3 _Vertex_Deformation_XY_Tube_s;
-float _Vertex_Deformation_XY_Tube_t;
-#endif // _VERTEX_DEFORMATION_XY_TUBE
-#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
-float3 _Vertex_Deformation_XZ_Tube_p;
-float3 _Vertex_Deformation_XZ_Tube_r;
-float3 _Vertex_Deformation_XZ_Tube_s;
-float _Vertex_Deformation_XZ_Tube_t;
-#endif // _VERTEX_DEFORMATION_XZ_TUBE
-#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
-float3 _Vertex_Deformation_YZ_Tube_p;
-float3 _Vertex_Deformation_YZ_Tube_r;
-float3 _Vertex_Deformation_YZ_Tube_s;
-float _Vertex_Deformation_YZ_Tube_t;
-#endif // _VERTEX_DEFORMATION_YZ_TUBE
+#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_NORM_CONVERSION)
float _Vertex_Deformation_Norm_Conversion_Input_k;
diff --git a/vertex.cginc b/vertex.cginc
index daa5ce0..a5770f2 100644
--- a/vertex.cginc
+++ b/vertex.cginc
@@ -59,67 +59,21 @@
#define VERTEX_DEFORM_XY_UNTUBE_NORM
#endif // VERTEX_DEFORMATION_XY_UNTUBE
-#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
-#define VERTEX_DEFORM_XZ_TUBE_PREAMBLE \
- float3 p = _Vertex_Deformation_XZ_Tube_p; \
- float3 r = _Vertex_Deformation_XZ_Tube_r; \
- float3 s = _Vertex_Deformation_XZ_Tube_s; \
- float t = _Vertex_Deformation_XZ_Tube_t
-#define VERTEX_DEFORM_XZ_TUBE_POS \
+#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_XZ_TUBE_NORM \
+#define VERTEX_DEFORM_PLANE_TO_TUBE_NORM \
plane_to_tube_normal(objPos.xyz, objNorm, objTan, p, r, s, t)
#else
-#define VERTEX_DEFORM_XZ_TUBE_PREAMBLE
-#define VERTEX_DEFORM_XZ_TUBE_POS
-#define VERTEX_DEFORM_XZ_TUBE_NORM
-#endif // VERTEX_DEFORMATION_XZ_TUBE
-
-#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
-#define VERTEX_DEFORM_YZ_TUBE_PREAMBLE \
- float3 p = _Vertex_Deformation_YZ_Tube_p; \
- float3 r = _Vertex_Deformation_YZ_Tube_r; \
- float3 s = _Vertex_Deformation_YZ_Tube_s; \
- float t = _Vertex_Deformation_YZ_Tube_t
-#define VERTEX_DEFORM_YZ_TUBE_POS \
- objPos = plane_to_tube(objPos.yxz, p, r, s, t); \
- objPos = objPos.yxz
-#define VERTEX_DEFORM_YZ_TUBE_NORM \
- float3 yzPos = objPos.yxz; \
- float3 yzNorm = objNorm.yxz; \
- float3 yzTan = objTan.yxz; \
- plane_to_tube_normal(yzPos, yzNorm, yzTan, p, r, s, t); \
- objPos = yzPos.yxz; \
- objNorm = yzNorm.yxz; \
- objTan = yzTan.yxz
-#else
-#define VERTEX_DEFORM_YZ_TUBE_PREAMBLE
-#define VERTEX_DEFORM_YZ_TUBE_POS
-#define VERTEX_DEFORM_YZ_TUBE_NORM
-#endif // VERTEX_DEFORMATION_YZ_TUBE
-
-#if defined(_VERTEX_DEFORMATION_XY_TUBE)
-#define VERTEX_DEFORM_XY_TUBE_PREAMBLE \
- float3 p = _Vertex_Deformation_XY_Tube_p; \
- float3 r = _Vertex_Deformation_XY_Tube_r; \
- float3 s = _Vertex_Deformation_XY_Tube_s; \
- float t = _Vertex_Deformation_XY_Tube_t
-#define VERTEX_DEFORM_XY_TUBE_POS \
- objPos = plane_to_tube(objPos.xzy, p, r, s, t); \
- objPos = objPos.xzy
-#define VERTEX_DEFORM_XY_TUBE_NORM \
- float3 xyPos = objPos.xzy; \
- float3 xyNorm = objNorm.xzy; \
- float3 xyTan = objTan.xzy; \
- plane_to_tube_normal(xyPos, xyNorm, xyTan, p, r, s, t); \
- objPos = xyPos.xzy; \
- objNorm = xyNorm.xzy; \
- objTan = xyTan.xzy
-#else
-#define VERTEX_DEFORM_XY_TUBE_PREAMBLE
-#define VERTEX_DEFORM_XY_TUBE_POS
-#define VERTEX_DEFORM_XY_TUBE_NORM
-#endif // VERTEX_DEFORMATION_XY_TUBE
+#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
#if defined(_VERTEX_DEFORMATION_NORM_CONVERSION)
#define VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE \
@@ -202,16 +156,8 @@ void deform(inout float3 objPos) {
VERTEX_DEFORM_XY_UNTUBE_POS;
}
{
- VERTEX_DEFORM_XZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_TUBE_POS;
- }
- {
- VERTEX_DEFORM_YZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_TUBE_POS;
- }
- {
- VERTEX_DEFORM_XY_TUBE_PREAMBLE;
- VERTEX_DEFORM_XY_TUBE_POS;
+ VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_POS;
}
{
VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
@@ -246,16 +192,8 @@ void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTa
VERTEX_DEFORM_XY_UNTUBE_NORM;
}
{
- VERTEX_DEFORM_XZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_TUBE_NORM;
- }
- {
- VERTEX_DEFORM_YZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_TUBE_NORM;
- }
- {
- VERTEX_DEFORM_XY_TUBE_PREAMBLE;
- VERTEX_DEFORM_XY_TUBE_NORM;
+ VERTEX_DEFORM_PLANE_TO_TUBE_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_NORM;
}
{
VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
@@ -275,217 +213,6 @@ void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTa
}
}
-// `objPos` is in the un-deformed coordinate system, while `objNorm` and
-// `objTan` are in the deformed coordinate system. The task is to map `objNorm`
-// and `objTan` to the un-deformed coordinate system.
-// We do this, coarsely, as follows:
-// 1. Map objPos into the deformed coordinate system through stepwise
-// transformations, like `deform`. We remember each position along the way.
-// 2. Map objNorm and objTan back one step using the deformed final position.
-// For the first iteration, we use the last (deformed) `objPos` that we
-// remembered from step 1.
-// 3. Repeat step 2 until we're back in the un-deforme coordinate system. At
-// each step, we use the cached objPos from the forward pass (step 1), so
-// that we evaluate the normal deformation at the correct point in space.
-void undeform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTan) {
- const float t = getTime();
- const int kMaxDeformations = 32;
- // Cache each intermediate position so we can undo stages in reverse order.
- float3 posHistory[kMaxDeformations + 1];
- int posCount = 0;
- posHistory[posCount++] = objPos;
-
-#if defined(_VERTEX_DEFORMATION_XZ_UNTUBE)
- {
- VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_UNTUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_YZ_UNTUBE)
- {
- VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_UNTUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XY_UNTUBE)
- {
- VERTEX_DEFORM_XY_UNTUBE_PREAMBLE;
- VERTEX_DEFORM_XY_UNTUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
- {
- VERTEX_DEFORM_XZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_XZ_TUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
- {
- VERTEX_DEFORM_YZ_TUBE_PREAMBLE;
- VERTEX_DEFORM_YZ_TUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XY_TUBE)
- {
- VERTEX_DEFORM_XY_TUBE_PREAMBLE;
- VERTEX_DEFORM_XY_TUBE_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_NORM_CONVERSION)
- {
- VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
- VERTEX_DEFORM_NORM_CONVERSION_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_SEAL)
- {
- VERTEX_DEFORM_SEAL_PREAMBLE;
- VERTEX_DEFORM_SEAL_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_SINE_WAVES)
- {
- VERTEX_DEFORM_SINE_WAVES_PREAMBLE;
- VERTEX_DEFORM_SINE_WAVES_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_FBM)
- {
- VERTEX_DEFORM_FBM_PREAMBLE;
- VERTEX_DEFORM_FBM_POS;
- posHistory[posCount++] = objPos;
- }
-#endif
- float3 objPos_deformed = objPos;
-
- int cursor = posCount - 1;
- objPos = posHistory[cursor];
-
-#if defined(_VERTEX_DEFORMATION_FBM)
- if (cursor > 0) {
- VERTEX_DEFORM_FBM_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- fbm_undeform_normal(stageInput, st, amplitude, gain, lacunarity, scale,
- octaves, velocity, objNorm, objTan);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_SINE_WAVES)
- if (cursor > 0) {
- VERTEX_DEFORM_SINE_WAVES_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- sine_wave_undeform_normal(stageInput, objNorm, objTan, amplitude, direction,
- k, omega, st);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_SEAL)
- if (cursor > 0) {
- VERTEX_DEFORM_SEAL_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- seal_undeform_normal(stageInput, objNorm, objTan, A, k, st);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_NORM_CONVERSION)
- if (cursor > 0) {
- VERTEX_DEFORM_NORM_CONVERSION_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- norm_conversion_undeform_normal(stageInput, objNorm, objTan, input_k, output_k, t);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XY_TUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_XY_TUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- float3 xyPos = stageInput.xzy;
- float3 xyNorm = objNorm.xzy;
- float3 xyTan = objTan.xzy;
- plane_to_tube_undeform_normal(xyPos, xyNorm, xyTan, p, r, s, t);
- objNorm = xyNorm.xzy;
- objTan = xyTan.xzy;
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_YZ_TUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- float3 yzPos = stageInput.yxz;
- float3 yzNorm = objNorm.yxz;
- float3 yzTan = objTan.yxz;
- plane_to_tube_undeform_normal(yzPos, yzNorm, yzTan, p, r, s, t);
- objNorm = yzNorm.yxz;
- objTan = yzTan.yxz;
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_XZ_TUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- plane_to_tube_undeform_normal(stageInput, objNorm, objTan, p, r, s, t);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XY_UNTUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_XY_UNTUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- float3 xyPos = stageInput.xzy;
- float3 xyNorm = objNorm.xzy;
- float3 xyTan = objTan.xzy;
- tube_to_plane_undeform_normal(xyPos, xyNorm, xyTan, t);
- objNorm = xyNorm.xzy;
- objTan = xyTan.xzy;
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_YZ_UNTUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- float3 yzPos = stageInput.yxz;
- float3 yzNorm = objNorm.yxz;
- float3 yzTan = objTan.yxz;
- tube_to_plane_undeform_normal(yzPos, yzNorm, yzTan, t);
- objNorm = yzNorm.yxz;
- objTan = yzTan.yxz;
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-#if defined(_VERTEX_DEFORMATION_XZ_UNTUBE)
- if (cursor > 0) {
- VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE;
- float3 stageInput = posHistory[cursor - 1];
- tube_to_plane_undeform_normal(stageInput, objNorm, objTan, t);
- objPos = stageInput;
- cursor -= 1;
- }
-#endif
-
- objPos = objPos_deformed;
-}
-
void propagateObjPos(inout v2f i) {
i.worldPos = mul(unity_ObjectToWorld, float4(i.objPos, 1));
i.pos = UnityObjectToClipPos(i.objPos);
diff --git a/vertex_deformation.slang b/vertex_deformation.slang
index c193889..3118394 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -91,8 +91,10 @@ float2 project_x_onto_y(float2 x, float2 y) {
return (dot(x, y) / dot(y, y)) * y;
}
-// Maps a 2x2 quad on the xy plane to a tube. The circular cross section
-// is on the xz plane.
+// Maps a 2x2 quad to a tube.
+// `s_cart` is the axis along which the tube is rolled.
+// `r_cart` is an axis along which points are not transformed. It is assumed to
+// 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) {
@@ -102,7 +104,7 @@ public float3 plane_to_tube(float3 xyz,
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_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.
@@ -118,23 +120,23 @@ public float3 plane_to_tube(float3 xyz,
// 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 r0 = length(float2(r, rxs));
+ float r1 = max(abs(r), epsilon);
- float angle_src = atan2(rxs, r);
- float angle_dst = rxs / radius_dst;
+ float theta0 = atan2(rxs, r);
+ float theta1 = rxs / r1;
- float delta = angle_dst - angle_src;
- float angle = angle_src + t * delta;
+ // Interpolate polar coordinates.
+ float radius = dlerp(r0, r1, t);
+ float theta = dlerp(theta0, theta1, t);
- // Radial interpolation per derivation.
- float radius = dlerp(radius_src, radius_dst, t);
- float2 nb_t = float2(cos(angle), sin(angle)) * radius;
+ // Map into (r, rxs) basis.
+ float2 nb_t = float2(cos(theta), sin(theta)) * radius;
- // Reconstruct with preserved axial component.
+ // Un-project from (r, rxs) plane to full (r, s, rxs) basis.
xyz = float3(nb_t.x, s, nb_t.y);
- // Move back into cartesian basis.
+ // Map back to cartesian basis.
xyz = mul(to_cart, xyz) + p;
return xyz;