diff --git a/src/fill.wgsl b/src/fill.wgsl index 0b31d8c..465abce 100644 --- a/src/fill.wgsl +++ b/src/fill.wgsl @@ -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(in.screen.x); let y = bitcast(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 { diff --git a/src/main.rs b/src/main.rs index 8cf4458..db3fc10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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: &[], }) diff --git a/src/present.wgsl b/src/present.wgsl index 656d55f..53a135a 100644 --- a/src/present.wgsl +++ b/src/present.wgsl @@ -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.); } diff --git a/src/step.wgsl b/src/step.wgsl index 70ae300..515aa78 100644 --- a/src/step.wgsl +++ b/src/step.wgsl @@ -14,26 +14,30 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying { @group(0) @binding(0) var field: texture_2d; @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, 3>; + var nb: array, 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; }