diff options
| author | yum <yum.food.vr@gmail.com> | 2025-12-06 19:09:42 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-12-06 19:10:03 -0800 |
| commit | 036919d692fda532bfba508f77ea9dba37d5c4f9 (patch) | |
| tree | ce12c65635cda34f4a71de690fa33cbff98fbc33 | |
| parent | 0663fa9713e1fc44395401a96f60aca7a947bdbb (diff) | |
begin work on "un-tube" feature
essentially the inverse of the sheet -> tube transform.
| -rw-r--r-- | 3ner.shader | 21 | ||||
| -rw-r--r-- | Images/plane_tube_deformation_derivation.png | bin | 510833 -> 607439 bytes | |||
| -rw-r--r-- | LUTS/dfg_cloth.exr.meta | 2 | ||||
| -rw-r--r-- | features.cginc | 3 | ||||
| -rw-r--r-- | globals.cginc | 9 | ||||
| -rw-r--r-- | vertex.cginc | 135 | ||||
| -rw-r--r-- | vertex_deformation.slang | 39 |
7 files changed, 206 insertions, 3 deletions
diff --git a/3ner.shader b/3ner.shader index 609bac2..1334699 100644 --- a/3ner.shader +++ b/3ner.shader @@ -183,6 +183,27 @@ 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 + //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 + //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 + //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 diff --git a/Images/plane_tube_deformation_derivation.png b/Images/plane_tube_deformation_derivation.png Binary files differindex 4ce0130..9103ca7 100644 --- a/Images/plane_tube_deformation_derivation.png +++ b/Images/plane_tube_deformation_derivation.png diff --git a/LUTS/dfg_cloth.exr.meta b/LUTS/dfg_cloth.exr.meta index 2dc43e3..450e377 100644 --- a/LUTS/dfg_cloth.exr.meta +++ b/LUTS/dfg_cloth.exr.meta @@ -22,7 +22,7 @@ TextureImporter: normalMapFilter: 0 flipGreenChannel: 0 isReadable: 0 - streamingMipmaps: 0 + streamingMipmaps: 1 streamingMipmapsPriority: 0 vTOnly: 0 ignoreMipmapLimit: 0 diff --git a/features.cginc b/features.cginc index 08d8e3f..af52b18 100644 --- a/features.cginc +++ b/features.cginc @@ -39,6 +39,9 @@ //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_XZ_TUBE #pragma shader_feature_local _VERTEX_DEFORMATION_YZ_TUBE #pragma shader_feature_local _VERTEX_DEFORMATION_XY_TUBE diff --git a/globals.cginc b/globals.cginc index 56d9e49..4e03e0b 100644 --- a/globals.cginc +++ b/globals.cginc @@ -78,6 +78,15 @@ texture2D _Cloth_Sheen_DFG_LUT; #if defined(_VERTEX_DEFORMATION_XY_TUBE) float _Vertex_Deformation_XY_Tube_t; #endif // _VERTEX_DEFORMATION_XY_TUBE +#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_XZ_TUBE) float _Vertex_Deformation_XZ_Tube_t; #endif // _VERTEX_DEFORMATION_XZ_TUBE diff --git a/vertex.cginc b/vertex.cginc index 9cdbead..f82fad6 100644 --- a/vertex.cginc +++ b/vertex.cginc @@ -6,6 +6,59 @@ #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) +#else +#define VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE +#define VERTEX_DEFORM_XZ_UNTUBE_POS +#define VERTEX_DEFORM_XZ_UNTUBE_NORM +#endif // VERTEX_DEFORMATION_XZ_UNTUBE + +#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 +#else +#define VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE +#define VERTEX_DEFORM_YZ_UNTUBE_POS +#define VERTEX_DEFORM_YZ_UNTUBE_NORM +#endif // VERTEX_DEFORMATION_YZ_UNTUBE + +#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 +#else +#define VERTEX_DEFORM_XY_UNTUBE_PREAMBLE +#define VERTEX_DEFORM_XY_UNTUBE_POS +#define VERTEX_DEFORM_XY_UNTUBE_NORM +#endif // VERTEX_DEFORMATION_XY_UNTUBE + #if defined(_VERTEX_DEFORMATION_XZ_TUBE) #define VERTEX_DEFORM_XZ_TUBE_PREAMBLE \ float t = _Vertex_Deformation_XZ_Tube_t @@ -128,6 +181,18 @@ void deform(inout float3 objPos) { const float t = getTime(); { + VERTEX_DEFORM_XZ_UNTUBE_PREAMBLE; + VERTEX_DEFORM_XZ_UNTUBE_POS; + } + { + VERTEX_DEFORM_YZ_UNTUBE_PREAMBLE; + VERTEX_DEFORM_YZ_UNTUBE_POS; + } + { + VERTEX_DEFORM_XY_UNTUBE_PREAMBLE; + VERTEX_DEFORM_XY_UNTUBE_POS; + } + { VERTEX_DEFORM_XZ_TUBE_PREAMBLE; VERTEX_DEFORM_XZ_TUBE_POS; } @@ -160,6 +225,18 @@ 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_YZ_UNTUBE_PREAMBLE; + VERTEX_DEFORM_YZ_UNTUBE_NORM; + } + { + VERTEX_DEFORM_XY_UNTUBE_PREAMBLE; + VERTEX_DEFORM_XY_UNTUBE_NORM; + } + { VERTEX_DEFORM_XZ_TUBE_PREAMBLE; VERTEX_DEFORM_XZ_TUBE_NORM; } @@ -209,6 +286,27 @@ void undeform_normal(inout float3 objPos, inout float3 objNorm, inout float3 obj 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; @@ -338,6 +436,43 @@ void undeform_normal(inout float3 objPos, inout float3 objNorm, inout float3 obj 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; } diff --git a/vertex_deformation.slang b/vertex_deformation.slang index 047f7d7..577b0d2 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -84,7 +84,7 @@ float3x3 inverse(float3x3 m, float det) { return inv; } -// Takes map a 2x2 quad on the xy plane to a tube. The circular cross section +// 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 float t) { @@ -93,7 +93,8 @@ public float3 plane_to_tube(float3 xyz, no_diff float t) { float z0 = xyz.z; float theta = x0 * PI; - float phi = z0 * PI; + + // Equivalent to (1 / (|t| + eps)) * sign(t) float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t); float x = sin(theta / radius) * (radius * PI_RCP - z0); @@ -114,6 +115,40 @@ public void plane_to_tube_undeform_normal(float3 xyz, inout float3 normal, R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); } +// 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; + + float theta = atan2(z0, x0) - PI; + float r = length(float2(x0, z0)); + x0 = r * cos(theta); + z0 = r * sin(theta); + + // Equivalent to (1 / (|t| + eps)) * sign(t) + float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t); + + float x = sin(theta / radius) * (radius * PI_RCP - z0); + float z = (1.0f - cos(theta / radius)) * (radius * PI_RCP) + cos(theta / radius) * z0; + + return float3(x, y0, z); +} + +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); +} + +public void tube_to_plane_undeform_normal(float3 xyz, inout float3 normal, + inout float3 tangent, float t) { + R3R3_DECLARE_BASIS_VECTORS(xyz); + R3R3_AUTODIFF_BASIS_VECTORS(tube_to_plane, 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; |
