Skip to content

Latest commit

 

History

637 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reze Engine

npm · Live demo

Zero-runtime-dependency WebGPU engine for real-time MMD/PMX rendering — renderer, animation, IK, physics, and a multi-effect VFX system, all in TypeScript.

One piece of the Reze MMD family, covering the whole MMD workflow on the web:

reze-engine This repo — the WebGPU foundation, anime-character rendering and physics
reze-design Scene design, rendering and sharing
reze-studio Animation editing on a professional timeline and curve editor
MiKaPo Real-time motion capture in the browser, exporting straight to VMD
reze-rig Retarget FBX animations to MMD VMD format, Mixamo and Unity tested

screenshot

npm install reze-engine

Features

Models and motion

  • PMX models, VMD motion with MMD's own bezier packing, IK with per-chain enable, append-inherit bones and fixed-axis twist bones, VMD export
  • Vertex / group / bone / material morphs (multiply and add), vertex morphs on a GPU compute path
  • MMD draw disciplines reproduced: author-order transparency with depth write, per-mesh interleaved outline hulls, the eyes-through-bangs stencil pass, sphere maps as graph nodes
  • In-house sequential-impulse physics for PMX rigs — rigid bodies, joints, deterministic wind, a world floor
  • Stages as environments, not characters: a stage PMX takes the same materials, graphs and style groups a character does, and keeps the bone and material morphs its author rigged for doors, lifts and colour switches — while skipping physics, IK and idle pose work, and owning the floor so the built-in ground steps aside. A stage keeps the light it was built under, by Unity's rendering layers: a stage draws on RENDERING_LAYER_DEFAULT and the cast on RENDERING_LAYER_CHARACTER too, so a directional light given to setLights on the default layer is the stage's daylight while the sun, keyed to the character layer, stays the cast's — and setModelAmbient and setModelFill give one model its own ambient and fill, so a room ported from a game is lit by its own day while the cast keeps the scene's key
  • A model can ride another's bone — MMD's 外部親 — so a weapon, a phone or a second character follows a hand without being parented in the file; setModelParentKeys keys that parent over the scene, for a prop handed over, put down, or thrown and left to gravity

Rendering

  • Shader-graph materials: every look is a node graph compiled to WGSL, lit with Unity's own models — URP's Lit (base colour, metallic, smoothness, specular, occlusion, emission) and Lambert for the toon ramps that read the light; style groups bind any materials to any graph; ungrouped materials render a Lit default
  • HDR pipeline end to end — bloom, 4× MSAA, three view transforms (Filmic, Standard, AgX from Blender's own LUT), bladed-bokeh depth of field
  • Colour grading over the tonemapped image: ASC CDL slope / offset / power with contrast and saturation, uniforms-only so dragging a slider rebuilds no pipeline — and the background layer stays ungraded, so a grade shapes the scene without staining the sky behind it
  • Four shadow cascades fitted to the camera every frame: the inner one to the stretch around what it looks at, the outer ones out to everything it sees and the floor the shadows land on, all reaching along the light to the scene's bounds — so a stage's window frames shadow its floor to the far wall, a low sun's long shadow is whole, and a lone dancer keeps a crisp near map
  • Floor mirror: a planar reflection pass reusing the scene pipelines, with depth-proportional blur and the reflection composited as its own ground layer
  • HDRI worlds (.hdr): the sky renders through the same view transform as the scene and lights the cast via spherical-harmonic irradiance — the sun keeps the toon ramp — and a Lit surface reflects it along the reflection vector at a level its smoothness picks, on Unity's mip curve. On a stage a reflection probe stands in, as Unity's does: the stage captured from its middle, GGX-prefiltered and box-projected to its bounds, so a polished floor mirrors the room and a metal mirrors the sky
  • Positional lights, placed in the scene or emitted by effect shaders — stage rigs, firework bursts, a hand ribbon lighting the dancer as it passes — in Unity's units and by URP's law: no π anywhere, inverse square windowed to zero at the lamp's reach and held flat inside its bulb, up to 256 in a scene; a spot can throw a cookie, its gobo pattern projected along the cone. Every lamp that reaches a Lit surface puts its highlight on it; forty candles on a polished floor are forty glints
  • Eye tracking: a gaze that follows the camera or a point within the rig's own range, and the cast interface reports where she is looking so an effect can follow it
  • setModelDissolve takes a character apart in her own material — a per-triangle threshold burn with a glowing front, run identically by the colour pass, depth prepass, shadow map and outline hull, so nothing of her is left standing; setModelPhysicsWhileHidden keeps a hidden model's cloth moving, so a costume swapped in arrives already in motion

Effects

  • N simultaneous scene effects, each one WGSL file declaring its mounts: fullscreen background/foreground, GPU particles, bone-trail ribbons, a persistent simulation grid, and lights
  • Scheduled and parameterised from the source: setEffectSchedule gives an effect any number of windows, each with its own clock starting at zero and its own blend in and out, while #param lines declare the dials a host shows — turning one writes a uniform rather than recompiling
  • Effects read the scene through data interfaces — the cast (bones, velocities, trail history), the audio analysis, MIDI notes, .lrc lyrics with their words rasterised for the shader to draw, and per-pixel object/material ids
  • Particles and ribbons are scene geometry: depth-tested, bloomed, and reflected in the mirror
  • Install-time compile diagnostics per effect; a broken effect fails alone

Pipeline

  • GPU frustum culling writing indirect draw arguments, replayed through render bundles — the CPU re-encodes only when scene structure changes
  • Deterministic by construction: everything runs on the scene clock, so offline export (renderFrame at any resolution) reproduces the live scene exactly
  • Camera: orbit, bone-follow, or a driven MMD camera VMD; GPU picking, gizmos, morph/material editing surfaces
  • Every emitted shader is compiled on a real GPU device by the repo's validation tool (engine/tools/validate-wgsl.mjs) before release

Quick start

import { Engine } from "reze-engine"

const engine = new Engine(canvas)
await engine.init()

const model = await engine.loadModel("reze", "/models/reze/reze.pmx")
await engine.autoStyleGroups("reze")

await model.loadVmd("dance", "/animations/dance.vmd")
model.show("dance")
model.play()

engine.runRenderLoop()

autoStyleGroups reads the model's own material names and gives each group a shader graph, so hair, eyes and skin come out looking like MMD with no shading code of your own.

Architecture

One frame, top to bottom. The CPU describes the scene once and the GPU runs it: culling and effect simulation in compute, shadows and the floor mirror feeding a scene pass that draws MMD the way MMD artists expect — author order, outlines, the eye/hair stencil — then bloom, film tone mapping, and depth of field finish the image.

architecture

License

MIT

About

Zero-dependency WebGPU MMD renderer

Topics

Resources

Stars

278 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages