Rain It In

CS184 Final Project - Water Droplet Physics Simulation

Link to Video: Rain It In Simulation Demo
Link to Presentation Video: Presentation Video

Abstract

Rain It In is a real-time simulation of raindrops falling and splashing upon impact using OpenGL. The system models both particle-level fluid behavior and physical interactions with surfaces. By combining custom teardrop mesh generation, reflection/refraction shaders, and gravity-based dynamics, the project visualizes realistic rain behavior in an interactive 3D environment with skybox lighting and camera control.

Technical Approach

We started with a basic 2D simulation, evolving it into a full 3D OpenGL-based simulation using GLEW, GLFW, and GLM. Each droplet is rendered as a procedurally generated mesh with cosine-based tapering to mimic a teardrop shape. The main shader employs a Fresnel-based blend of reflection and refraction using a cubemap to simulate realistic lighting on water. Droplets are subject to gravity and spawn splash particles upon impact using randomized velocity vectors and size sampled from log-normal distributions, inspired by techniques described in Splash! A Particle-Based Fluid Simulation

Our simulation applied fundamental physics and optical formulas. Droplets fall under Newtonian gravity, updating their position \( \vec{p} \) and velocity \( \vec{v} \) using:

\( \vec{v}(t+\Delta t) = \vec{v}(t) + \vec{g} \cdot \Delta t \),
\( \vec{p}(t+\Delta t) = \vec{p}(t) + \vec{v}(t+\Delta t) \cdot \Delta t \)

To model optical effects like reflection and refraction, we used built-in GLSL functions based on:

Particle splash sizes were sampled from a log-normal distribution:
\( r \sim \text{LogNormal}(\mu, \sigma^2) \),
where \( \mu = \log(r_{parent} \cdot 0.5) \)

Camera movement is controlled via keyboard (WASD) and mouse (pitch/yaw), and interactions include pausing ('P') and restarting ('R') the simulation. A ground plane is rendered using standard Phong lighting while droplets and particles use environment-mapped shaders.

Our shaders were written in GLSL 330 core. Shader logic was loaded and compiled via utility functions from `ShaderUtils.h/cpp`. We diverged from existing references by crafting our droplet geometry manually, instead of using sphere primitives, and added realistic refraction using the built-in `refract()` function and Schlick approximation for Fresnel reflectance.

Problems Encountered

Lessons Learned

Results

Our system produces visually compelling animations of falling droplets and splash particles under various lighting conditions.

Contributions

A CS184 Computer Graphics and Imaging Project

View on GitHub