4 independent layers

This commit is contained in:
numzero 2025-01-11 16:06:38 +03:00
parent c25573db87
commit 79b63154d7
4 changed files with 15 additions and 11 deletions

View File

@ -12,11 +12,11 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
}
@fragment
fn on_fragment(in: Varying) -> @location(0) u32 {
fn on_fragment(in: Varying) -> @location(0) vec4u {
let x = bitcast<u32>(in.screen.x);
let y = bitcast<u32>(in.screen.y);
let rand = hash(hash(hash(SEED) ^ hash(x)) ^ hash(y));
return rand >> 31;
return vec4(rand >> 31, rand >> 30, rand >> 29, rand >> 28) & vec4(1u);
}
fn hash(key : u32) -> u32 {

View File

@ -47,7 +47,7 @@ fn main() {
entry_point: None,
compilation_options: wgpu::PipelineCompilationOptions::default(),
targets: &[Some(wgpu::ColorTargetState {
format: wgpu::TextureFormat::R8Uint,
format: wgpu::TextureFormat::Rgba8Uint,
blend: None,
write_mask: wgpu::ColorWrites::ALL,
})],
@ -80,7 +80,7 @@ fn main() {
entry_point: None,
compilation_options: wgpu::PipelineCompilationOptions::default(),
targets: &[Some(wgpu::ColorTargetState {
format: wgpu::TextureFormat::R8Uint,
format: wgpu::TextureFormat::Rgba8Uint,
blend: None,
write_mask: wgpu::ColorWrites::ALL,
})],
@ -155,7 +155,7 @@ fn main() {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::R8Uint,
format: wgpu::TextureFormat::Rgba8Uint,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
})

View File

@ -15,6 +15,6 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
@fragment
fn on_fragment(in: Varying) -> @location(0) vec4f {
let pos = vec2u(in.screen.xy);
let state = textureLoad(field, pos, 0).x;
return vec4f(f32(state));
let state = textureLoad(field, pos, 0).xyz;
return vec4(vec3f(state), 1.);
}

View File

@ -14,26 +14,30 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
@group(0) @binding(0) var field: texture_2d<u32>;
@fragment
fn on_fragment(in: Varying) -> @location(0) u32 {
fn on_fragment(in: Varying) -> @location(0) vec4u {
let dim = vec2i(textureDimensions(field));
let center = vec2i(in.screen.xy);
var nb: array<array<u32, 3>, 3>;
var nb: array<array<vec4u, 3>, 3>;
for (var j = 0; j < 3; j++) {
for (var i = 0; i < 3; i++) {
let off = vec2i(i, j);
let coords = (center + off + dim - 1) % dim;
let px = textureLoad(field, coords, 0);
nb[j][i] = px.x;
nb[j][i] = px;
}
}
let state = nb[1][1];
var n = 0u;
var n = vec4u();
for (var j = 0; j < 3; j++) {
for (var i = 0; i < 3; i++) {
n += nb[i][j];
}
}
n -= state;
return vec4(rule(state.x, n.x), rule(state.y, n.y), rule(state.z, n.z), rule(state.w, n.w));
}
fn rule(state: u32, n: u32) -> u32{
switch (n) {
case 3u: { return 1u; }
case 4u: { return state; }