summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-04-13 23:13:16 -0700
committeryum <yum.food.vr@gmail.com>2026-04-13 23:13:16 -0700
commit07f8f3db17354c3e77aa9cb67338d451de6572d3 (patch)
treed526eef93d3091ace08fd12d5a3a0b9737cad0c6
parent2791567370385c9c8d7a5aeaa64c4588346e1779 (diff)
zebra: pull in phacelle noiseHEADmaster
-rwxr-xr-x3ner.shader2
-rwxr-xr-xglobals.cginc2
-rwxr-xr-xmath.cginc54
-rwxr-xr-xpbr.cginc14
4 files changed, 62 insertions, 10 deletions
diff --git a/3ner.shader b/3ner.shader
index 47fee80..9b93615 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -966,6 +966,8 @@ Shader "yum_food/3ner"
[HideInInspector] m_start_Zebra("Zebra", Float) = 0
[ThryToggle(_ZEBRA)] _Zebra_Enabled("Enable", Float) = 0
_Zebra_Scale("Scale", Float) = 1
+ _Zebra_Angle("Angle", Range(0, 1)) = 0
+ _Zebra_X_Scale("X Scale", Range(0, 1)) = 1
[HideInInspector] m_end_Zebra("Zebra", Float) = 0
//endex
diff --git a/globals.cginc b/globals.cginc
index 97b8d1d..b75eac6 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -207,6 +207,8 @@ float _Aperiodic_Tiling_Normal_Thickness;
#if defined(_ZEBRA)
float _Zebra_Scale;
+float _Zebra_Angle;
+float _Zebra_X_Scale;
#endif // _ZEBRA
#if defined(_CUSTOM31_WORLD)
diff --git a/math.cginc b/math.cginc
index 514d21f..0692440 100755
--- a/math.cginc
+++ b/math.cginc
@@ -110,7 +110,6 @@ float3 round_hex(float3 hex_coord) {
float3 blendNormalsHill12(float3 n0, float3 n1) {
n0.z += 1.0;
n1.xy = -n1.xy;
-
return normalize(n0 * dot(n0, n1) - n1 * n0.z);
}
@@ -213,19 +212,21 @@ float3 domain_warp_3d_tex(Texture3D noise_tex, SamplerState s, float3 uvw,
return noise;
}
-// Return distance to the nearest voronoi cell edge, clamped to [0, 0.5].
-// 0.5 is on the edge, 0 is far from it.
-float voronoi_d_2d(float2 x) {
+// Return distance to the nearest voronoi cell edge. Also returns p1 and p2,
+// vectors from the x to the nearest 2 lattice points, and p1_id, an identifier
+// for p1 which does not within the current cell.
+float voronoi_d_2d(float2 x, out float2 p1, out float2 p2, out float2 p1_id) {
float2 x_floor = floor(x);
float2 x_frac = frac(x);
float d1 = 1e6;
float d2 = 1e6;
- float2 p1 = 0;
- float2 p2 = 0;
+ p1 = 0;
+ p2 = 0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
float2 cell_offset = float2(i, j);
+ // Radial vector from origin lattice point to current.
float2 r = cell_offset + hash22_fast(x_floor + cell_offset) - x_frac;
float d = dot(r, r);
if (d < d1) {
@@ -233,14 +234,51 @@ float voronoi_d_2d(float2 x) {
p2 = p1;
d1 = d;
p1 = r;
+ p1_id = x_floor + cell_offset;
} else if (d < d2) {
d2 = d;
p2 = r;
}
}
}
- float d = (d2 - d1) / (2.0f * max(1e-4, length(p2 - p1)));
- return max(0.0f, 0.5f - d);
+ return (d2 - d1);
+}
+
+// stripe_dir is the direction we want to draw stripes along. It must be
+// normalized.
+float4 phacelle_noise_2d(float2 x, float2 stripe_dir) {
+ float2 x_floor = floor(x);
+ float2 x_frac = frac(x);
+
+ float2 stripe_ortho = float2(-stripe_dir.y, stripe_dir.x) * TAU;
+
+ float2 vec = 0;
+ float normalization = 0;
+ for (int j = -1; j <= 2; j++) {
+ for (int i = -1; i <= 2; i++) {
+ float2 cell_offset = float2(i, j);
+ // Radial vector from origin lattice point to current.
+ float2 r = cell_offset + (hash22_fast(x_floor + cell_offset) - 0.5) * 0.5 - x_frac;
+ float d2 = dot(r, r);
+ // 0th cell is centered at 0.5.
+ float weight = max(0, exp(-2.0 * d2) - 0.01111);
+ normalization += weight;
+ float wave_input = dot(r, stripe_ortho);
+ // TODO what the fuck
+ // why is r not normalized
+ float vecs, vecc;
+ sincos(wave_input, vecs, vecc);
+ vec += float2(vecc, vecs) * weight;
+ }
+ }
+ vec /= normalization;
+ float magnitude = dot(vec, vec);
+ return float4(vec / magnitude, stripe_ortho);
+}
+
+float voronoi_d_2d(float2 x) {
+ float2 p1, p2, p1_id;
+ return voronoi_d_2d(x, p1, p2, p1_id);
}
// Return distance to the nearest voronoi cell edge, clamped to [0, 0.5].
diff --git a/pbr.cginc b/pbr.cginc
index facb8f5..29bcedb 100755
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -228,8 +228,18 @@ void apply_burley_tiling(inout Pbr pbr, inout float3 normal_tangent) {
void apply_zebra(float2 uv, inout float3 albedo) {
#if defined(_ZEBRA)
- float mask = 2.0f * voronoi_d_2d(uv * _Zebra_Scale);
- albedo = lerp(albedo, 0, mask);
+ //float theta = 0.25 * PI;
+ //float theta = _Time[1];
+ float theta = _Zebra_Angle * TAU;
+ uv.x *= _Zebra_X_Scale;
+ float st, ct;
+ sincos(theta, st, ct);
+ float4 phacelle = phacelle_noise_2d(uv * _Zebra_Scale, float2(ct, st));
+ float2 dir = phacelle.xy;
+ float2 ortho_dir = phacelle.zw;
+ float mask = dot(dir, float2(0, 1));
+ float mask_fw = fwidth(mask);
+ albedo = smoothstep(-mask_fw * 0.5, mask_fw * 0.5, mask);
#endif
}