Simulating Liquid Spread with Height Maps and Fluid Dynamics
A developer describes implementing a liquid-spreading effect for a cosmetics brand’s foundation simulator, first released in 2021. The project began in January 2021 when the author faced the challenge of making digital liquid behave realistically. Rather than deforming geometry, the solution uses a fluid simulation algorithm combined with a height map to track liquid thickness and movement across the surface.
The implementation relies on three interconnected components. A velocity map from the fluid simulation drives how thickness redistributes each frame through advection—the algorithm traces velocity backward to find source positions and samples thickness from there. A separate alpha map preserves visual traces by storing the historical maximum thickness at each location, so color remains even after the liquid thins out and flows away. Surface normals are computed directly from the height map within the fragment shader, allowing the renderer to add highlights and definition without modifying the underlying mesh. The effect uses two framebuffer objects that alternate each frame.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.