Skip to main content

Overview

Hyperscape uses Three.js with WebGPU for high-performance 3D rendering, with automatic fallback to WebGL for compatibility.

Renderer Architecture

WebGPU with WebGL Fallback

The rendering system uses THREE.WebGPURenderer with automatic backend selection:

Backend Selection

WebGPU (Preferred):
  • Modern high-performance rendering API
  • TSL (Three.js Shading Language) post-processing
  • Cascaded shadow maps (CSM) for realistic shadows
  • Requires Chrome 113+, Edge 113+, or Safari 17+
WebGL (Fallback):
  • Graceful degradation for older browsers and WebViews
  • Single directional shadow maps (no CSM)
  • Disabled TSL post-processing
  • Works in WKWebView (Tauri), older Safari, and browsers without WebGPU
Detection Logic:

Auto Exposure System

The environment system includes adaptive exposure that mimics eye adaptation to different light levels.

Exposure Values

How It Works

Auto exposure adjusts based on the day/night cycle:
  1. Calculate target exposure based on day intensity (0-1)
  2. Use smoothstep interpolation for natural transitions
  3. Lerp to target with factor 0.03 (~30 frames for smooth adaptation)
  4. Apply to renderer via toneMappingExposure
Benefits:
  • Night scenes remain visible while still darker than day
  • Smooth transitions during sunrise/sunset
  • Mimics realistic eye adaptation
  • No jarring exposure changes

Lighting System

Day/Night Cycle

The environment system dynamically adjusts lighting based on time of day: Daytime Lighting:
  • Sun intensity: 1.8
  • Sun color: Warm white (1.0, 0.98, 0.92)
  • Hemisphere light: 0.9 intensity
  • Ambient light: 0.5 intensity
  • Exposure: 0.85
Nighttime Lighting:
  • Moon intensity: 0.6 (increased from 0.4 for better visibility)
  • Moon color: Cool blue (0.6, 0.7, 0.9)
  • Hemisphere light: 0.4 intensity (blue-silver tones)
  • Ambient light: 0.3 intensity (brighter blue moonlight)
  • Exposure: 1.7 (compensates for lower light)

Ambient Lighting


Shadow System

Cascaded Shadow Maps (WebGPU)

WebGPU uses CSM for high-quality shadows:
CSM Levels:

WebGL Shadow Fallback

WebGL uses simplified single directional shadows:
Differences:
  • No cascaded shadow maps
  • Single shadow frustum
  • Lower shadow quality but better compatibility

Post-Processing

TSL Post-Processing (WebGPU Only)

WebGPU supports Three.js Shading Language (TSL) post-processing:
Effects:
  • Color grading with LUT support
  • Bloom for glowing effects
  • Tone mapping
  • Anti-aliasing
WebGL Limitation:
  • TSL post-processing disabled on WebGL
  • Basic tone mapping only
  • Maintains playability without advanced effects

Renderer Configuration

Creating a Renderer

Renderer Capabilities


Visual Effects

Cloud Rendering

Clouds use depth testing to render correctly behind closer objects:
This fixes clouds appearing in front of nearby terrain.

Fog System

Dynamic fog color transitions based on time of day:

Performance Considerations

Renderer Selection

  • WebGPU: Higher performance, modern features
  • WebGL: Better compatibility, slightly lower performance
  • Automatic fallback: No user intervention required

Shadow Quality

Shadow quality can be adjusted via settings:
Users can choose: none, low, med, high

Post-Processing Toggle

Post-processing can be disabled for better performance:

Client Package

Client-side rendering setup and configuration.

Environment System

Day/night cycle, weather, and environmental effects.