A WebGL-based fire simulation project implementing realistic fire effects through GPU-accelerated fluid dynamics. This project uses a combination of particle systems and fluid simulation based on the Navier-Stokes equations to create physically accurate fire behavior, including combustion, buoyancy, and thermal dynamics.
- ✅ GPU-Accelerated Fluid Simulation - Real-time Navier-Stokes equation solver
- ✅ Particle System - Fire particles with lifecycle and physics simulation
- ✅ Physical Fields - Velocity, temperature, fuel, density, and pressure fields
- ✅ Combustion Model - Realistic fuel-to-heat conversion with cooling
- ✅ Buoyancy Effects - Thermal buoyancy driving fire upward
- ✅ Pressure Projection - Incompressible fluid simulation
- ✅ Blackbody Radiation - Temperature-based color mapping
- ✅ Interactive Controls - Real-time parameter adjustment
- ✅ Debug Modes - Visualize individual physical fields
- WebGL 2.0 / WebGL 1.0 (with fallback)
- GLSL for shader programming
- Vite for development and build tooling
- JavaScript ES6+ with modules
- Node.js (v14 or higher)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd csci580-final-project- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:5173/
npm run buildThe built files will be in the dist/ directory.
csci580-final-project/
├── src/
│ ├── main.js # Main application entry point
│ ├── utility.js # WebGL utility functions
│ └── shaders/
│ ├── baseVertexShader.glsl # Base vertex shader (full-screen quad)
│ ├── advectionShader.glsl # Advection shader (Semi-Lagrangian method)
│ ├── combustionShader.glsl # Combustion shader (fuel → temperature)
│ ├── buoyancyShader.glsl # Buoyancy shader (temperature → velocity)
│ ├── divergenceShader.glsl # Divergence calculation
│ ├── pressureIterationShader.glsl # Pressure solver (Jacobi iteration)
│ ├── projectionShader.glsl # Pressure projection
│ ├── vorticityConfinementShader.glsl # Vorticity confinement
│ ├── displayFireShader.glsl # Final fire rendering
│ └── ... (other shaders)
├── index.html # HTML entry point
├── package.json # Project dependencies
└── vite.config.js # Vite configuration
This fire simulation implements a complete fluid dynamics system with multiple interacting physical fields. Understanding these relationships is crucial for modifying and extending the simulation.
-
Velocity Field (
velocity)- Type: RG format (two channels)
- Stores: (vx, vy) velocity vector per pixel
- Role: Drives movement of all other fields
-
Temperature Field (
temperature)- Type: Single-channel float
- Stores: Temperature value per pixel
- Role: Generates buoyancy, affects fire color
-
Fuel Field (
fuel)- Type: Single-channel float
- Stores: Fuel amount per pixel
- Role: Burns to produce temperature
-
Density Field (
density)- Type: RGBA format (four channels)
- Stores: Color/smoke information
- Role: Visual effects (color and transparency)
-
Pressure Field (
pressure)- Type: Single-channel float
- Stores: Pressure value
- Role: Corrects velocity field to satisfy incompressibility
┌─────────────┐
│ Fuel Field │ ──┐
│ (Fuel) │ │
└─────────────┘ │
│ Combustion
┌─────────────┐ │
│ Temperature │ ◄─┘
│ Field │ │
└─────────────┘ │
│ │
│ Buoyancy │
▼ │
┌─────────────┐ │
│ Velocity │ │
│ Field │ │
└─────────────┘ │
│ │
│ Advection │
├───────────┘
│
├──► Density Field - Color/smoke
├──► Temperature Field - Carried along
├──► Fuel Field - Carried along
│
▼
┌─────────────┐
│ Pressure │ ◄── Computed from velocity (divergence)
│ Field │
└─────────────┘
│
│ Pressure Projection
▼
┌─────────────┐
│ Velocity │ ◄── Corrected (divergence-free)
│ Field │
└─────────────┘
The simulation updates fields in the following order each frame:
1. Particles → Fuel Field (add fuel)
↓
2. Fuel Field + Temperature Field → Temperature Field (combustion & cooling)
↓
3. Velocity Field → Velocity Field (self-advection)
↓
4. Velocity Field → Velocity Field (vorticity confinement)
↓
5. Temperature Field → Velocity Field (buoyancy)
↓
6. Velocity Field → Pressure Field → Velocity Field (pressure projection)
↓
7. Velocity Field → Density Field (advection)
↓
8. Velocity Field → Temperature Field (advection)
↓
9. Velocity Field → Fuel Field (advection)
↓
10. Noise Field update
Fuel Field
- Generated by: Particle emitters, user interaction (splat)
- Consumed by: Combustion (converted to temperature)
- Decay: Per-frame dissipation (FUEL_DISSIPATION = 0.92)
Temperature Field
- Generated by: Fuel combustion
- Decay: Natural cooling (fourth-power model)
- Movement: Advected by velocity field
Velocity Field
- Generated by: Buoyancy, user interaction
- Decay: Per-frame dissipation (VELOCITY_DISSIPATION = 0.98)
- Correction: Pressure projection makes it divergence-free
Density Field
- Generated by: User interaction (splat)
- Decay: Per-frame dissipation (DENSITY_DISSIPATION = 0.99)
- Movement: Advected by velocity field
Pressure Field
- Generated by: Computed from velocity field divergence
- Purpose: Corrects velocity field
- Decay: Per-frame dissipation (PRESSURE_DISSIPATION = 0.8)
BUOYANCY (Buoyancy Coefficient)
- Affects: Temperature → Velocity conversion strength
- Higher value: Fire rises faster
BURN_TEMPERATURE (Burn Temperature)
- Affects: Fuel → Temperature conversion
- Higher value: More fuel needed to produce same temperature
COOLING (Cooling Coefficient)
- Affects: Natural temperature decrease rate
- Higher value: Temperature decreases faster
VELOCITY_DISSIPATION (Velocity Dissipation)
- Affects: Velocity field decay
- Lower value: Velocity decays faster (simulates viscosity)
FUEL_DISSIPATION (Fuel Dissipation)
- Affects: Fuel field decay
- Lower value: Fuel disappears faster
DENSITY_DISSIPATION (Density Dissipation)
- Affects: Color/smoke decay
- Lower value: Color disappears faster
This fire simulation system is based on the following physical principles:
- Navier-Stokes Equations: Describe fluid motion
- Incompressibility Condition: div(u) = 0 (achieved through pressure projection)
- Buoyancy Principle: Hot air rises (Archimedes' principle)
- Blackbody Radiation: Temperature determines color (Stefan-Boltzmann law)
- Combustion Reaction: Fuel → Heat
- Heat Conduction: Natural temperature cooling
All fields are interconnected through the advection process, forming a complete physical system.
- Mouse/Touch: Click and drag to add fuel, velocity, and color to the simulation
- Spacebar: Cycle through debug display modes
- Panel Controls: Adjust simulation parameters in real-time
Press Spacebar or use the panel dropdown to switch between:
- Normal: Full fire rendering with particles
- DebugFire: Visualize fuel and temperature
- DebugTemperature: Temperature field only
- DebugFuel: Fuel field only
- DebugPressure: Pressure field only
- DebugDensity: Density (color) field only
- DebugNoise: Noise field only
See LICENSE file for details.
This project was created as part of CSCI 580 coursework.