diff options
| author | yum <yum.food.vr@gmail.com> | 2025-10-31 15:40:20 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-10-31 15:40:20 -0700 |
| commit | 2edd7a2333ebc36f19f8726cb2d2f79aa501cb18 (patch) | |
| tree | ae34b5707ca07d9c2b78d41fb6190a99cb7ab875 /ray_marching_maps.slang | |
| parent | 15f9778a65a0f163627bd229b8f212cc5c7c0c22 (diff) | |
begin sketching out "undeform" codepath
Diffstat (limited to 'ray_marching_maps.slang')
| -rw-r--r-- | ray_marching_maps.slang | 40 |
1 files changed, 4 insertions, 36 deletions
diff --git a/ray_marching_maps.slang b/ray_marching_maps.slang index d98248b..649a557 100644 --- a/ray_marching_maps.slang +++ b/ray_marching_maps.slang @@ -31,51 +31,19 @@ R3R1_AUTODIFF_BASIS_VECTORS(fun, ##__VA_ARGS__); \ R3R1_DEFORM_NORMAL_AND_TANGENT(normal, tangent) -float distance_from_hex_comb( - float3 p, - float3 period, - float count) { - float3 p_hex = cart_to_hex(p.yz); - - float3 half_period = period * 0.5; - float3 which = abs(floor((p_hex + half_period) / period)); - - // The original code here was this: - // p_hex = glsl_mod(p_hex + half_period, period) - half_period; - // - // But you can simplify it. Given the definition of glsl_mod: - // #define glsl_mod(x,y) (((x)-(y)*floor((x)/(y)))) - // - // You can plug in terms: - // (p_hex + half_period) - (period) * floor((p_hex + half_period) / period) - // = p_hex + half_period - period * floor(p_hex/period + 0.5) - // - // For all x, - // round(x) = floor(x + 0.5) - // - // Continuing to simplify: - // (p_hex + half_period - period * round(p_hex/period)) - half_period - // = p_hex - period * round(p_hex / period) - p_hex = p_hex - period * round(p_hex / period); - - p.yz = hex_to_cart(p_hex); - - float hex_d = length(p) - 0.15; - return hex_d; -} - // Just trace a sphere of radius 0.1 for now. [Differentiable] public float map(float3 p) { - float period = 0.2f; - float3 count = float3(6,5,1); - float half_period = period * 0.5f; + float3 count = float3(5,5,1); + float3 period = 0.2f; + float3 half_period = period*0.5f; float3 which = abs(floor((p + half_period) / period)); if (any(abs(which) >= count)) { p = 1e6; } else { p = glsl_mod(p + half_period, period) - half_period; } + p.z += 0.1f; return length(p) - 0.1f; } |
