diff options
| author | yum <yum.food.vr@gmail.com> | 2025-11-01 16:25:42 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-11-01 16:25:42 -0700 |
| commit | ea09e3e5425d935ed9dd277c0f1a7488033d2ede (patch) | |
| tree | 8b2009c59409cde4f8e00c96e4ff1536359b9d9f /ray_marching_maps.slang | |
| parent | 195df414b5310dec05d509dcc7d91b786419e360 (diff) | |
add l2 -> l infinity norm deformation
Diffstat (limited to 'ray_marching_maps.slang')
| -rw-r--r-- | ray_marching_maps.slang | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/ray_marching_maps.slang b/ray_marching_maps.slang index 87481a0..3c83a19 100644 --- a/ray_marching_maps.slang +++ b/ray_marching_maps.slang @@ -14,9 +14,9 @@ DifferentialPair<float3> dp_z = diffPair(xyz, float3(0, 0, 1)) #define R3R1_AUTODIFF_BASIS_VECTORS(fun, ...) \ - DifferentialPair<float> dp_x_out = fwd_diff(fun)(dp_x, ##__VA_ARGS__); \ - DifferentialPair<float> dp_y_out = fwd_diff(fun)(dp_y, ##__VA_ARGS__); \ - DifferentialPair<float> dp_z_out = fwd_diff(fun)(dp_z, ##__VA_ARGS__) + DifferentialPair<float> dp_x_out = fwd_diff(fun)(dp_x, __VA_ARGS__); \ + DifferentialPair<float> dp_y_out = fwd_diff(fun)(dp_y, __VA_ARGS__); \ + DifferentialPair<float> dp_z_out = fwd_diff(fun)(dp_z, __VA_ARGS__) #define R3R1_DEFORM_NORMAL_AND_TANGENT(normal, tangent) \ { \ @@ -29,29 +29,28 @@ // Syntactic sugar - wraps the previous three macros. #define R3R1_RAY_MARCH_NORMALS(xyz, normal, tangent, fun, ...) \ R3R1_DECLARE_BASIS_VECTORS(xyz); \ - R3R1_AUTODIFF_BASIS_VECTORS(fun, ##__VA_ARGS__); \ + R3R1_AUTODIFF_BASIS_VECTORS(fun, __VA_ARGS__); \ R3R1_DEFORM_NORMAL_AND_TANGENT(normal, tangent) // Just trace a sphere of radius 0.1 for now. [Differentiable] -public float map(float3 p) { - float3 count = float3(20,20,1); - float3 period = 0.05f; +public float map_ball_grid(float3 p, no_diff float3 count) { + float3 period = 1.0f / count; + period *= 2; float3 half_period = period*0.5f; - float3 which = abs(floor((p + half_period) / period)); - if (any(abs(which) >= count)) { + float3 which = floor((p + half_period) / period); + if (any(abs(which) > count/2)) { p = 1e6; } else { p = glsl_mod(p + half_period, period) - half_period; } - p.z += half_period.x; return length(p) - half_period.x; } -public void map_normal(inout float3 xyz, inout float3 normal, +public void map_ball_grid_normal(float3 count, inout float3 xyz, inout float3 normal, inout float3 tangent) { - R3R1_RAY_MARCH_NORMALS(xyz, normal, tangent, map); + R3R1_RAY_MARCH_NORMALS(xyz, normal, tangent, map_ball_grid, count); } #endif // __RAY_MARCHING_MAPS_INC |
