Replace textureGathers with textureLoads
This commit is contained in:
parent
1ad22dbb35
commit
c25573db87
21
src/main.rs
21
src/main.rs
|
|
@ -122,17 +122,6 @@ 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
|
||||||
|
|
@ -253,16 +242,10 @@ 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: &[
|
entries: &[wgpu::BindGroupEntry {
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 0,
|
binding: 0,
|
||||||
resource: wgpu::BindingResource::TextureView(&state.last),
|
resource: wgpu::BindingResource::TextureView(&state.last),
|
||||||
},
|
}],
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 1,
|
|
||||||
resource: wgpu::BindingResource::Sampler(&state_sampler),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
&[],
|
&[],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,28 @@ 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) u32 {
|
fn on_fragment(in: Varying) -> @location(0) u32 {
|
||||||
let a = textureGather(0, field, smp, in.uv, vec2(0, 0));
|
let dim = vec2i(textureDimensions(field));
|
||||||
let b = textureGather(0, field, smp, in.uv, vec2(0, 1));
|
let center = vec2i(in.screen.xy);
|
||||||
let c = textureGather(0, field, smp, in.uv, vec2(1, 0));
|
var nb: array<array<u32, 3>, 3>;
|
||||||
let d = textureGather(0, field, smp, in.uv, vec2(1, 1));
|
for (var j = 0; j < 3; j++) {
|
||||||
let state = a.y;
|
for (var i = 0; i < 3; i++) {
|
||||||
let n = a.x + a.z + a.w + b.x + b.y + c.y + c.z + d.y;
|
let off = vec2i(i, j);
|
||||||
|
let coords = (center + off + dim - 1) % dim;
|
||||||
|
let px = textureLoad(field, coords, 0);
|
||||||
|
nb[j][i] = px.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let state = nb[1][1];
|
||||||
|
var n = 0u;
|
||||||
|
for (var j = 0; j < 3; j++) {
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
n += nb[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n -= state;
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 3u: { return 1u; }
|
case 3u: { return 1u; }
|
||||||
case 4u: { return state; }
|
case 4u: { return state; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user