3D Cellular Automata [WGPU/Rust]
3d Cellular Automata using WGPU in Rust running on the web.
Note: if the performance of the simulation is very bad (<5 FPS) you are likely not using hardware acceleration. I highly recommend enabling it to fully use the simulation or downloading it and running it natively.
- Orbit camera : WASD or arrow keys
- Zoom in/out : Q/E
- Reset camera : space
- Pause, resetting the cells, and toggling the cross section are available at the bottom of the bar on the right
- Color setting changes take affect immediately, but changes to the simulation rule requires them to be applied
What are cellular automata?
Cellular automata are discrete, abstract computational systems that have proved useful both as general models of complexity and as more specific representations of non-linear dynamics in a variety of scientific fields. Firstly, cellular automata are (typically) spatially and temporally discrete: they are composed of a finite or denumerable set of homogeneous, simple units, the atoms or cells. At each time unit, the cells instantiate one of a finite set of states. They evolve in parallel at discrete time steps, following state update functions or dynamical transition rules: the update of a cell state obtains by taking into account the states of cells in its local neighborhood (there are, therefore, no actions at a distance). Secondly, cellular automata are abstract: they can be specified in purely mathematical terms and physical structures can implement them. Thirdly, cellular automata are computational systems: they can compute functions and solve algorithmic problems. Despite functioning in a different way from traditional, Turing machine-like devices, cellular automata with suitable rules can emulate a universal Turing machine, and therefore compute, given Turing’s thesis, anything computable.
— Stanford Encyclopedia of Philosophy
What does the rule mean?
There are 4 rules: survival, spawn, state, and neighborhoods. A cell can be in one of 3 states: alive, dying, or dead.
- A list or single integer
- Example: [X, Y, ...]
- If a cell is alive, it will remain alive if it has X, Y, or ... neighbors (only applies to alive cells)
- If it does not have X, Y, or ... neighbors, it will begin dying
- A list or single integer
- Example: [X, Y, ...]
- Can have any amount of overlap with survival
- If a cell is dead, it will come alive if it has X, Y, or ... neighbors (only applies to dead cells)
- Must be a single integer
- Example: X
- Once a cell begins dying, it has X simulation/update ticks to live before disappearing
- Both survival and spawn rules will no longer affect the cell while it decays (only applies to dying cells)
- "Moore" or "Von Neumann"
- How neighbors are counted (applies to all cells)
- Neighbors are any cells where 1 away, including diagonals
- Think like a Rubik's cube where the current cell is the middle, all the outside/colored cubes are the neighbors
- 3^3 - 1 = 26 possible neighbors
- "Von Neumann":
- Neighbors are only cells where the faces touch
- 6 possible neighbors
Other setting options
- The cells on the edges of the simulation would have less neighbors
- If wrap neighborhood is enabled, those cells on the edges would also sample the cells on the opposite edge
- Now every cell as the exact same number of neighbors
- Allows certain moving shapes to move off the one side and continue moving from the other
- But it is a move expensive calculation, so on larger cell bounds the simulation will run a couple FPS slower
- There are (cell bounds)^3 total cells
- A higher cell bounds leads to a more complex simulation that is less like to become static, but the simulation runs faster on lower cell bounds
- Change the wrap neighborhood option to change how cells on the edge of the simulation behave
Dual Color Dying
- One color option: "Alive Color"
- Alive cells: "Alive Color"
- Dying cells: scales from white to black based on how close the cell is to dead
- Easiest to see the state/difference between alive and dead cells at the cost of your eyes
- One color option: "Start Color"
- Scales from "Start Color" to black based on how close the cell is to dead
- Alive cells: "Start Color"
- Basically dead cells: almost black
- Two color options: "Start Color" and "End Color"
- Displays the cell's state as a scale from color from "Start Color" to "End Color"
- If the cell is "Start Color," it is fully alive
- Anything else: the cell is dying
- Closer to "Start Color" : more time to live
- Closer to "End Color" : closer to dead
- No color option
- Maps the cell's position (X, Y, Z) to a color
- X * k = red intensity, Y * k = green, Z * k = blue
- This draw mode makes it easier to see each cell's position because its color is directly related to its position
- At the cost of not displaying the cell's state
- One color option: "Max Distance Color"
- A scale of how far each cell is from the center of the simulation from black to "Max Distance Color"
- Like RGB, it is easy to see the positions of the cells at the cost of not displaying the cell's state
- It is likely easier on the eyes than RGB, but there are cells that have the same color
Per vertex lighting
- It is normally hard to tell the cells apart
- Unless you are using RGB draw mode, there are many cells with the same color
- Per vertex lighting add a slight darkening to the corners of the vertices of the cells
- Gives them a slight outline making it a lot easier to tell the cells apart
- But it can ruin the clean/smooth look (especially the RGB draw mode)
For more information about cellular automata, I recommend reading these:
|Platforms||Windows, macOS, Linux, Android, HTML5|
|Tags||3D, automata, Automation, cellular, rust, wgpu|
|Code license||MIT License|
|Average session||A few minutes|
|Inputs||Keyboard, Mouse, Touchscreen, Smartphone|
|Accessibility||Color-blind friendly, High-contrast, One button, Textless|
|Links||Source code, YouTube|
Click download now to get access to the following files:
Leave a comment
Log in with itch.io to leave a comment.