Cleaner layer handling code

This commit is contained in:
numzero 2025-01-11 02:46:07 +03:00
parent 33487a68b2
commit 308cc6c3c2

View File

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