Skip to main content

VIVIA โ€” Rendering Pipeline

GPU Pipeline (wgpu)โ€‹

The renderer uses wgpu 0.20 with custom WGSL shaders for all rendering:

Render Passesโ€‹

  1. Terrain โ€” instanced chunk geometry, per-fragment lighting
  2. Sky โ€” procedural gradient with sun/moon, ACES tonemapping
  3. Animals/Mobs โ€” instanced voxel bodies with walk animation
  4. GLB Models โ€” loaded AI-mesh models with procedural skinning
  5. Weather โ€” rain/snow particles (disabled for performance)
  6. UI โ€” HUD, inventory, crafting, text overlays

Lighting Modelโ€‹

  • Sun โ€” directional NยทL with day/night cycle
  • Moon โ€” soft ambient at night
  • Specular โ€” Bln-Phong for wet skin, shells, ice, metal
  • Emission โ€” glow for eyes, crystals, lava
  • Fog โ€” distance-based, sky-colored, matches terrain/mobs
  • Tonemapping โ€” ACES (Narkowicz approximation) in linear space

Geometryโ€‹

Procedural 3D primitives generated by pure math:

  • Sphere โ€” UV sphere with configurable rings/stacks
  • Cylinder โ€” lathed with end caps
  • Capsule โ€” cylinder + hemisphere ends
  • Cone โ€” lathed with base cap
  • Box โ€” unit cube

All shapes have smooth per-vertex normals for organic creature bodies.

GLB Model Pipelineโ€‹

  1. Load raw GLB (tripo/meshy AI exports)
  2. Weld duplicate vertices
  3. Decimate to ~6K triangles (meshopt, 2% threshold)
  4. Bake triplanar UVs from positions + normals
  5. Generate procedural skin texture per creature type
  6. Cache to ~/.local/share/nv2/mesh_cache (keyed by GLB hash)
  7. Upload vertex + index buffers to GPU

Shadersโ€‹

ShaderPurpose
shader.wgslMain terrain + block rendering
sky.wgslProcedural sky, sun/moon, aurora
weather.wgslRain/snow particles
animals.wgslVoxel creature rendering + walk animation
model.wgslGLB model rendering + procedural gait
text.wgslText/glyph rendering
ui.wgslHUD elements
ui_sprite.wgslSprite rendering

Performanceโ€‹

  • Instanced rendering โ€” one draw call per shape per chunk
  • 2048 cube instances max (creatures)
  • 256 AI mesh instances max (GLB models)
  • Bilinear texture upscale + high-frequency grain for close-up detail
  • Deterministic mesh cache โ€” instant restart (0.3s from cache)