This simulator implements a complete ecosystem on the GPU where cellular organisms compete for resources (organics and energy) distributed across a soil substrate. Organisms are guided by genetic programs encoded in 32-gene genomes, enabling complex behaviors like growth, migration, energy trading, and reproduction.

The entire simulation runs on the GPU via compute shaders, with only minimal CPU orchestration for UI, parameter adjustment, and async readback of statistics.

World Structure

Environment & Resources

The world is a continuous 2D grid containing two primary resources:

  • Soil Organics — Available through roots, decays through diffusion, represents plant matter and nutrients
  • Soil Energy — Available through antenna structures, produced by leaf photosynthesis, gradually diffuses across the landscape
  • Sunlight — Global parameter that boosts leaf production efficiency

Simulation Cycle

Each frame executes 12 sequential substeps:

  1. Energy Diffusion — Soil energy disperses across the grid (9-point averaging kernel)
  2. Leaf Production — Leaf cells convert available organics into cellular energy (photosynthesis-like process)
  3. Root Absorption — Root cells extract organics from soil and convert to energy; convert to wood if starving
  4. Antenna Absorption — Antenna cells extract energy from soil; convert to wood if source depleted
  5. Energy Rerouting — Cells establish energy transport channels with neighbors based on availability
  6. Energy Transport — Energy flows between connected cells along established channels
  7. Life Maintenance — All cells consume energy to stay alive
  8. Death Check — Cells die if energy depleted or local conditions become unfavorable
  9. Cell Death Processing — Dead cells spill resources back into soil; cleanup connections
  10. Seed Movement — Seed cells migrate if unattached; convert to sprouts upon maturation
  11. Decision Making — Sprout cells read their genome and select an action
  12. Action Execution — Execute the selected behavior (grow, move, eat, separate, etc.)

Cell Types & Behaviors

Cell Type Hierarchy

Each cell has a fundamental type that determines its role in the organism:

  • Leaf — Primary energy producer; absorbs light energy from abundant organics
  • Root — Resource harvester; extracts organics from soil substrate
  • Antenna — Energy collector; extracts soil energy for distribution
  • Wood — Structural support and energy conduit; inert but efficient at transport
  • Sprout — Active growth node; interprets genome and executes behaviors
  • Seed — Mobile reproduction unit; migrates before developing into sprout
  • Empty — No cell present; available for growth

Genetic System

Genome Structure

Each organism carries a 32-gene genome. Each gene encodes:

  • Growth directions — Which cell types to spawn in each relative direction
  • Conditions — Two environmental checks (resource abundance, obstacles, neighbor comparison, randomness)
  • Parameters — Thresholds and comparison values for conditions
  • Commands — Action to execute if conditions succeed (with fallback if they fail)
  • Gene transitions — Which gene becomes active next based on success/failure

Available Gene Conditions

  1. Organic vs. Energy — Check if soil has more organics than energy
  2. Obstacle detection — Test for neighbors blocking growth/move
  3. Resource comparison — Compare resource levels in neighboring cells
  4. Abundance checks — Local or regional resource availability
  5. Randomness — Probabilistic branching

Available Commands

Commands allow organisms to:

  • Grow — Spawn new cells in specified directions
  • Move — Relocate in the cell direction (single cells)
  • Rotate — Reorient the cell direction (single cells)
  • Extract — Harvest organics or energy from soil
  • Trade — Exchange resources with neighboring cells
  • Reproduce — Create seeds for dispersal
  • Consume — Eat nearby cells for quick energy
  • Separate — Break connections
  • Adapt — Transform into a seed to wait for better environment conditions
  • Attach — Attach to nearby organism to receive energy from it

Evolution & Mutation

Reproduction Strategy

When an organism creates an offspring (seed or sprout):

  1. Inherit the parent's genome or create a mutated copy (25% chance)
  2. Placement of offspring depends on available space and genetic program
  3. Initialization with modest energy; must survive on its own

Mutation Mechanism

When mutations occur, a random gene is selected and one of its properties is randomly modified:

  • Growth direction types shift
  • Condition thresholds adjust
  • Command sequences change
  • Gene transitions rewrite
  • Behavioral parameters drift

The combination of finite energy, spatial constraints, and random mutations drives continuous adaptation. Successful strategies persist; failed experiments die and are recycled into the soil.

Getting Started

Requirements

  • GPU supporting Compute Shaders (most modern GPUs)
  • HLSL/Compute Shader support in your graphics backend

Running the Simulation

  1. Use Space to pause/resume
  2. Use [1-4] to switch visualization modes
  3. Use [R] to restart with a fresh world
  4. Use brush tools to interact with the environment

Customization

  • Adjust sunlight intensity to change energy availability
  • Modify cell constants (growth cost, maintenance, diffusion rate) to tune difficulty
  • Adjust brush properties to control interaction magnitude

Source code with implementation details can be found here.

Published 1 day ago
StatusReleased
PlatformsHTML5
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
Authormeownsk
GenreSimulation
Made withUnity
TagsIdle, Pixel Art
ContentNo generative AI was used

Leave a comment

Log in with itch.io to leave a comment.