So, inspired by
redacted and @Andrew_Stacey, I decided to try using Stacey’s GameOfLifeshader to do something more complex.
And I failed!
To be fair, I think I succeeded in principle. My main frustration was that, using regular drawing tools and lua, in any simulation I tried to make the draw cycle would slow down drastically before I could get even a hundred organisms on screen. I wanted something that could have hundreds of organisms and be fast!
Since that’s just what Stacey’s GameOfLife shader does, I set out to hack it, and I have. Mostly.
I set up a system whereby the mechanic of Stacey’s GameOfLife shader can model more complex behavior. Here’s how it works:
Stacey’s system uses two different shaders; a game logic shader and a pretty-for-the-world shader. The game logic computes what happens each turn and the pretty shader makes it pretty colors.
In my version of the logic shader, the texture is broken into series of a 2-pixel-by-2-pixel grids. Each pixel is used to store different information:
V M D D V - visible color - this is the color the user will see in the visible shader M - movement data - this color tells the logic shader whether or not this grid is an organism, and what direction it will move D - these can hold different data, but I didn't get far enough to configure them to do anything
Right now the way it works is that the V pixel is the only one allowed to have any red in it at all, and the pretty shader just goes along, reading every 2x2 grid and looking for the pixel with red in it. Then it draws that color for all four of the positions. Right now the “ground” color is a green with 0.004 red in it, and it doesn’t look red at all. The obligation to have a little red doesn’t really constrain the possible color range.
The game logic cycle is all about the M pixel right now. Most of the 2x2 grids have no data in the M pixel, and they get drawn green. But when the logic encounters an M pixel with data, it puts a solid red color in the V position. So when you run the project you see red blocks moving against a green background.
Right now the M pixels only encode movement instructions, and only two kinds. The creatures can move left, and diagonally down and to the left. The whole thing works by a system where one kind of marker tells the logic where to draw the other kind of marker, and vice versa. So markerA says to the logic, “hey, put a markerB to the left of me,” and markerB says “hey, put a markerA down and to the left of me.”
Also right now: the world is 20 pixels by 20 pixels. I way enlarged it so I could see what was happening. But I believe it can scale up to thousands of pixels fairly easily.
It’s very primitive, though I think there’s lots of potential. I think I also ran up against my programming limitations because I’m sure someone else could do the same thing better in 1/2 the code. I would love it if anyone with better skills could make this work more efficiently and actually make the little critters do something cool.
It’s not much to look at right now, but with the help of some more capable programmers, it could be an awesome way to rapidly model life simulations with hundreds of organisms!
Here’s the code: