diff options
| author | yum <yum.food.vr@gmail.com> | 2026-02-16 16:32:00 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-02-16 16:36:24 -0800 |
| commit | 864c2ba12dc864d9cb55cb797ba8919bee5b5913 (patch) | |
| tree | aa6cd98a71e4ef05d23f762127d3759a4a3e3e21 /vertex_deformation.slang | |
| parent | 6504b2c4631bab477838548167b88c1052eac263 (diff) | |
Add instancing distance culling, scale deformation
* GPU instance distance culling now takes a min/max range
* Fold recovers ops from material, allowing state to persist across
editor restarts
* Add scale node to vertex deformation framework
* Remove fold presets - dumb LLM idea, unused
* Drop more "undeform" code; unused, was for ray marching, which does
not work well
* Fix reflection energy compensation; was using cloth math, which makes
things too bright
Diffstat (limited to 'vertex_deformation.slang')
| -rwxr-xr-x | vertex_deformation.slang | 103 |
1 files changed, 11 insertions, 92 deletions
diff --git a/vertex_deformation.slang b/vertex_deformation.slang index 1cb002f..0c25d76 100755 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -53,18 +53,6 @@ normal = mul(itjac, normal) * jac_det; \ tangent = mul(jacobian, tangent) * jac_det -#define R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent) \ - float3x3 jacobian = float3x3( \ - float3(dp_x_out.d.x, dp_y_out.d.x, dp_z_out.d.x), \ - float3(dp_x_out.d.y, dp_y_out.d.y, dp_z_out.d.y), \ - float3(dp_x_out.d.z, dp_y_out.d.z, dp_z_out.d.z) \ - ); \ - float jac_det = determinant(jacobian); \ - float3x3 inv_jac = inverse(jacobian, jac_det); \ - float3x3 trans_jac = transpose(jacobian); \ - normal = mul(trans_jac, normal) * jac_det; \ - tangent = mul(inv_jac, tangent) * jac_det - // Syntactic sugar - wraps the previous three macros. #define R3R3_NORMALS(xyz, normal, tangent, fun, ...) \ R3R3_DECLARE_BASIS_VECTORS(xyz); \ @@ -111,7 +99,7 @@ public float3 plane_to_tube(float3 xyz, s_cart = normalize(s_cart); float3 rxs_cart = cross(s_cart, r_cart); float3x3 to_rsrxs = float3x3(r_cart, s_cart, rxs_cart); - // Ivnerse of orthonormal matrix is just the transpose. + // Inverse of orthonormal matrix is just the transpose. float3x3 to_cart = transpose(to_rsrxs); // Translate origin to `p` then change into (r, s, r x s) basis. @@ -154,13 +142,6 @@ public void plane_to_tube_normal(inout float3 xyz, inout float3 normal, R3R3_NORMALS(xyz, normal, tangent, plane_to_tube, p, r, s, t); } -public void plane_to_tube_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float3 p, float3 r, float3 s, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(plane_to_tube, p, r, s, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - [Differentiable] public float3 axis_align(float3 xyz, no_diff float3 po, no_diff float3 pp, no_diff float3 r, no_diff float t) { const float3 xyz0 = xyz; @@ -206,13 +187,6 @@ public void axis_align_normal(inout float3 xyz, inout float3 normal, R3R3_NORMALS(xyz, normal, tangent, axis_align, po, pp, r, t); } -public void axis_align_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float3 po, float3 pp, float3 r, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(axis_align, po, pp, r, t); - 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] @@ -274,14 +248,6 @@ public void tube_to_plane_normal(inout float3 xyz, inout float3 normal, R3R3_NORMALS(xyz, normal, tangent, tube_to_plane, p, r, s, t); } -public void tube_to_plane_undeform_normal( - float3 xyz, inout float3 normal, inout float3 tangent, - float3 p, float3 r, float3 s, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(tube_to_plane, p, r, s, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - [Differentiable] public float3 point_align(float3 xyz, no_diff float3 po, no_diff float3 pp, no_diff float3 r, no_diff float t) { const float3 xyz0 = xyz; @@ -320,12 +286,6 @@ public void point_align_normal(inout float3 xyz, inout float3 normal, inout floa R3R3_NORMALS(xyz, normal, tangent, point_align, po, pp, r, t); } -public void point_align_undeform_normal(float3 xyz, inout float3 normal, inout float3 tangent, float3 po, float3 pp, float3 r, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(point_align, po, pp, r, 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; @@ -352,13 +312,6 @@ public void seal_normal(inout float3 xyz, inout float3 normal, R3R3_NORMALS(xyz, normal, tangent, seal, A, k, t); } -public void seal_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float A, float k, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(seal, A, k, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - [Differentiable] public float3 sine_wave(float3 xyz, no_diff float3 amplitude, @@ -375,14 +328,6 @@ public void sine_wave_normal(inout float3 xyz, inout float3 normal, inout float3 R3R3_NORMALS(xyz, normal, tangent, sine_wave, amplitude, direction, k, omega, t); } -public void sine_wave_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float3 amplitude, float3 direction, float3 k, - float3 omega, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(sine_wave, amplitude, direction, k, omega, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - [Differentiable] 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-4f; @@ -396,12 +341,6 @@ public void norm_conversion_normal(inout float3 xyz, inout float3 normal, inout R3R3_NORMALS(xyz, normal, tangent, norm_conversion, input_k, output_k, 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(norm_conversion, input_k, output_k, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - [Differentiable] float3 rand3_hash3(float3 p) { @@ -544,24 +483,6 @@ public void fbm_normal(inout float3 xyz, inout float3 normal, inout float3 tange tangent = mul(jac, tangent); } -public void fbm_undeform_normal(float3 xyz, float t, - float3 amplitude, float gain, float lacunarity, - float3 period, float octaves, float3 velocity, - inout float3 normal, inout float3 tangent) { - float3 dx, dy, dz; - fbm_with_derivatives(xyz, t, amplitude, gain, lacunarity, period, octaves, - velocity, dx, dy, dz); - float3x3 jac = float3x3( - dx.x, dy.x, dz.x, - dx.y, dy.y, dz.y, - dx.z, dy.z, dz.z); - float jac_det = determinant(jac); - float3x3 inv_jac = inverse(jac, jac_det); - float3x3 trans_jac = transpose(jac); - normal = mul(trans_jac, normal) * jac_det; - tangent = mul(inv_jac, tangent); -} - // Maps a plane to a hemi-octahedron (half octahedron). // Uses octahedral parameterization consistent with pbrt's OctahedralVector. // Input: plane on [-1,1]² in the (r, rxs) plane @@ -618,13 +539,6 @@ public void plane_to_hemi_octahedron_normal(inout float3 xyz, inout float3 norma R3R3_NORMALS(xyz, normal, tangent, plane_to_hemi_octahedron, p, r, s, t); } -public void plane_to_hemi_octahedron_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float3 p, float3 r, float3 s, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(plane_to_hemi_octahedron, p, r, s, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); -} - // Maps a hemi-octahedron to a plane (inverse of plane_to_hemi_octahedron). // Input: unit hemisphere with pole at +s direction // Output: plane on [-1,1]² in the (r, rxs) plane @@ -676,11 +590,16 @@ public void hemi_octahedron_to_plane_normal(inout float3 xyz, inout float3 norma R3R3_NORMALS(xyz, normal, tangent, hemi_octahedron_to_plane, p, r, s, t); } -public void hemi_octahedron_to_plane_undeform_normal(float3 xyz, inout float3 normal, - inout float3 tangent, float3 p, float3 r, float3 s, float t) { - R3R3_DECLARE_BASIS_VECTORS(xyz); - R3R3_AUTODIFF_BASIS_VECTORS(hemi_octahedron_to_plane, p, r, s, t); - R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); +[Differentiable] +public float3 scale(float3 xyz, + no_diff float3 k, no_diff float t) { + return dlerp(xyz, xyz * k, t); +} + +public void scale_normal(inout float3 xyz, inout float3 normal, + inout float3 tangent, float3 k, float t) { + R3R3_NORMALS(xyz, normal, tangent, scale, k, t); } #endif // __CUSTOM31_INC + |
