A Repository of Real-time physics Simulations: GPU fluid simulation (2D/3D), Collision Detection, and Procedural Geometry.
- Overview
- Features
- Prerequisites
- Build (Windows)
- Run the programs
- From VS Code tasks
- From PowerShell (optional)
- Controls
- Project structure
- Performance notes
- Troubleshooting
- License
This suite projects that implement multiple simulation systems with modern OpenGL (core profile) and compute shaders for GPU-accelerated physics. It includes SPH-based fluid simulation (2D/3D), a particle collision system, and a small set of procedural geometry tools.
- GPU Fluid Simulation (2D/3D) using SPH + spatial hashing
- Particle Collision System with uniform grid partitioning
- Procedural geometry: parametric surfaces, polygons, spheres, and helpers
- Modern OpenGL 3.3+ rendering, OpenGL 4.3+ compute shaders
- GLM math, GLFW windowing/input, GLAD loader, optional Assimp model loading
- Windows 10/11, GPU with OpenGL 4.3+ recommended for compute shaders
- CMake 3.15+
- Visual Studio 2019/2022 (C++17)
- You must manually download and place third‑party dependencies; they are not shipped in this repo:
- GLFW 3.4 — headers and compiled library (find_package + link)
- Assimp — headers and compiled library + DLL (used by OpenGLProject)
- GLAD, GLM, stb_image — headers and GLAD source file
Expected header locations under this repo (manual copy):
includes/glad/(must containinclude/glad/glad.handsrc/glad.cper this CMake)includes/glm/(GLM headers)includes/stb_image.hincludes/assimp/include/(Assimp headers)- Optionally
includes/GLFW/if you want local GLFW headers; the library itself is located vialib/glfw3.
Choose ONE of the following setups before configuring/building.
Place compiled libraries and configs into this repo so CMake can find them via CMAKE_PREFIX_PATH and explicit link dirs:
Place headers under includes/ and compiled libraries under lib/ as follows.
-
GLFW 3.4 (required for all programs)
- Build from source with CMake (Visual Studio 2022 x64, Debug/Release)
- Install to:
<repo>/lib/glfw3- Must contain
lib/glfw3/lib/glfw3.libandlib/glfw3/lib/cmake/glfw3/GLFW3Config.cmake
- Must contain
- Headers: either install system‑wide or copy to
includes/GLFW/
-
Assimp (required for OpenGLProject executable)
- Build from source with CMake (Visual Studio 2022 x64)
- Install to:
<repo>/lib/assimp- Expected libs:
lib/assimp/lib/assimp-vc143-mt.lib,lib/assimp/lib/zlibstatic.lib - Expected DLL:
lib/assimp/bin/assimp-vc143-mt.dll(copied to runtime dir post‑build for OpenGLProject)
- Expected libs:
- Headers: copy to
includes/assimp/include/
-
GLAD, GLM, stb_image (headers only + GLAD source)
- GLAD: copy to
includes/glad/and ensureincludes/glad/src/glad.cexists (the CMake compiles it) - GLM: copy to
includes/glm/ - stb_image: place
includes/stb_image.h
- GLAD: copy to
Notes:
CMakeLists.txtsetsCMAKE_PREFIX_PATHtolib/glfw3andlib/assimpsofind_package(glfw3)works and Assimp libs are located.- If your filenames differ (toolset/version), adjust
CMakeLists.txtor rename the binaries to match.
- Install vcpkg and integrate with VS/VS Code
- Install packages:
vcpkg install glfw3:x64-windowsvcpkg install assimp:x64-windows
- Configure with vcpkg toolchain (manual configure example):
cmake -B build -S . -G "Visual Studio 17 2022" -A x64 `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET=x64-windowsYou can then build with the existing VS Code tasks or via Visual Studio.
All paths are relative to the repo root (tasks set the working directory accordingly).
- GPUFluidSim 2D
- OpenGL context: 4.3 Core (compute shaders)
- Window: 1200 x 800
- Default particles: 10,000
- Shaders:
SPHFluid/shaders/FluidSim-2D.compute,SPHFluid/shaders/particle2d.vs,SPHFluid/shaders/particle2d.fs - World bounds: x=[-10, 10], y=[-6.67, 6.67]
- GPUFluidSim 3D
- OpenGL context: 4.3 Core (compute shaders)
- Window: 1280 x 720
- Default particles: 10,000
- Shaders:
SPHFluid/shaders/FluidSim-3D.compute,SPHFluid/shaders/particle3d.vs,SPHFluid/shaders/particle3d.fs,SPHFluid/shaders/box.*,shaders/infinite_grid.* - Simulation bounds: axis‑aligned box of size 4 x 4 x 4
- CollisionSystem (2D)
- OpenGL context: 3.3 Core
- Window title: 1280 x 800 (Resizable)
- Auto‑spawning streams from the left edge; performance‑aware throttling
- Shaders:
shaders/vertex.vs,shaders/simple_fragment.fs
- OpenGLProject (main demo)
- OpenGL context: 3.3 Core
- Demonstrates geometry and basic rendering with an infinite grid
- Shaders:
shaders/vertex.vs,shaders/simple_fragment.fs,shaders/infinite_grid.*, optional normal debugshaders/normal_debug.*
Use the provided VS Code tasks (Terminal → Run Task…):
- CMake Configure (Windows) — generates the solution into
build/ - CMake Build (Windows) — builds all targets in Debug
- CMake Build Release (Windows) — builds in Release (optional)
Executables are written to output/Debug/ and output/Release/ (per configuration).
Tip: A Visual Studio solution is generated at build/OpenGLProject.sln if you prefer opening it directly in VS.
- Run GPUFluidSim 2D (Debug) → launches
GPUFluidSim2D.exe - Run GPUFluidSim 3D (Debug) → launches
GPUFluidSim3D.exe - Run Collision System 2D (Debug) → launches
CollisionSystem.exe - Run OpenGL Project (Debug) → launches
OpenGLProject.exe
Release variants are available for the main demo and collision system:
- Run OpenGL Project (Release)
- Run Collision System (Release)
Optional maintenance and alt build:
- Clean Build — removes build artifacts
- MinGW Build (Alternative) — experimental GCC build for quick checks
Note on shader paths: executables load shaders relative to the repo root (e.g., SPHFluid/shaders/...). Make sure your current directory is the project root (the VS Code tasks already do this).
Run these locally, after a successful build. One command per line.
# Navigate to the repo root (path contains spaces, so keep the quotes)
cd "c:\Users\dimai\Documents\Programming\Programming\Gravi Sim\OpenGL-C"
# Debug configuration binaries
.\output\Debug\GPUFluidSim2D.exe
.\output\Debug\GPUFluidSim3D.exe
.\output\Debug\CollisionSystem.exe
.\output\Debug\OpenGLProject.exe
# Release configuration binaries (after building Release)
.\output\Release\GPUFluidSim2D.exe
.\output\Release\GPUFluidSim3D.exe
.\output\Release\CollisionSystem.exe
.\output\Release\OpenGLProject.exeGPU Fluid Simulation (2D):
- Mouse move: interact with the fluid
- Left mouse: attract particles
- Right mouse: repel particles
- Space: pause/resume
- R: reset simulation
- ESC: exit
GPU Fluid Simulation (3D):
- WASD: move camera
- Shift: move down
- C: move up
- Mouse: look around (cursor disabled)
- Space: pause/resume
- R: reset simulation
- ESC: exit
Collision System (2D):
- Auto‑spawning particle streams from the left
- Right‑click or C: clear particles
- ESC: exit
Before configuring/building, confirm these paths exist (examples):
- Headers
includes/glad/include/glad/glad.hincludes/glad/src/glad.cincludes/glm/glm.hpp(GLM folder structure)includes/stb_image.hincludes/assimp/include/assimp/Importer.hpp- Optional:
includes/GLFW/glfw3.h
- Libraries
lib/glfw3/lib/cmake/glfw3/GLFW3Config.cmakelib/glfw3/lib/glfw3.liblib/assimp/lib/assimp-vc143-mt.liblib/assimp/lib/zlibstatic.liblib/assimp/bin/assimp-vc143-mt.dll(required at runtime for OpenGLProject)
├── SPHFluid/ # Fluid simulation (2D/3D) and compute shaders
│ ├── 2D/
│ ├── 3D/
│ └── shaders/
├── Collision System/ # Particle collision detection demo
├── geometry/ # Procedural geometry and helpers
├── shaders/ # Vertex/fragment shaders
├── models/ # Assets for the main demo
├── includes/ # Third‑party headers (GLFW, GLAD, GLM, stb, Assimp)
├── lib/ # Prebuilt libraries (GLFW, Assimp, etc.)
├── build/ # CMake build tree (generated)
└── output/ # Built executables (Debug/Release)
- 2D particles: 10k - 15k+ depending on GPU and Window size at 144fps
- 3D particles: 50k - 60k+ at 60fps
- Memory: ~100–200 MB for common presets
- Dedicated GPU strongly recommended for 3D + compute
Black screen or no motion:
- Verify GPU and drivers support OpenGL 4.3+ for compute shaders
- Try the Release build for performance-sensitive paths
Slow performance:
- Reduce particle count and grid resolution in the simulation
Build errors on Windows:
- Ensure CMake and Visual Studio are installed and on PATH
- Use the provided VS Code tasks to avoid environment conflicts
Missing DLLs:
- Visual C++ Redistributable may be required for some systems
SPH Techniques for the Physics Based Simulation of Fluids and Solids
This project is provided for educational and research purposes. Third‑party libraries retain their respective licenses.


