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 usesTHREE.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+
- 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
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:- Calculate target exposure based on day intensity (0-1)
- Use smoothstep interpolation for natural transitions
- Lerp to target with factor 0.03 (~30 frames for smooth adaptation)
- Apply to renderer via
toneMappingExposure
- 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
- 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:| Level | Cascades | Map Size | Max Distance |
|---|---|---|---|
| None | 0 | 0 | 0 |
| Low | 2 | 1024 | 200 |
| Med | 3 | 2048 | 400 |
| High | 4 | 4096 | 600 |
WebGL Shadow Fallback
WebGL uses simplified single directional shadows:- 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:- Color grading with LUT support
- Bloom for glowing effects
- Tone mapping
- Anti-aliasing
- 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: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:none, low, med, high