From c582fd133c756d5fa5d9158c452ff7a47b524683 Mon Sep 17 00:00:00 2001 From: k Date: Sat, 3 May 2025 20:42:39 -0400 Subject: [PATCH] working game of life --- shaders.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/shaders.hpp b/shaders.hpp index 6c93406..87d5fc6 100644 --- a/shaders.hpp +++ b/shaders.hpp @@ -19,12 +19,19 @@ int alive(ivec2 uv){ return int(px.r > 0.5); } -void main() { - ivec2 uv = ivec2(gl_GlobalInvocationID.xy); +void main(){ + ivec2 uv = ivec2(gl_GlobalInvocationID.xy); + int state = alive(uv); + int cnt = 0; - vec4 c = texelFetch(srcTex,uv,0); - int newState = alive(uv-ivec2(1,1)); - imageStore(destTex, uv, vec4(newState, newState, newState, 1.0)); + for(int y = -1; y <= 1; ++y) + for(int x = -1; x <= 1; ++x){ + if(x == 0 && y == 0) continue; + cnt += alive((uv + ivec2(x,y))); + } + + int newState = ((state == 1 && (cnt == 2 || cnt == 3)) || (state == 0 && cnt == 3)) ? 1 : 0; + imageStore(destTex, uv, vec4(newState, newState, newState, 1.0)); } )glsl";