GPU-accelerated fluid simulation and cellular automata Unity Package (UPM) providing core simulation systems for ink-based interactions.
InkTools provides high-performance, non-game-specific simulation components that power the Inkling ecosystem. Built as a Unity Package Manager (UPM) compatible library, it offers reusable fluid dynamics and cellular automata systems.
GPU fluids and cellular automata with compute shaders and C# bindings.
Packages/
└── com.inktools.sim/
├── package.json # Package manifest
├── Runtime/
│ ├── Compute/ # Compute shader infrastructure
│ │ ├── FluidSolver.compute # Navier-Stokes fluid solver
│ │ ├── CellularAutomata.compute
│ │ └── Common.hlsl # Shared HLSL definitions
│ └── Simulation/ # C# simulation framework
│ ├── FluidSimulation.cs
│ ├── CASystem.cs
│ ├── MaterialProperties.cs
│ └── ParticleData.cs
└── Editor/
└── Debug/ # Editor debugging tools
├── SimulationDebugger.cs
└── PerformanceProfiler.cs
- Stable Fluid Solver: Jos Stam's algorithm adapted for GPU
- Multi-Material Support: Different ink types with unique properties
- Deterministic Simulation: Reproducible results with fixed seeds
- Resolution Scaling: Adaptive quality from 256x256 to 2048x2048
- 5-Layer System: Chemistry, Metabolism, Structure, Information, Evolution
- GPU Parallel Updates: Compute shader based processing
- Rule Customization: JSON-based rule configuration
- State Serialization: Save/load simulation states
Unified data types for C#/HLSL interoperability:
ifloat(16-bit float)idouble(32-bit float)ishort(16-bit unsigned)
- Open Package Manager in Unity
- Click "+" → "Add package from disk..."
- Navigate to
InkTools/Packages/com.inktools.sim/package.json
Add to your project's Packages/manifest.json:
{
"dependencies": {
"com.inktools.sim": "file:../../InkTools/Packages/com.inktools.sim"
}
}Add to your depfile.yaml:
packages:
- name: com.inktools.sim
path: ../InkTools/Packages/com.inktools.simusing InkTools.Sim;
public class FluidDemo : MonoBehaviour
{
private FluidSimulation fluid;
void Start()
{
var config = new FluidConfig
{
Resolution = 512,
Viscosity = 0.0001f,
Diffusion = 0.00001f
};
fluid = new FluidSimulation(config);
fluid.Initialize();
}
void Update()
{
fluid.AddVelocity(Input.mousePosition, Vector2.up * 100);
fluid.Step(Time.deltaTime);
}
}using InkTools.Sim.CA;
public class CADemo : MonoBehaviour
{
private CASystem automata;
void Start()
{
automata = new CASystem(256, 256);
automata.LoadRules("biochemical_rules.json");
automata.Initialize();
}
void FixedUpdate()
{
automata.Update();
}
}- Simulation Budget: < 4ms per frame
- Memory Usage: < 100MB GPU memory
- Platform Support: Mobile (iOS/Android), Desktop, WebGPU
- Adaptive resolution based on device capabilities
- Compute shader LOD system
- Temporal caching for static regions
- Async GPU readback for data export
Main fluid dynamics controller.
public class FluidSimulation
{
public void Initialize();
public void Step(float deltaTime);
public void AddVelocity(Vector2 position, Vector2 force);
public void AddDensity(Vector2 position, float amount, MaterialType type);
public RenderTexture GetDensityTexture();
public RenderTexture GetVelocityTexture();
}Cellular automata engine.
public class CASystem
{
public void Initialize();
public void Update();
public void SetCell(int x, int y, CellState state);
public CellState GetCell(int x, int y);
public void LoadRules(string rulesPath);
}- Unity 2022.3 LTS or newer
- Compute shader support (SM 5.0+)
- Git LFS for binary assets
Run tests via Unity Test Runner:
Window → General → Test Runner → Run All
Enable debug overlays in Editor:
InkToolsDebug.EnableOverlay = true;
InkToolsDebug.ShowPerformanceStats = true;InkTools provides the foundational simulation layer (LOD 0) for Inkling:
- Data Generation: Export simulation textures for ML training
- Deterministic Replay: Reproducible simulations for dataset creation
- Performance Scaling: Automatic quality adjustment per device
- Shader Variants: Multiple rendering paths for different tiers
- Inkling: Main game implementation
- InkModel: ML training pipeline
- MagiUnityTools: Shared Unity utilities
- MagiUnityDependencyManager: Package management
- Jos Stam's "Stable Fluids" (SIGGRAPH 1999)
- GPU Gems fluid dynamics chapters
- Unity Compute Shader documentation
See LICENSE for details.