Compare commits

..

No commits in common. "multilayer" and "master" have entirely different histories.

3 changed files with 8 additions and 21 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 >> 24; return rand >> 31;
} }
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) / 255.); return vec4f(f32(state));
} }

View File

@ -16,25 +16,12 @@ 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 aa = textureGather(0, field, smp, in.uv, vec2(0, 0)); let a = textureGather(0, field, smp, in.uv, vec2(0, 0));
let ab = textureGather(0, field, smp, in.uv, vec2(0, 1)); let b = textureGather(0, field, smp, in.uv, vec2(0, 1));
let ba = textureGather(0, field, smp, in.uv, vec2(1, 0)); let c = textureGather(0, field, smp, in.uv, vec2(1, 0));
let bb = textureGather(0, field, smp, in.uv, vec2(1, 1)); let d = textureGather(0, field, smp, in.uv, vec2(1, 1));
let s = aa.y; let state = a.y;
let a = vec4(aa.xzw, bb.y); let n = a.x + a.z + a.w + b.x + b.y + c.y + c.z + d.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; }