GLSL shader example
Conway’s Game of Life on the GPU
Each texel is a cell. Count eight neighbors and apply B3/S23. A fixed repeating glider seed makes initialization reproducible; the boundary clamps instead of wrapping.
Live example
Edit the code and the preview updates as you type.
What to observe
Conway’s Game of Life on the GPU.
Mechanism
Each texel is a cell. Count eight neighbors and apply B3/S23. A fixed repeating glider seed makes initialization reproducible; the boundary clamps instead of wrapping.
The controlling code
float alive=texture2D(u_cells,(floor(uv*80.)+.5)/u_resolution).r;c=mix(vec3(.02,.04,.1),vec3(.3,.95,.65),alive);
u_cells applies the eight-neighbor rules, and Fragment enlarges a portion of the state texture for display. Replace floor(uv*80.) with floor(uv*160.) in Fragment to show a larger area of the same cell state instead of changing the simulation rules.
Experiment
Pause and use Step to watch the repeated glider seed move through successive generations. In u_cells, change neighbors==3. to neighbors==4. to alter the birth rule; the original glider will no longer follow Conway's standard motion.
Debugging and cost
Each update reads the current cell and eight neighbors; its seed repeats every 32 texels via mod(floor(gl_FragCoord.xy),32.). Change 32. to 16. to pack more initial gliders into the target; the display still magnifies only the region chosen by floor(uv*80.).