Compare commits
No commits in common. "interlayer" and "master" have entirely different histories.
interlayer
...
master
|
|
@ -12,11 +12,11 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
|
||||||
}
|
}
|
||||||
|
|
||||||
@fragment
|
@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 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 vec4(rand >> 31, rand >> 30, rand >> 29, rand >> 28) & vec4(1u);
|
return rand >> 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash(key : u32) -> u32 {
|
fn hash(key : u32) -> u32 {
|
||||||
|
|
|
||||||
31
src/main.rs
31
src/main.rs
|
|
@ -47,7 +47,7 @@ fn main() {
|
||||||
entry_point: None,
|
entry_point: None,
|
||||||
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
||||||
targets: &[Some(wgpu::ColorTargetState {
|
targets: &[Some(wgpu::ColorTargetState {
|
||||||
format: wgpu::TextureFormat::Rgba8Uint,
|
format: wgpu::TextureFormat::R8Uint,
|
||||||
blend: None,
|
blend: None,
|
||||||
write_mask: wgpu::ColorWrites::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
})],
|
})],
|
||||||
|
|
@ -80,7 +80,7 @@ fn main() {
|
||||||
entry_point: None,
|
entry_point: None,
|
||||||
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
||||||
targets: &[Some(wgpu::ColorTargetState {
|
targets: &[Some(wgpu::ColorTargetState {
|
||||||
format: wgpu::TextureFormat::Rgba8Uint,
|
format: wgpu::TextureFormat::R8Uint,
|
||||||
blend: None,
|
blend: None,
|
||||||
write_mask: wgpu::ColorWrites::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
})],
|
})],
|
||||||
|
|
@ -122,6 +122,17 @@ fn main() {
|
||||||
cache: None,
|
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;
|
let mut state = None;
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
event_loop
|
event_loop
|
||||||
|
|
@ -155,7 +166,7 @@ fn main() {
|
||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8Uint,
|
format: wgpu::TextureFormat::R8Uint,
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
view_formats: &[],
|
view_formats: &[],
|
||||||
})
|
})
|
||||||
|
|
@ -242,10 +253,16 @@ fn main() {
|
||||||
&device.create_bind_group(&wgpu::BindGroupDescriptor {
|
&device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
layout: &step_pipeline.get_bind_group_layout(0),
|
layout: &step_pipeline.get_bind_group_layout(0),
|
||||||
entries: &[wgpu::BindGroupEntry {
|
entries: &[
|
||||||
binding: 0,
|
wgpu::BindGroupEntry {
|
||||||
resource: wgpu::BindingResource::TextureView(&state.last),
|
binding: 0,
|
||||||
}],
|
resource: wgpu::BindingResource::TextureView(&state.last),
|
||||||
|
},
|
||||||
|
wgpu::BindGroupEntry {
|
||||||
|
binding: 1,
|
||||||
|
resource: wgpu::BindingResource::Sampler(&state_sampler),
|
||||||
|
},
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
&[],
|
&[],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,6 @@ fn on_vertex(@builtin(vertex_index) vi: u32) -> Varying {
|
||||||
@fragment
|
@fragment
|
||||||
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).xy;
|
let state = textureLoad(field, pos, 0).x;
|
||||||
return vec4(vec2f(state), 0., 1.);
|
return vec4f(f32(state));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(0) var field: texture_2d<u32>;
|
||||||
|
@group(0) @binding(1) var smp: sampler;
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn on_fragment(in: Varying) -> @location(0) vec4u {
|
fn on_fragment(in: Varying) -> @location(0) u32 {
|
||||||
let dim = vec2i(textureDimensions(field));
|
let a = textureGather(0, field, smp, in.uv, vec2(0, 0));
|
||||||
let center = vec2i(in.screen.xy);
|
let b = textureGather(0, field, smp, in.uv, vec2(0, 1));
|
||||||
var nb: array<array<vec4u, 3>, 3>;
|
let c = textureGather(0, field, smp, in.uv, vec2(1, 0));
|
||||||
for (var j = 0; j < 3; j++) {
|
let d = textureGather(0, field, smp, in.uv, vec2(1, 1));
|
||||||
for (var i = 0; i < 3; i++) {
|
let state = a.y;
|
||||||
let off = vec2i(i, j);
|
let n = a.x + a.z + a.w + b.x + b.y + c.y + c.z + d.y;
|
||||||
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{
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 2u: { return state; }
|
case 2u: { return state; }
|
||||||
case 3u: { return 1u; }
|
case 3u: { return 1u; }
|
||||||
default: { return 0u; }
|
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user