Skip to content

Commit 2b93ab5

Browse files
committed
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`
1 parent 71368d4 commit 2b93ab5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

assets/shaders/game_of_life.wgsl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ fn hash(value: u32) -> u32 {
1111
state = state * 2654435769u;
1212
return state;
1313
}
14+
1415
fn randomFloat(value: u32) -> f32 {
1516
return f32(hash(value)) / 4294967295.0;
1617
}
1718

1819
@compute @workgroup_size(8, 8, 1)
1920
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
2021
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
21-
let location_f32 = vec2<f32>(f32(invocation_id.x), f32(invocation_id.y));
2222

2323
let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x);
2424
let alive = randomNumber > 0.9;
@@ -27,7 +27,6 @@ fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_wo
2727
textureStore(texture, location, color);
2828
}
2929

30-
3130
fn is_alive(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
3231
let value: vec4<f32> = textureLoad(texture, location + vec2<i32>(offset_x, offset_y));
3332
return i32(value.x);
@@ -49,7 +48,6 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
4948
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
5049

5150
let n_alive = count_alive(location);
52-
let color = vec4<f32>(f32(n_alive) / 8.0);
5351

5452
var alive: bool;
5553
if (n_alive == 3) {
@@ -60,8 +58,9 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
6058
} else {
6159
alive = false;
6260
}
61+
let color = vec4<f32>(f32(alive));
6362

6463
storageBarrier();
6564

66-
textureStore(texture, location, vec4<f32>(f32(alive)));
65+
textureStore(texture, location, color);
6766
}

0 commit comments

Comments
 (0)