working game of life
This commit is contained in:
parent
136e02a692
commit
c582fd133c
13
shaders.hpp
13
shaders.hpp
@ -19,11 +19,18 @@ int alive(ivec2 uv){
|
||||
return int(px.r > 0.5);
|
||||
}
|
||||
|
||||
void main() {
|
||||
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));
|
||||
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";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user