working game of life

This commit is contained in:
k 2025-05-03 20:42:39 -04:00
parent 136e02a692
commit c582fd133c

View File

@ -21,9 +21,16 @@ int alive(ivec2 uv){
void main(){ void main(){
ivec2 uv = ivec2(gl_GlobalInvocationID.xy); ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
int state = alive(uv);
int cnt = 0;
vec4 c = texelFetch(srcTex,uv,0); for(int y = -1; y <= 1; ++y)
int newState = alive(uv-ivec2(1,1)); 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)); imageStore(destTex, uv, vec4(newState, newState, newState, 1.0));
} }
)glsl"; )glsl";