stackgl/shader-school — pull request #89 by mdda (2014-08-21 17:13:43+00:00)
Title: #24-gpgpu-1 : Game of Life fix

The 'ideal solution' is a really neat 'logic compression'. However, because the initial conditions are not {0,255}, it's almost impossible to write an explicit version that works.

The attached pull request changes the initial state to be {0,255} instead, so that the following kernel also works (boringly written, I know):

```
float state(vec2 coord) {
return texture2D(prevState, fract(coord / stateSize)).r;
}

void main() {
vec2 coord = gl_FragCoord.xy;

float count = state(coord+vec2(-1,-1)) + state(coord+vec2(-1, 0)) + state(coord+vec2(-1,+1)) +
state(coord+vec2( 0,-1)) + + state(coord+vec2( 0,+1)) +
state(coord+vec2(+1,-1)) + state(coord+vec2(+1, 0)) + state(coord+vec2(+1,+1));
float current = state(coord);

float s = (current==0.0 && count==3.0)?1.0:((current==1.0 && (count==2.0 || count==3.0))?1.0:0.0);

gl_FragColor = vec4(s,s,s, 1.0);
}
```

All the Best
Martin
:-)