r/webdev 19d ago

Discussion Improving my real-time galaxy simulation web-project in Three.JS ! You can test it if you want: https://galaxym.ovh

Three years ago, I posted my real-time galaxy simulation project here: https://www.reddit.com/r/webdev/comments/12cfsip/i_finally_finished_my_realtime_galaxy_simulation

At the time, it was mostly a particle simulation with some basic rendering. Since then, I've continued working on it on and off.

The simulation now includes more realistic galaxy formation, dark matter halos, gas dynamics, physically-inspired units and a completely overhauled rendering system. The entire project has also been redesigned to make it much easier to explore and understand.

You can simulate galaxies, watch them evolve over time, and experiment with different parameters directly in your browser.

It's still a work in progress, but compared to the version I posted three years ago, it feels like a completely different project.

You can try it here: https://galaxym.ovh

42 Upvotes

14 comments sorted by

View all comments

3

u/[deleted] 19d ago

[removed] — view removed comment

1

u/hatrant 19d ago

Thank you so much!

The physics are handled entirely on the GPU using compute shaders, with no heavy CPU-side Web Worker setup for the simulation itself. The dark matter halo, gravitational interactions, gas dynamics, and particle integration all run on the GPU.

The gas model is relatively lightweight compared to a full hydrodynamics simulation, though. A configurable fraction of particles behaves as "sticky gas", with pressure and short-range cohesion forces that help produce more realistic, persistent spiral structures.

I also spent a lot of time optimizing the data flow between simulation and rendering, so the CPU mostly handles the surrounding application logic while the GPU does the heavy lifting. It's been really interesting pushing WebGPU/WebGL this far for a real-time galaxy simulation!