Real-Time Physics Simulation

Feel the Flow.

A stunning real-time 2D fluid simulator powered by Smoothed Particle Hydrodynamics. Watch 5,000 particles dance under gravity, pressure, and viscosity — rendered as a beautiful continuous fluid with Phong lighting.

5,000 Particles
60 FPS Real-Time
8 Substeps / Frame
WaterSimulation.exe
Liquid Simulation — splashing water with Phong lighting

Physics That Feels Real

Every drop is simulated. Every wave is emergent. No shortcuts, no pre-baked animations.

SPH Physics Engine

Smoothed Particle Hydrodynamics with spatial hashing for O(1) neighbor lookups. Density, pressure, and viscosity forces create authentic fluid behavior.

Two-Pass Rendering

Gaussian splat pass creates a smooth density field, then a fluid pass extracts the surface with gradient-based normals and Phong lighting with specular highlights.

8

8 Substeps / Frame

Sub-frame physics stepping ensures rock-solid stability even with thousands of particles colliding and splashing in the container.

Interactive Controls

Push water with your mouse, spawn particles on the fly, and reset instantly. The simulation responds to your every move in real time.

OpenGL 3.3 Rendering

Hardware-accelerated rendering with off-screen framebuffers, additive blending, and shader-based surface extraction for buttery smooth visuals.

Lightweight & Fast

No bloated frameworks. Pure C++17 and OpenGL — boots in under a second and runs at 60 FPS on modest hardware. GLFW is the only dependency.

How The Magic Happens

Two elegant systems working in harmony to bring water to life.

01

Spatial Hashing

Particles are bucketed into a grid where each cell matches the smoothing radius. Neighbor lookups become O(1) instead of O(n²), making 5,000 particles feel effortless.

02

Density & Pressure

A Poly6 kernel estimates density from nearby particles. Pressure derives from density using a stiffness coefficient — only positive pressures are kept to prevent vacuum collapse.

03

Force Accumulation

Spiky gradient kernels create pressure forces that push particles apart. Viscosity forces via Laplacian kernels smooth velocity differences for that satisfying, realistic flow.

04

Two-Pass Render

Gaussian splats create a density field, then the fluid pass extracts the surface, computes normals from gradients, and applies Phong lighting with depth-based color shifts.

Easy Controls

LMB + Drag

Push water away from your cursor

F

Hold to spawn particles at cursor

R

Reset the entire simulation

Esc

Quit the application

Ready to Dive In?

Download the simulation and experience real-time fluid physics on your own machine. Free, open-source, and runs on any OpenGL 3.3 capable GPU.

Windows

Windows 10 / 11

Download .zip

Build From Source

Linux / macOS / Windows

View on GitHub

Requirements

OpenGL 3.3 C++17 CMake 3.20+ Windows / Linux / macOS