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