Project Proposal v2 - Alexander-Hjelm/metaballs-glfw GitHub Wiki
Metaballs-GLFW
Objective
Using low-level graphics programming, we aim to program and render a dynamic fluid using the metaballs technique, where the fluid particles use a basic physics model to collide with each other and the environment. A reference video can be found here: https://www.youtube.com/watch?v=1HqCZgMjCuE. We will restrict ourselves to making a realtime simulation with the order of 50-100 particles.
Grading goal
For this project we are looking to obtain an A in the course. We would like to continue on the graphics programming tracks with our master's projects, and we would much appreciate it if the examinator would asses our project closer to the criteria of a master's project.
Tools
We will use GLFW and GLSL. GLFW is a utility library for working with OpenGL, and we will use it as an interface between the high-level program logic and the low-level rendering. Mainly we will use GLFW to manage the OpenGL context and make GPU drawcalls. GLSL is the OpenGL shading language that gives developers control over the rendering pipeline. We will use GLSL to write our shader programs.
Initial feasibility study
So far, we have begun development to examine how feasible our project idea is. In order to render simple primitives, we have created a program that renders triangles with glfw's built-in library for pixel rasterization. It also sets up the View-Model-Projection matrix and renders a primitive cube in perspective 3D, using a triangle buffer.
Using this base program, we have built a voxel shader that renders a cube field from a defined isosurface (we began using a spherical surface model for simplicity). After we derived the mathematical definition of the potential field of multiple metaballs, we made a test implementation of the marching cubes algorithm to construct the fluid mesh. Using these components, we have successfully rendered multiple metaballs with interacting potential fields.
Here is a screenshot of what the initial program looked like with only two metaballs whose fields are partially overlapping:

Completed work
We have optimized our previously hard-coded metaball potential field model. We are currently sending the ball positions to the GPU as a texture, which has proven much faster than sending each ball position as a uniform vector. The latter is also much more scalable for an increasing number of practices.
We have animated the individual particles using a basic physics model with universal gravity and inter-particle forces to simulate particle collision. Each ball is initialized with a random velocity, which is adjusted by external forces as the simulation goes along.
We have implemented a basic Phong illumination model on the fluid mesh.
We use the entire simulation domain (a cube that completely encapsulates the uniform 3D voxel grid), and as such we have had no need for explicitly modelling the simulation boundaries.
Here is an animated screen capture of what the current program looks like with 50 metaballs and a voxel grid length of 50:

Remaining steps
We will fine tune the physics model, primarily by modelling the balls' bounciness against the surfaces of the simulation space. In doing this, we will expose an elasticity coefficient, and apply bounces to all surfaces of the cube rendering domain. Futhermore, we will animate the camera to show the simulation from all angles, and we will include a controllable primitive shape in the scene that can be used by the user to manipulate the fluid.