Coffee Break was a game prototype me and a colleague created in early 2020 in which I was tasked with creating a 3D liquid effect that filled a cup, below is my process tackling this challenge.
Firstly, I searched for ways to simulate liquids in 2D, this is commonly done by using frictionless 2D circles that act like water particles and then drawing a mesh around circles that are bunched up in groups. This is the effect shown in the video.
This proved to be ineffective in 3D however as having enough frictionless spheres to accurately simulate water physics would take too much computing power without even going through the effort of forming a 3D model from meshes drawn around those spheres.
My second approach was in 3D but also proved unsuccessful, I used a tube with a shader that looked like coffee was being poured down it then used another model in the shape of a “falling liquid“ and a 3D culling mask shader to hide part of the tube and make it look like it was a flowing liquid.
These combined effects were not any more convincing that the tube with the shader by itself and so due to the complexity of animating two different models in conjunction to create an effect I decided to not pursue this path any further. The effect is demonstrated in the adjacent video.
Finally I discovered by reversing the shader used to fill the cup and coffee tank and animating the model and the shader in conjunction I could get a stream of coffee that although uniform, very well emulated the laminar flow seen in streams of liquid usually found coming out of pipes. The effect is shown in the adjacent video.