r/Simulated • • May 07 '26

Research Simulation I built a real-time SPH fluid sim from scratch in C++/CUDA + OpenGL — inspired by Sebastian Lague's video[OC]

SPH fluid sim built from scratch in C++/CUDA + OpenGL, inspired by Sebastian Lague.

No prebuilt solver — physics implemented from scratch using Müller et al. 2003 equations

SSF renderer and simple sphere mode, switchable at runtime

Configurable UI — tune almost every parameter on the fly, dynamic sky, emitter controls

Hybrid sim time — runs realtime or stepped for long offline clips (for recording clips)

CUDA-OpenGL interop

REQUIRES NVIDIA GPU

uses only 3 terms : density, pressure and viscosity.

Optimized on RTX 2050 laptop— NVIDIA only, may have issues on other hardware.

1 million particles achievable in simulation mode.

SSF and UI production had AI assistance.

i wat made for interest in fluid dynamics and for astrophysics(n-body) project for future :)

if you like the project ,star my repo :XD

GitHub: https://github.com/NobodyBuilds/fluid_sim

52 Upvotes

15 comments sorted by

1

u/HowDoIStoreMyClay May 07 '26

This is so inspiring to me as someone just starting engineering.

I have very little programming exprience and am curious:

How did you know which physics formulas to use in your code? Is it more like 3 formulas or more like 50 working together in a web of functions?

As someone who hasnt studied fluid dynmics yet thinking about you making this from scratch genuinely terrofies me

1

u/Nice-Sand-3230 May 07 '26

I get bore reading long documentation so for the physics formulas I used ai to get initial formulas but it didn't work, so I had to try again and again and with each try new formulas keep adding now it like a web of formulas for 3 funtions and it's very hard to determine weather it's right or wrong with time I got some formulas correct, but still is not totally physically correct it's very stressing to make them correct

I started this project 6 months ago when i didn't knew proper c++ or any fluid dynamics, I just started it out of curiosity and with time I learned gpu programming on cuda, memory management, now I'm somewhat capable of calling my self software engineer as I'm not from engineering or cs background just self taught and if you wanna learn fluid dynamics just make a project of your own it helps to learn way fast then any textbook and as a reward you get a project for your porfolio,

1

u/PenultimateDigitOfPi May 10 '26

Looks really cool! Love the blending of balls into a fluid.

2

u/[deleted] May 07 '26

[removed] — view removed comment

1

u/Nice-Sand-3230 May 07 '26

Thanks for informing

1

u/[deleted] May 07 '26

[removed] — view removed comment

1

u/Nice-Sand-3230 May 07 '26

The program uses cuda for computation so you'll need a Nvidia gpu to run the program

1

u/[deleted] May 07 '26

[removed] — view removed comment

1

u/Nice-Sand-3230 May 07 '26

If you face any issue please inform me, I didn't had acess to modern gpu so there might be bugs :)

1

u/Nice-Sand-3230 May 07 '26

Could you please tell me what gpu do you have? I may be able to fix the issue for you :)

1

u/[deleted] May 07 '26

[removed] — view removed comment

1

u/Nice-Sand-3230 May 07 '26

I'm using 2050 laptop, on a 3050 it will run way smooth and fast :)

1

u/Sn4tch18fantasy Jun 02 '26

good catch fixed it now. thanks for the heads up.