Glitchy fluid simulation | Xbox 360

Glitchy fluid simulation
Xbox 360

Four years ago, I was trying to implement an interactive fluid dynamics simulation. I didn't know much about how that stuff worked, so my code was mostly copy paste and guess work. Ended up with this strange buggy simulation system in the middle of my journey. Decided to upload it here for easy access!


Video of the application in use, showing how the simulation can take several minutes between when you input fluid and when the glitch starts:

In the video, I start by adding some fluid with my mouse. It spreads and it looks like it stabilizes, but then suddenly after about 3 minutes, a weird pattern appears from seemingly nowhere and invades the smooth area. It takes completely over and eventually converges into some vertical animated vein-like shapes. You can see the veins from time to time split up and merge with other veins.

The main code for the simulation is pretty short: https://github.com/asbjornlystrup/glitchy-fluid-simulation/blob/master/GlitchyFluidSimulation.gmx/shaders/sh_cml_rgb_displacement_update.shader
It's a GLSL ES shader that updates a texture with velocity and density information each time it renders. It takes the previous step's texture and calculates the new one. The texture is a 720x720 px texture with an RGBA 8-bit format. The texture initializes with 0 density (z-component) and (128, 128) for velocity, which is equal to (0, 0) after being transformed in the shader. You can download the full GameMaker Studio 1 project from the repository: https://github.com/asbjornlystrup/glitchy-fluid-simulation