mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Remove unused code in game of life shader (#5349)
# Objective - Make `game_of_life.wgsl` easier to read and understand ## Solution - Remove unused code in the shader - `location_f32` was unused in `init` - `color` was unused in `update`
This commit is contained in:
parent
71368d4ebe
commit
2b93ab5812
1 changed files with 3 additions and 4 deletions
|
@ -11,6 +11,7 @@ fn hash(value: u32) -> u32 {
|
||||||
state = state * 2654435769u;
|
state = state * 2654435769u;
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn randomFloat(value: u32) -> f32 {
|
fn randomFloat(value: u32) -> f32 {
|
||||||
return f32(hash(value)) / 4294967295.0;
|
return f32(hash(value)) / 4294967295.0;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +19,6 @@ fn randomFloat(value: u32) -> f32 {
|
||||||
@compute @workgroup_size(8, 8, 1)
|
@compute @workgroup_size(8, 8, 1)
|
||||||
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
|
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
|
||||||
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
||||||
let location_f32 = vec2<f32>(f32(invocation_id.x), f32(invocation_id.y));
|
|
||||||
|
|
||||||
let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x);
|
let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x);
|
||||||
let alive = randomNumber > 0.9;
|
let alive = randomNumber > 0.9;
|
||||||
|
@ -27,7 +27,6 @@ fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_wo
|
||||||
textureStore(texture, location, color);
|
textureStore(texture, location, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn is_alive(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
|
fn is_alive(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
|
||||||
let value: vec4<f32> = textureLoad(texture, location + vec2<i32>(offset_x, offset_y));
|
let value: vec4<f32> = textureLoad(texture, location + vec2<i32>(offset_x, offset_y));
|
||||||
return i32(value.x);
|
return i32(value.x);
|
||||||
|
@ -49,7 +48,6 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
|
||||||
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
||||||
|
|
||||||
let n_alive = count_alive(location);
|
let n_alive = count_alive(location);
|
||||||
let color = vec4<f32>(f32(n_alive) / 8.0);
|
|
||||||
|
|
||||||
var alive: bool;
|
var alive: bool;
|
||||||
if (n_alive == 3) {
|
if (n_alive == 3) {
|
||||||
|
@ -60,8 +58,9 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
|
||||||
} else {
|
} else {
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
|
let color = vec4<f32>(f32(alive));
|
||||||
|
|
||||||
storageBarrier();
|
storageBarrier();
|
||||||
|
|
||||||
textureStore(texture, location, vec4<f32>(f32(alive)));
|
textureStore(texture, location, color);
|
||||||
}
|
}
|
Loading…
Reference in a new issue