Code. Design. Code.

Real Time Liquid

For a side project, I was interested in the potential for a real-time liquid effect. I searched for possible ways to do this. I ended up finding research on the marching cubes algorithm (also known as polygonization of scalar fields). I was about to implement it in c# based on the research paper, but I found some source code of someone that had already translated it to c#. I grabbed it and modified it so that it would work with Unity scripting limitations. At first it performed really badly, so I jumped into the code and traded some space complexity for time complexity gains.

What the algorithm does is allow me to take any particle effect that I would normally build in unity and put a mesh in its place. As you can see in the video I can also scale the resolution of the field to increase frame-rate. I can also introduce new object (like the block) in real-time and the mesh will correctly mimic the particles change. You can also see multiple times when I turn the edge smoothing on and off. This demonstrates the variety of effect styles that are possible for this system. There are many more different improvements that can be made, but as a proof of concept it turned out pretty awesome. If I were to further this demo, I would add some realistic water shaders to seen how it would handle them in real-time. The screen capture died a little bit at the end, so the artifacts that are in the video at the end aren’t there when played.

Next Post

Previous Post

Leave a Reply

© 2021 andacode