Thanks to visit codestin.com
Credit goes to github.com

Skip to content

kmmod/substrate

Repository files navigation

Substrate - WebGPU Terrain Generator

screenshot.jpg

Live demo: https://substrate-webgpu.netlify.app/

Terrain generation system built with WebGPU that leverages compute shaders for GPU-accelerated mesh generation.

  • Node.js 18+
  • pnpm package manager
  • WebGPU-compatible browser (Chrome 113+, Edge 113+, or Firefox with WebGPU enabled)

Installation

# Clone the repository
git clone <repository-url>
cd substrate

# Install dependencies using pnpm
pnpm install

Development

# Start development server
pnpm dev

# Build for production
pnpm build

# Preview production build
pnpm preview

Architecture

GPU Compute Pipeline

The terrain generation uses a multi-stage GPU compute pipeline:

  1. Index Generation (index-generation.wgsl) - Generates triangle indices for tessellated quads
  2. Tessellation Compute (tessellation-compute.wgsl) - Creates vertex positions, normals, and UV coordinates
  3. Render Pipeline (tessellated-quad.wgsl) - Renders the terrain with lighting, fog, and optional wireframe

Key Components

  • GpuTessellator - Manages compute shader execution for mesh generation
  • GpuTessellatedQuadPipeline - Handles the rendering pipeline and GPU buffer management
  • Terrain - Manages terrain uniforms and wireframe state
  • Camera - Orbit camera with pan, rotate, and zoom controls
  • Gui - Tweakpane interface for real-time controls

Controls

  • Mouse Left Drag - Rotate camera
  • Mouse Right/Middle Drag - Pan camera
  • Mouse Wheel - Zoom in/out
  • WASD Keys - Pan camera

License

MIT License

About

WebGPU terrain generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages