summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-12-25 13:09:39 -0800
committeryum <yum.food.vr@gmail.com>2025-12-25 13:09:39 -0800
commite70d2cb317295571c57abd229846424754dff937 (patch)
tree8640003cd7dde0a6cf6d41d697141c3373f11ed0
parentf7c5e546c220f0f7be8ec3a9cccdb4641114cfe1 (diff)
more vertex deformation tweaks; unwrapping the donut
-rw-r--r--3ner.shader28
-rw-r--r--features.cginc3
-rw-r--r--globals.cginc19
-rw-r--r--vertex.cginc98
-rw-r--r--vertex_deformation.slang23
5 files changed, 110 insertions, 61 deletions
diff --git a/3ner.shader b/3ner.shader
index 442b493..d8ec8fe 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -213,6 +213,16 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Vertex_Deformation_Tube_To_Plane_1("Tube to Plane 1", Float) = 0
//endex
+ //ifex _Vertex_Deformation_Point_Align_0_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Point_Align_0("Point Align 0", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_POINT_ALIGN_0)] _Vertex_Deformation_Point_Align_0_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Point_Align_0_po("po", Vector) = (0, 0, 0)
+ _Vertex_Deformation_Point_Align_0_pp("pp", Vector) = (0, 0, 1)
+ _Vertex_Deformation_Point_Align_0_r("r", Vector) = (0, 1, 0)
+ _Vertex_Deformation_Point_Align_0_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Point_Align_0("Point Align 0", Float) = 0
+ //endex
+
//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
@@ -223,14 +233,14 @@ 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
+ //ifex _Vertex_Deformation_Point_Align_1_Enabled==0
+ [HideInInspector] m_start_Vertex_Deformation_Point_Align_1("Point Align 0", Float) = 0
+ [ThryToggle(_VERTEX_DEFORMATION_POINT_ALIGN_1)] _Vertex_Deformation_Point_Align_1_Enabled("Enable", Float) = 0
+ _Vertex_Deformation_Point_Align_1_po("po", Vector) = (0, 0, 0)
+ _Vertex_Deformation_Point_Align_1_pp("pp", Vector) = (0, 0, 1)
+ _Vertex_Deformation_Point_Align_1_r("r", Vector) = (0, 1, 0)
+ _Vertex_Deformation_Point_Align_1_t("t", Range(0,1)) = 0
+ [HideInInspector] m_end_Vertex_Deformation_Point_Align_1("Point Align 0", Float) = 0
//endex
//ifex _Vertex_Deformation_Plane_To_Tube_1_Enabled==0
@@ -281,7 +291,7 @@ Shader "yum_food/3ner"
_Vertex_Deformation_FBM_Lacunarity("Lacunarity", Range(1,10)) = 2
_Vertex_Deformation_FBM_Amplitude("Amplitude", Vector) = (1, 1, 1, 0)
_Vertex_Deformation_FBM_Period("Period", Vector) = (1, 1, 1, 0)
- _Vertex_Deformation_FBM_Octaves("Octaves", Range(1, 5.1)) = 3
+ [IntRange] _Vertex_Deformation_FBM_Octaves("Octaves", Range(1, 5)) = 3
[HideInInspector] m_end_Vertex_Deformation_FBM("FBM", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index f5d547f..17f0566 100644
--- a/features.cginc
+++ b/features.cginc
@@ -43,7 +43,8 @@
#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_POINT_ALIGN_0
+#pragma shader_feature_local _VERTEX_DEFORMATION_POINT_ALIGN_1
#pragma shader_feature_local _VERTEX_DEFORMATION_PLANE_TO_TUBE_1
//endex
diff --git a/globals.cginc b/globals.cginc
index c096e89..ddb126c 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -103,12 +103,19 @@ 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_POINT_ALIGN_0)
+float3 _Vertex_Deformation_Point_Align_0_po;
+float3 _Vertex_Deformation_Point_Align_0_pp;
+float3 _Vertex_Deformation_Point_Align_0_r;
+float _Vertex_Deformation_Point_Align_0_t;
+#endif // _VERTEX_DEFORMATION_POINT_ALIGN_0
+
+#if defined(_VERTEX_DEFORMATION_POINT_ALIGN_1)
+float3 _Vertex_Deformation_Point_Align_1_po;
+float3 _Vertex_Deformation_Point_Align_1_pp;
+float3 _Vertex_Deformation_Point_Align_1_r;
+float _Vertex_Deformation_Point_Align_1_t;
+#endif // _VERTEX_DEFORMATION_POINT_ALIGN_1
#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_1)
float3 _Vertex_Deformation_Plane_To_Tube_1_p;
diff --git a/vertex.cginc b/vertex.cginc
index 9a1ed2f..acc6d60 100644
--- a/vertex.cginc
+++ b/vertex.cginc
@@ -70,21 +70,37 @@
#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 \
+#if defined(_VERTEX_DEFORMATION_POINT_ALIGN_0)
+#define VERTEX_DEFORM_POINT_ALIGN_0_PREAMBLE \
+ float3 po = _Vertex_Deformation_Point_Align_0_po; \
+ float3 pp = _Vertex_Deformation_Point_Align_0_pp; \
+ float3 r = _Vertex_Deformation_Point_Align_0_r; \
+ float t = _Vertex_Deformation_Point_Align_0_t
+#define VERTEX_DEFORM_POINT_ALIGN_0_POS \
+ objPos = point_align_0(objPos, po, pp, r, t)
+#define VERTEX_DEFORM_POINT_ALIGN_0_NORM \
+ point_align_normal(objPos, objNorm, objTan, po, pp, r, t)
+#else
+#define VERTEX_DEFORM_POINT_ALIGN_0_PREAMBLE
+#define VERTEX_DEFORM_POINT_ALIGN_0_POS
+#define VERTEX_DEFORM_POINT_ALIGN_0_NORM
+#endif // VERTEX_DEFORMATION_POINT_ALIGN_0
+
+#if defined(_VERTEX_DEFORMATION_POINT_ALIGN_1)
+#define VERTEX_DEFORM_POINT_ALIGN_1_PREAMBLE \
+ float3 po = _Vertex_Deformation_Point_Align_1_po; \
+ float3 pp = _Vertex_Deformation_Point_Align_1_pp; \
+ float3 r = _Vertex_Deformation_Point_Align_1_r; \
+ float t = _Vertex_Deformation_Point_Align_1_t
+#define VERTEX_DEFORM_POINT_ALIGN_1_POS \
objPos = point_align(objPos, po, pp, r, t)
-#define VERTEX_DEFORM_POINT_ALIGN_NORM \
+#define VERTEX_DEFORM_POINT_ALIGN_1_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
+#define VERTEX_DEFORM_POINT_ALIGN_1_PREAMBLE
+#define VERTEX_DEFORM_POINT_ALIGN_1_POS
+#define VERTEX_DEFORM_POINT_ALIGN_1_NORM
+#endif // VERTEX_DEFORMATION_POINT_ALIGN_1
#if defined(_VERTEX_DEFORMATION_PLANE_TO_TUBE_1)
#define VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE \
@@ -193,12 +209,16 @@ void deform(inout float3 objPos) {
// Plane to tube.
{
{
+ VERTEX_DEFORM_POINT_ALIGN_0_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_0_POS;
+ }
+ {
VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE;
VERTEX_DEFORM_PLANE_TO_TUBE_0_POS;
}
{
- VERTEX_DEFORM_POINT_ALIGN_PREAMBLE;
- VERTEX_DEFORM_POINT_ALIGN_POS;
+ VERTEX_DEFORM_POINT_ALIGN_1_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_1_POS;
}
{
VERTEX_DEFORM_PLANE_TO_TUBE_1_PREAMBLE;
@@ -221,34 +241,44 @@ void deform(inout float3 objPos) {
void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTan) {
const float t = getTime();
+ // Tube to plane.
{
- VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE;
- VERTEX_DEFORM_TUBE_TO_PLANE_0_NORM;
- }
- {
- VERTEX_DEFORM_AXIS_ALIGN_PREAMBLE;
- VERTEX_DEFORM_AXIS_ALIGN_NORM;
- }
- {
- VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE;
- VERTEX_DEFORM_TUBE_TO_PLANE_1_NORM;
+ {
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_0_NORM;
+ }
+ {
+ VERTEX_DEFORM_AXIS_ALIGN_PREAMBLE;
+ VERTEX_DEFORM_AXIS_ALIGN_NORM;
+ }
+ {
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_PREAMBLE;
+ VERTEX_DEFORM_TUBE_TO_PLANE_1_NORM;
+ }
}
// Here we're a plane.
{
VERTEX_DEFORM_FBM_PREAMBLE;
VERTEX_DEFORM_FBM_NORM;
}
+ // Plane to tube.
{
- VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE;
- 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;
+ {
+ VERTEX_DEFORM_POINT_ALIGN_0_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_0_NORM;
+ }
+ {
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_PREAMBLE;
+ VERTEX_DEFORM_PLANE_TO_TUBE_0_NORM;
+ }
+ {
+ VERTEX_DEFORM_POINT_ALIGN_1_PREAMBLE;
+ VERTEX_DEFORM_POINT_ALIGN_1_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 9ac88db..ed514fc 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -21,8 +21,9 @@
1.061025e-01 * sin(1.884956e+01*(x)) - \
7.957647e-02 * sin(2.513274e+01*(x))
-#define cubic(t) ((t) * (t) * (3.0 - 2.0 * (t)))
-#define d_cubic(t) (6.0f * (t) * (1.0f-(t)))
+// Quintic interpolation for C2 continuity (smoother derivatives)
+#define quintic(t) ((t) * (t) * (t) * ((t) * ((t) * 6.0f - 15.0f) + 10.0f))
+#define d_quintic(t) (30.0f * (t) * (t) * ((t) * ((t) - 2.0f) + 1.0f))
// Macros for transforming normal and tangent using autodiff.
// r3r3 refers to "r3 to r3 transform", aka a mapping between 3d real-valued
@@ -69,7 +70,7 @@
[Differentiable]
float3x3 inverse(no_diff float3x3 m, no_diff float det) {
- det = max(1e-6 * abs(det), abs(det)) * sign(det);
+ det = (det < 0.0f ? -1.0f : 1.0f) * max(1e-6f, abs(det));
float invDet = 1.0f / det;
float3x3 inv;
@@ -421,13 +422,13 @@ float3 value_noise(float3 xyz, out float3 dx, out float3 dy, out float3 dz) {
float3 cell = floor(xyz);
float3 f = xyz - cell;
- float ux = cubic(f.x);
- float uy = cubic(f.y);
- float uz = cubic(f.z);
+ float ux = quintic(f.x);
+ float uy = quintic(f.y);
+ float uz = quintic(f.z);
- float dux = d_cubic(f.x);
- float duy = d_cubic(f.y);
- float duz = d_cubic(f.z);
+ float dux = d_quintic(f.x);
+ float duy = d_quintic(f.y);
+ float duz = d_quintic(f.z);
float3 n000 = rand3_hash3(cell + float3(0.0f, 0.0f, 0.0f));
float3 n001 = rand3_hash3(cell + float3(0.0f, 0.0f, 1.0f));
@@ -535,7 +536,7 @@ public void fbm_normal(inout float3 xyz, inout float3 normal, inout float3 tange
dx.z, dy.z, dz.z);
float jac_det = determinant(jac);
float3x3 itjac = inverse(transpose(jac), jac_det);
- normal = mul(itjac, normal) * sign(jac_det);
+ normal = mul(itjac, normal) * jac_det;
tangent = mul(jac, tangent);
}
@@ -553,7 +554,7 @@ public void fbm_undeform_normal(float3 xyz, float t,
float jac_det = determinant(jac);
float3x3 inv_jac = inverse(jac, jac_det);
float3x3 trans_jac = transpose(jac);
- normal = mul(trans_jac, normal) * sign(jac_det);
+ normal = mul(trans_jac, normal) * jac_det;
tangent = mul(inv_jac, tangent);
}