Compare commits

..

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

4 changed files with 36 additions and 50 deletions

View File

@ -12,11 +12,11 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
}
@fragment
fn on_fragment(in: Varying) -> @location(0) vec4u {
fn on_fragment(in: Varying) -> @location(0) u32 {
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 vec4(rand >> 31, rand >> 30, rand >> 29, rand >> 28) & vec4(1u);
return rand >> 31;
}
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::Rgba8Uint,
format: wgpu::TextureFormat::R8Uint,
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::Rgba8Uint,
format: wgpu::TextureFormat::R8Uint,
blend: None,
write_mask: wgpu::ColorWrites::ALL,
})],
@ -122,6 +122,17 @@ fn main() {
cache: None,
});
let state_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
label: None,
address_mode_u: wgpu::AddressMode::Repeat,
address_mode_v: wgpu::AddressMode::Repeat,
address_mode_w: wgpu::AddressMode::Repeat,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
..Default::default()
});
let mut state = None;
#[allow(deprecated)]
event_loop
@ -155,7 +166,7 @@ fn main() {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Uint,
format: wgpu::TextureFormat::R8Uint,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
})
@ -242,10 +253,16 @@ fn main() {
&device.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
layout: &step_pipeline.get_bind_group_layout(0),
entries: &[wgpu::BindGroupEntry {
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(&state.last),
}],
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::Sampler(&state_sampler),
},
],
}),
&[],
);

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).xy;
return vec4(vec2f(state), 0., 1.);
let state = textureLoad(field, pos, 0).x;
return vec4f(f32(state));
}

View File

@ -12,50 +12,19 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
}
@group(0) @binding(0) var field: texture_2d<u32>;
@group(0) @binding(1) var smp: sampler;
@fragment
fn on_fragment(in: Varying) -> @location(0) vec4u {
let dim = vec2i(textureDimensions(field));
let center = vec2i(in.screen.xy);
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;
}
}
let state = nb[1][1];
var n = vec4u();
for (var j = 0; j < 3; j++) {
for (var i = 0; i < 3; i++) {
n += nb[i][j];
}
}
n -= state;
let z = daynight(state.z, n.z);
let x = life(state.x, n.x + n.z);
let y = life(state.y, n.y + 8u - n.x);
return vec4(x, y, z, 0u);
}
fn life(state: u32, n: u32) -> u32{
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 state = a.y;
let n = a.x + a.z + a.w + b.x + b.y + c.y + c.z + d.y;
switch (n) {
case 2u: { return state; }
case 3u: { return 1u; }
default: { return 0u; }
}
}
fn daynight(state: u32, n: u32) -> u32{
switch (n) {
case 3u: { return 1u; }
case 4u: { return state; }
case 6u: { return 1u; }
case 7u: { return 1u; }
case 8u: { return 1u; }
default: { return 0u; }
}
}