Inspiration

Simulation is one of the most interesting fields in computer science. It poses fantastic problems and is a true test of someones optimization skills. I've only ever dealt optical simulation, so I thought id get fluid a shot.

What it does

It simulates a fluid in a bounding volume. Its a point based simulation, given a surface via the marched cubes algorithm. Its a bit slow.

How we built it

Under the hood it uses the euler method to simulate the motion and collision of a large number of spheres. Its given a surface, and then passed to my raytracing engine to be rendered. The engine has been highly modified for this task, to try and minimize render time per frame.

Challenges we ran into

Getting rendering working took longer than getting the fluid sim working. I spent 3 odd hours trying to get opengl working, but it just didnt work out. Simply too much to learn in a few hours. So instead, I opted to retrofit my raytracer for the task.

When youre converting an engine meant to render in seconds per frame to something that renders in frames per second, you have to cut out ALOT of fat. I had to cut out all secondary bounces, as well as almost entirely rework thread and data management. A lot of things that used to be essentially free had to be cut out to save precious hundreds of milliseconds.

Theres also a bug with the marching cubes algo I never got around to figuring out that causes flickering, not sure what thats about.

aside from that, the fluid sim was quite frustrating. I haven't touched kinetic simulation before, so I was going in blind. I had intended to implement FLIP, but I in the end barely managed to implement a highly chaotic particle only sim.

Accomplishments that we're proud of

For what it is, a CPU based raytracer never meant for this task, the retrofit went very well. As well as that, the simulation is at least identifiable as a liquid, so I take that as a win.

What we learned

GPU bindings in C++ are rough. I need to set aside more time to learning it. I also learned a fair bit about kinetic simulation, and how finicky it can be. It was a good lesson in data and performance management.

What's next for Fluid simulation & render

Hopefully? a trashbin. Its a mess, a beautiful, horrible, mess. But the best of projects are the ones that go in the trash, because theyre the ones you learn the most from.

Built With

Share this project:

Updates