How noniv/snowflow_demo works
Purpose and runtime
SNOWFLOW is a browser-only real-time snow-rendering tech demo. It uses Babylon.js on WebGPU with custom WGSL; there is intentionally no WebGL fallback and no authored runtime assets. Vite serves/builds the application from index.html into the JavaScript entry point src/main.js.
Frame orchestration and core services
src/main.js owns initialization, loading/readiness gating, and per-frame ordering. Core systems provide camera/input motion, GPU resource helpers, live settings, loading state, and frame instrumentation:
• src/core/camera.js
• src/core/input.js
• src/core/loading.js
• src/core/settings.js
• src/core/perf.js
The browser/WebGPU device is the primary platform boundary; Babylon.js supplies engine/resource abstractions while application rendering behavior remains in custom shaders and passes.
Procedural terrain and persistent snow state
Terrain is a static nested-ring clipmap whose vertex shaders place, morph, and displace geometry; CPU code does not rebuild terrain each frame. Load-time terrain generation creates the procedural heightfield and supports CPU-side grounding samples. Persistent snow deformation is a ping-ponged GPU state updated every frame, receiving brushes from character, wake, and spells.
• src/terrain/terrain.js
• src/terrain/clipmapMesh.js
• src/terrain/heightfield.js
• src/terrain/deformation.js
• src/shaders/deformSim.fragment.wgsl
This is a key shared boundary: writers produce deformation inputs, while terrain beauty and shadow shaders consume the resulting state.
Scene rendering, sky, and shadows
The render layer builds custom depth/prepass and three-cascade shadow workflows compatible with GPU-displaced terrain and procedural casters. Sky/IBL is generated from atmospheric shaders rather than external HDR assets.
• src/render/depthPass.js
• src/render/shadows.js
• src/render/sky.js
• src/shaders/lib/terrain.wgsl
• src/shaders/lib/shadowLookup.wgsl
Shader registration and include composition are centralized in src/shaders/registry.js; shared WGSL libraries encode terrain, atmosphere, shading, deformation, water, and dynamic-light contracts.
Character simulation and contact
The character is generated from a procedural skeleton/figure definition, driven by controller motion and foot placement, with cloth simulation and snow-contact output. Its GPU-facing character/cloth state is rendered through dedicated WGSL variants for beauty, depth, and prepass.
• src/character/build.js
• src/character/controller.js
• src/character/cloth.js
• src/character/snowContact.js
• src/shaders/char.vertex.wgsl
Character contact feeds the terrain deformation boundary rather than maintaining a separate footprint system.
Dynamic interactions: wake, particles, and spells
Snow-surf creates a swept wake mesh plus spray; spells are coordinated by a shared system. Water-like spells reuse a common swept-body representation, write into deformation, and populate a pooled dynamic-light interface consumed by common shading.
• src/vfx/surfWake.js
• src/vfx/particles.js
• src/spells/spellSystem.js
• src/spells/waterBody.js
• src/spells/spellLights.js
Individual spell modules (src/spells/sweep.js, src/spells/ribbon.js, etc.) are behavior producers, while shared water/light/deformation paths keep rendering draw/resource usage bounded.
Post-processing and presentation
A depth/specular prepass feeds a post chain implementing temporal and screen-space effects before final presentation. UI exposes live art/system controls and performance/debug views.
• src/post/postChain.js
• src/shaders/prepass.fragment.wgsl
• src/shaders/post/taa.fragment.wgsl
• src/shaders/post/tonemap.fragment.wgsl
• src/ui/overlay.js
The major control flow is: input/camera → simulation and interaction writers → deformation update → shadow/depth/beauty rendering → post chain → overlay/performance reporting.
Main entry points: main.js Frame orchestrator · terrain.js Clipmap terrain · deformation.js Snow deformation state · terrain.wgsl Beauty rendering
Components 21
App runtime
- Vite entry · Serves and builds the browser application.
index.html - Frame orchestrator · Initializes systems, gates readiness, and orders each frame.
src/main.js - Browser WebGPU + Babylon · WebGPU-only device and Babylon resource abstractions.
- Camera and input
src/core/camera.js - Settings, loading, perf
src/core/settings.js - Control and debug overlay
src/ui/overlay.js
Terrain and simulation
- Clipmap terrain · Static nested-ring terrain with GPU vertex displacement.
src/terrain/terrain.js - Procedural heightfield · Load-time terrain generation and CPU grounding samples.
src/terrain/heightfield.js - Snow deformation state · Shared persistent snow state updated every frame.
src/terrain/deformation.js - Deformation simulation
src/shaders/deformSim.fragment.wgsl
Character and interactions
- Procedural character · Controller-driven figure, foot placement, and cloth.
src/character/build.js - Snow contact
src/character/snowContact.js - Surf wake and spray · Swept wake mesh and snow spray.
src/vfx/surfWake.js - Spell system · Coordinates individual spell behavior producers.
src/spells/spellSystem.js - Water bodies and spell lights · Swept spell bodies write snow and populate pooled lights.
src/spells/waterBody.js
Rendering pipeline
- WGSL registry and libraries · Central registration and shared rendering contracts.
src/shaders/registry.js - Atmospheric sky and IBL · Generated from atmospheric shaders without HDR assets.
src/render/sky.js - Cascaded shadows · Three cascades support displaced terrain and procedural casters.
src/render/shadows.js - Depth and specular prepass
src/render/depthPass.js - Beauty rendering · Renders terrain, character, and dynamic effects.
src/shaders/lib/terrain.wgsl - Post chain · Temporal and screen-space effects followed by tone mapping.
src/post/postChain.js
Connections 27
- Vite entry → Frame orchestrator: loads
- Frame orchestrator → Browser WebGPU + Babylon: initializes
- Frame orchestrator → Camera and input: updates
- Frame orchestrator → Settings, loading, perf: uses
- Frame orchestrator → Clipmap terrain: initializes
- Procedural heightfield → Clipmap terrain: grounds and shapes
- Camera and input → Procedural character: drives motion
- Procedural character → Snow contact: produces foot contact
- Snow contact → Snow deformation state: writes brushes
- Surf wake and spray → Snow deformation state: writes wake
- Spell system → Water bodies and spell lights: coordinates
- Water bodies and spell lights → Snow deformation state: writes spells
- Deformation simulation → Snow deformation state: updates ping-pong state
- Snow deformation state → Clipmap terrain: displaces snow
- WGSL registry and libraries → Deformation simulation: registers
- WGSL registry and libraries → Beauty rendering: composes shaders
- Clipmap terrain → Cascaded shadows: casts displaced terrain
- Procedural character → Cascaded shadows: casts procedural figure
- Cascaded shadows → Beauty rendering: shadow lookup
- Atmospheric sky and IBL → Beauty rendering: provides IBL
- Water bodies and spell lights → Beauty rendering: dynamic lights
- Clipmap terrain → Depth and specular prepass: renders depth
- Procedural character → Depth and specular prepass: renders depth
- Depth and specular prepass → Post chain: depth and specular inputs
- Beauty rendering → Post chain: HDR scene color
- Post chain → Control and debug overlay: final presentation
- Settings, loading, perf → Control and debug overlay: settings and metrics