3D Cellular Automata on the GPU

Let’s say that I’m working on implementing cellular automata (like Conway’s Game of Life) on the GPU using compute shaders. (also, using DX11, not openGL, but that’s only half-relevant)

My question is more focused on data structures side of things. In particular, in order to do any sort of cellular automata, you need knowledge of your neighbouring cells.

Right now, I have a RWStructuredBuffer in my compute shader, to which (from c# in unity) I upload a list of points (arranged in the shape of a 3D cube). I can access points via the SV_DispatchThreadID index in the CS, and do shenanigans like apply velocities to each point etc.
alt text

But is this good practice when you want each cell to be able to know what its neighbours are? Doing index calculations to figure out what 1d index does a 3d-placed neighbour have, seems suboptimal.

Is there any way you could instead cast rays from each point and return its neighbour? That would be awesome because it would eliminate the need for a cubic “Grid” entirely, and save space (no more “empty”/unused points).

Cheers!

PS: I’m not very familiar with 3d textures, but they aren’t available in unity free; so I’d like to stay away from them if possible.

Just create a 3d array. In that case find the neighbours will be easy. Now the problem is how to simulate. There is two ways:
1)You can use only centered position in cell, just like particle is moving by only in integer numbers. Is is easy way.
2)The true hardcore: using floating numbers for coordinates in gridspace! I’am actually trying to do that in 2d space, but it is realy hard to make it stabilized. Idea: in one cell ypu can place maximum 4 particles, so one cell has information about 4 particles (if collision distance 1 and distance between cells also 1), you always know neighbours of each particle, because it is just closest cells (26 cells in 3d and 8 in 2d space)! Awesome! But how can i know their position in gridspace? By rounding. You have coordinates of particles and if you floor thouse coordinates you’ll get the cell, where they are. Sadly part of it is their position change. You have first position of particle, then you apply velocity and getting new position and if this position will different to its cell, so you overwriting free place of new cell, and erasing old (NOT DELETING). You can use position by x lower than 0 to set the place of cell empty, new variables in such a big array is too bad. I think that’s all what i can say.
Dynamic memory in videocard is not possible or it will by toooo slow. If you don’t want to use grid, then check particles each by each, there is no other way out.
The cool moment is that my second way to make particle system isn’t used by anyone, and if you make it you will be the first, because it works based on floating number coordinates, not integer.