diff options
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] |
