Compare commits

..

2 Commits

Author SHA1 Message Date
308cc6c3c2 Cleaner layer handling code 2025-01-11 02:46:07 +03:00
33487a68b2 Now it’s 8-layer life! 2025-01-11 02:41:07 +03:00
3 changed files with 21 additions and 8 deletions

View File

@ -16,7 +16,7 @@ fn on_fragment(in: Varying) -> @location(0) u32 {
let x = bitcast<u32>(in.screen.x); let x = bitcast<u32>(in.screen.x);
let y = bitcast<u32>(in.screen.y); let y = bitcast<u32>(in.screen.y);
let rand = hash(hash(hash(SEED) ^ hash(x)) ^ hash(y)); let rand = hash(hash(hash(SEED) ^ hash(x)) ^ hash(y));
return rand >> 31; return rand >> 24;
} }
fn hash(key : u32) -> u32 { fn hash(key : u32) -> u32 {

View File

@ -16,5 +16,5 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
fn on_fragment(in: Varying) -> @location(0) vec4f { fn on_fragment(in: Varying) -> @location(0) vec4f {
let pos = vec2u(in.screen.xy); let pos = vec2u(in.screen.xy);
let state = textureLoad(field, pos, 0).x; let state = textureLoad(field, pos, 0).x;
return vec4f(f32(state)); return vec4f(f32(state) / 255.);
} }

View File

@ -16,12 +16,25 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
@fragment @fragment
fn on_fragment(in: Varying) -> @location(0) u32 { fn on_fragment(in: Varying) -> @location(0) u32 {
let a = textureGather(0, field, smp, in.uv, vec2(0, 0)); let aa = textureGather(0, field, smp, in.uv, vec2(0, 0));
let b = textureGather(0, field, smp, in.uv, vec2(0, 1)); let ab = textureGather(0, field, smp, in.uv, vec2(0, 1));
let c = textureGather(0, field, smp, in.uv, vec2(1, 0)); let ba = textureGather(0, field, smp, in.uv, vec2(1, 0));
let d = textureGather(0, field, smp, in.uv, vec2(1, 1)); let bb = textureGather(0, field, smp, in.uv, vec2(1, 1));
let state = a.y; let s = aa.y;
let n = a.x + a.z + a.w + b.x + b.y + c.y + c.z + d.y; let a = vec4(aa.xzw, bb.y);
let b = vec4(ab.xy, ba.yz);
var ret = 0u;
for (var layer = 0u; layer < 8u; layer++) {
let s = s >> layer & 1u;
let a = a >> vec4(layer) & vec4(1u);
let b = b >> vec4(layer) & vec4(1u);
ret |= calc(s, a, b) << layer;
}
return ret;
}
fn calc(state: u32, a: vec4u, b: vec4u) -> u32 {
let n = dot(a, vec4(1u)) + dot(b, vec4(1u));
switch (n) { switch (n) {
case 2u: { return state; } case 2u: { return state; }
case 3u: { return 1u; } case 3u: { return 1u; }