summaryrefslogtreecommitdiffstats
path: root/vertex_deformation.slang
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 /vertex_deformation.slang
parentf7c5e546c220f0f7be8ec3a9cccdb4641114cfe1 (diff)
more vertex deformation tweaks; unwrapping the donut
Diffstat (limited to 'vertex_deformation.slang')
-rw-r--r--vertex_deformation.slang23
1 files changed, 12 insertions, 11 deletions
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);
}