diff options
| author | yum <yum.food.vr@gmail.com> | 2026-04-08 22:16:35 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-04-08 22:16:35 -0700 |
| commit | 34f3001c0ae2ac20ad02f02434a2e13c50c8b6d8 (patch) | |
| tree | d7babb9ad73910930eadb88e008524b84843315e | |
| parent | f8b7967fce24ac1678985f8e49288a1a3600ccae (diff) | |
add rotation to c31 hexagons
needs some cleanup but it's pretty efficient, at least
| -rw-r--r-- | custom31.cginc | 21 | ||||
| -rwxr-xr-x | math.cginc | 6 |
2 files changed, 19 insertions, 8 deletions
diff --git a/custom31.cginc b/custom31.cginc index f44d185..67ecb78 100644 --- a/custom31.cginc +++ b/custom31.cginc @@ -6,20 +6,25 @@ #include "math.cginc" #include "quilez.cginc" -float c31_map(float3 p) { +float c31_map(float3 p, float3 p_quant) { float2 hex_dim = float2(_Custom31_World_Hexagons_Tile_Radius, _Custom31_World_Hexagons_Tile_Thickness); + float3 axis_normal = normalize(hash33_fast(p_quant) * 2 - 1); + float theta = hash31_ff(p_quant) * TAU + _Time[1]; + float4 quat = get_quaternion(axis_normal, theta); + p = rotate_vector(p, quat); + return distance_from_hex_prism(p, hex_dim); } -float3 c31_normal(float3 p) { +float3 c31_normal(float3 p, float3 p_quant) { const float epsilon = 1e-3; const float3 xstep = float3(epsilon, 0, 0); - float d0 = c31_map(p); + float d0 = c31_map(p, p_quant); return normalize(float3( - c31_map(p + xstep.xyy) - d0, - c31_map(p + xstep.yxy) - d0, - c31_map(p + xstep.yyx) - d0)); + c31_map(p + xstep.xyy, p_quant) - d0, + c31_map(p + xstep.yxy, p_quant) - d0, + c31_map(p + xstep.yyx, p_quant) - d0)); } void apply_custom31_world(v2f i, inout Pbr pbr, inout float3 normal_tangent) { @@ -45,7 +50,7 @@ void apply_custom31_world(v2f i, inout Pbr pbr, inout float3 normal_tangent) { [loop] for (uint ii = 0; ii < _Custom31_World_Ray_March_Steps; ++ii) { float3 p = ro + rd * d_acc; - d = c31_map(p); + d = c31_map(p, h_rounded); d_acc += d; if (d < _Custom31_World_Ray_March_Min_Dist) { break; @@ -58,7 +63,7 @@ void apply_custom31_world(v2f i, inout Pbr pbr, inout float3 normal_tangent) { if (d < _Custom31_World_Ray_March_Min_Dist) { pbr.albedo.xyz = 1; - normal_tangent = c31_normal(ro + rd * d_acc); + normal_tangent = c31_normal(ro + rd * d_acc, h_rounded); } else { pbr.albedo.xyz = 0; } @@ -67,6 +67,12 @@ float3 rotate_vector(float3 v, float4 q) return v + q.w * t + cross(q.xyz, t); } +float4 get_quaternion(float3 axis_normal, float theta) { + float sint2, cost2; + sincos(theta*0.5, sint2, cost2); + return float4(axis_normal * sint2, cost2); +} + // Cartesian to packed cube hexagonal coordinates. // Stores (q + r, q, r), where the article's cube coordinates satisfy // q + r + s = 0 and s = -(q + r). |
