Skip to content

luoluobuli/WebGPU-MPM-based-Snow-Simulation

Repository files navigation

WebGPU snow sim

This project contains a snow simulation engine using the material point method (MPM) algorithm.

You can view this demo online so long as your browser supports WebGPU!

snowy low poly terrain

Features

Physics

This project features a material point method (MPM) particle engine for dynamic cohesion and fracture, with...

  1. a position-based material point method (PBMPM) variant for stability.
  2. an explicit MPM variant for speed.

MPM enables:

Elastic deformation and stress forces to simulate soft materials Plastic deformation to simulate fracture and tearing Hardening to simulate the "packing" behavior of snow
elastic deformation with a high grid size plastic deformation with a high grid size

Additionally, the particles are also affected by:

  1. A rigid collider mesh, with triangle-based intersection.
  2. Repulsion and attraction forces spawned at your pointer (RMB).
Grabbing with attraction Exploding with repulsion
grabbing with attraction exploding with repulsion

Rendering

Data from the simulation can be rendered out using the following methods:

Marching cubes, which applies a procedural snow material to a dynamic mesh that is created based on the density of particles
(shadows are volumetrically raymarched)
Screen-space fluid rendering (SSFR) for a fast (but blobby) appearance Volumetric raymarching inspired by offline rendering for snow Points for a fast way to visualize particles, colored by their deformation (red channel = elastic deformation, green channel = plastic deformation)
marching cubes demo rendersnow material closeup ssfr demo render volumetric demo rendervolumetric demo render from behind points demo renderpoints demo render with deformation coloring

Additionally, when Points or Marching Cubes are selected, the scene is rendered with screen-space ambient occlusion.

snowy horse

Code

This is a SvelteKit project with a simulation powered by WebGPU.

Local development

After cloning this repository:

  1. Setup: npm i (Node.js) or deno i (Deno)
  2. Run: npm run dev or deno task dev

Motivation

Existing simulation systems in 3D tools like Blender are somewhat limited. There are simulations for mesh-based solids (cloth/rigid body) and simulations for particle-based solids (soft body), liquid (fluid), and gas (smoke). However, at present, there isn't exactly a solution for fragile materials like snow or jelly that only sometimes stay together and sometimes break apart.

The closest practical solution there is is to pre-fracture a mesh, sometimes manually if there are not many pieces or otherwise using a "cell fracture" mechanism which tends to be pretty easy to spot visually. In movies, simulations have evolved to use certain techniques which better support semi-solid materials. For this project, we'll focus on the "material point method", which is an algorithm often leveraged for snow, as with Frozen in 2013. One goal of this project is to implement and describe this technique in an accessible and customizable way, both to demonstrate its benefits as well as lay the groundwork for engine implementations for artistic use in tools like Blender.

An additional point of interest is animated characters. Even in industry tooling, characters made of a simulatable material like sand, snow, or water often simply consist of a mesh styled to look like the material, with a particle system on its surface. A large amount of manual labor is necessary to model simple interactions with other characters or meshes in a believable way, such as controllers to decide when and where to fracture the mesh into pre-factured pieces or blend between the mesh and a particle system. We'd like to investigate how easily a simulation can achieve similar results; importing meshes and animations to the scene, while maintaining ease of artistic control, is an additional point of interest.

Implementation

Hey kid, want some implementation details...?

mpm grid-to-particle

Bloopers and progress shots

Volumetric raymarching Surface raymarching
volume raymarch with piles of materialbacklit volume raymarch raymarched blobsraymarched suzanneraymarch after collision
Small grid cell size, large timestep with elastic deformation Ditto, with plastic deformation
elastic high grid resolution demo plastic high grid size demo

Collision tests

collider with low grid resolution collider with wire collision at high grid resolution

Resources

  1. A Material Point Method For Snow Simulation. The 2013 Disney paper proposing MPM for simulating snow.
  2. Breakpoint. A DirectX implementation of 3D PBMPM with mixed material types, along with a mesh shading renderer.
  3. GPUMPM. A CUDA implemenation of MPM, associated with the 2019 paper GPU optimization of material point methods.
  4. PB-MPM. The original WebGPU proof-of-concept implementation of 2D PBMPM with various material types, associated with the original 2024 paper introducing PBMPM, A Position Based Material Point Method. (although internal forces seem to be broken at the moment, as of 2025-11-21...)
  5. Principles towards Real-Time Simulation of Material Point Method on Modern GPUs. A 2021 paper covering GPU optimizations of MPM.
  6. The Material Point Method for Simulating Continuum Materials. A 2016 paper introducing MPM.

Project pitch document

Project intermediate presentations

Project presentation

Acknowledgments

Libraries

  1. Chart.js. Performance graphs
  2. SASS. CSS preprocessing
  3. SvelteKit. UI/reactivity
  4. THREE.js. gLTF/gLB loading
  5. Vite. Bundling and development environment
  6. wgpu-matrix. Helper classes for operations involving WGSL builtins on the CPU

Assets

  1. Free Low Poly Forest by purepoly. Scene model
  2. Horse Statue 01 by Rico Cilliers. Particle scatter model
  3. Kloofendal Misty Morning (Pure Sky) by Greg Zaal. Environment map

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •