Skip to content

N·Body 2.0 — A Gravitational Symphony

Latest

Choose a tag to compare

@sdcb sdcb released this 21 Oct 08:59
· 1 commit to master since this release

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.

Galaxy collision

🚀 Download & run

  1. Download NBody-win-x64.exe below.
  2. 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 Esc to quit, or start in a window with NBody-win-x64.exe --windowed.

✨ What's new in 2.0

35 scenarios in 7 categories

Butterfly I Solar system
Periodic three-body: Butterfly I The real Solar System (JPL J2000)
Butterfly effect Protoplanetary disk
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.NBody library 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 I to 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.

Ring of 6

🎧 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 (M to mute).
  • F12 screenshots saved to Pictures\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