summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--custom31.cginc21
-rwxr-xr-xmath.cginc6
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;
}
diff --git a/math.cginc b/math.cginc
index 15d02eb..ee70495 100755
--- a/math.cginc
+++ b/math.cginc
@@ -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).