Repository navigation
N·Body 2.0 — A Gravitational Symphony
A complete rewrite of the original N-Body demo: a real-time 3D gravity simulator for Windows, now driven by Direct3D 11 compute shaders with HDR bloom and a frosted-glass HUD — shipped as a single ~3 MB Native AOT executable.
🚀 Download & run
- Download
NBody-win-x64.exebelow. - Double-click it — no installer and no .NET runtime required.
Requirements: Windows 10 or later (x64) and a GPU supporting Direct3D 11 (feature level 11.0).
Starts fullscreen in a cinematic attract mode. Press
Escto quit, or start in a window withNBody-win-x64.exe --windowed.
✨ What's new in 2.0
35 scenarios in 7 categories
![]() |
![]() |
| Periodic three-body: Butterfly I | The real Solar System (JPL J2000) |
![]() |
![]() |
| Chaos: the butterfly effect | Protoplanetary disk with gap-carving planets |
- Galaxies: galaxy collision, Milky Way × Andromeda, and a self-gravitating spiral. Up to 65,536 particles simulated with O(N²) direct summation on the GPU (tiled HLSL compute shader, leapfrog). Dark-matter halos and dynamical friction let the galaxies actually merge.
- Periodic three-body: Figure-8, the Šuvakov–Dmitrašinović family (butterflies, moths, dragonfly, yin-yang, bumblebee, yarn…), Broucke, Hénon, and Lagrange.
- Choreographies: rigidly rotating rings of 4, 6 and 12 bodies, and a moonlet ring.
- Planetary systems: the real Solar System from JPL J2000 elements, the inner Solar System, and a circumbinary "Tatooine" system.
- Clusters & disks: Plummer globular cluster, cold collapse, and a protoplanetary disk.
- Chaos: two Pythagorean three-body systems whose initial conditions differ by 10⁻⁹, plus the Pythagorean problem itself.
- Sandbox:
Shift+ drag to launch new bodies; colliding bodies merge.
🔬 Physics core
- Platform-independent, AOT-compatible
Sdcb.NBodylibrary with a Structure-of-Arrays layout and SIMD + parallel force summation. - Plummer softening and four integrators: Leapfrog, Yoshida 4, RK4, and adaptive Dormand–Prince 5(4). Press
Ito cycle through them. - Live tracking of energy, momentum and angular momentum, with an energy-drift chart in the HUD.
🎨 Visuals
- Procedural starfield and nebula, HDR rendering, physically-inspired bloom, and ACES tonemapping.
- Fading GPU trails, stars with coronas and diffraction spikes, lit planets with atmospheres, and black holes with Doppler-beamed accretion disks.
🎧 Experience
- Cinematic attract mode on launch, with an automatic camera and a scenario carousel.
- Scenario gallery drawer (
G) and a responsive HUD that adapts to small windows. - Bilingual English / 中文 UI, switchable at runtime (
L). - Procedurally synthesized ambient soundtrack with no audio assets (
Mto mute). F12screenshots saved toPictures\N-Body.- Automatic quality tiers per GPU; override with
NBODY_QUALITY=ultra|high|medium|low.
🛠 Engineering
- Native Win32 window with no WinForms dependency, built on .NET 10 and Vortice (Direct3D 11 / Direct2D / XAudio2).
- Native AOT single-file exe (~3 MB).
- xUnit tests covering conservation laws, periodic-orbit regressions and scenario sanity checks, plus GitHub Actions CI.
⌨️ Controls
| Input | Action |
|---|---|
| Left drag | Orbit camera |
| Right / middle drag | Pan |
| Wheel | Zoom |
| Double-click a body | Follow |
Space |
Pause |
← → |
Previous / next scenario |
↑ ↓ |
Faster / slower |
G |
Scenario gallery |
I |
Cycle integrator |
T |
Toggle trails |
R |
Reset |
F |
Re-frame camera |
Tab |
Hide HUD |
L |
中文 / English |
M |
Mute |
F11 |
Fullscreen |
F12 |
Screenshot |
H |
Help |
Esc |
Quit |
Command-line options
--windowed start in a window
--scenario <id> start directly in a scenario (e.g. galaxy-collision, figure-8)
--capture <file.png> render to a PNG after --capture-at seconds, then exit
--check-shaders compile every shader and report errors
N·Body 1.0 was the original, much more primitive demo written years ago. Version 2.0 is a ground-up rebuild.
Full Changelog: https://github.com/sdcb/n-body/commits/v2.0.0





