diff options
| author | yum <yum.food.vr@gmail.com> | 2025-11-02 09:19:50 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-11-02 09:19:50 -0800 |
| commit | 93f27e3a8545fef6ccc293d033e5f422ed821215 (patch) | |
| tree | 0aa80b3bbd40e9fa8c7ffbddeb523df46c90002a /vertex_deformation.slang | |
| parent | ea09e3e5425d935ed9dd277c0f1a7488033d2ede (diff) | |
generalize norm conversion code
Diffstat (limited to 'vertex_deformation.slang')
| -rw-r--r-- | vertex_deformation.slang | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/vertex_deformation.slang b/vertex_deformation.slang index 5337e8a..1af5ec9 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -171,25 +171,22 @@ public void sine_wave_undeform_normal(float3 xyz, inout float3 normal, R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); } -// Map from l2 (euclidean) norm to l-infinity (supremum, max) norm. [Differentiable] -public float3 l2_to_linf(float3 xyz, no_diff float t) { - float l2 = length(xyz); - float3 abs_xyz = abs(xyz); - float linf = max(abs_xyz.x, max(abs_xyz.y, abs_xyz.z)); - - float scale = lerp(1.0f, linf / l2, t); - +public float3 norm_conversion(float3 xyz, no_diff float input_k, no_diff float output_k, no_diff float t) { + float3 xyz_abs = abs(xyz)+1e-3f; + float lin = pow(pow(xyz_abs.x, input_k) + pow(xyz_abs.y, input_k) + pow(xyz_abs.z, input_k), 1.0f / input_k); + float lout = pow(pow(xyz_abs.x, output_k) + pow(xyz_abs.y, output_k) + pow(xyz_abs.z, output_k), 1.0f / output_k); + float scale = lerp(1.0f, lout / lin, t); return xyz * scale; } -public void l2_to_linf_normal(float3 xyz, inout float3 normal, inout float3 tangent, float t) { - R3R3_NORMALS(xyz, normal, tangent, l2_to_linf, t); +public void norm_conversion_normal(inout float3 xyz, inout float3 normal, inout float3 tangent, float input_k, float output_k, float t) { + R3R3_NORMALS(xyz, normal, tangent, norm_conversion, input_k, output_k, t); } -public void l2_to_linf_undeform_normal(float3 xyz, inout float3 normal, inout float3 tangent, float t) { +public void norm_conversion_undeform_normal(float3 xyz, inout float3 normal, inout float3 tangent, float input_k, float output_k, float t) { R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(l2_to_linf, t); + R3R3_AUTODIFF_BASIS_VECTORS(norm_conversion, input_k, output_k, t); R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); } @@ -200,7 +197,7 @@ float3 rand3_hash3(float3 p) p = float3(dot(p, float3(127.1, 311.7, 74.7)), dot(p, float3(269.5, 183.3, 246.1)), dot(p, float3(113.5, 271.9, 124.6))); - return frac(sin(p) * 43758.5453123); + return frac(sin(p) * 43758.5453123)*2-1; } [Differentiable] |
