Claude/fix map editor black screen r v vfr#1313
Conversation
The map editor preview was causing WebGPU device lost errors on AI-generated water island maps. Root cause: the old WaterMesh created separate ThreeWaterMesh instances (each with reflection RenderTargets) per flood-filled water region, causing 3GB+ GPU memory usage on maps with many water regions. ## New Unified Water System ### Core Components - `UnifiedWaterMesh`: Single merged BufferGeometry for all water cells - One draw call regardless of region count - Vertex attributes encode regionId, isDeep, elevation - Quality-based cell merging (1x1 to 4x4) - `TSLWaterMaterial`: TSL/NodeMaterial water shader - Texture-based dual-layer animated normals (matching original) - Depth-based shallow/deep color blending - Fresnel reflections + specular highlights - Quality-tiered features - `WaterMemoryManager`: Memory budget management - 100MB budget enforcement - Automatic quality tier selection - Runtime degradation support - `PlanarReflection`: Shared reflection system (ultra only) - Single 1024x1024 render target for ALL water - Throttled updates (every 2-3 frames) ### Device Lost Recovery - WebGPU device lost detection via GPUDevice.lost promise - Automatic recovery with quality reduction - WebGL fallback after 3 failed attempts - User notification on recovery ### Quality Tiers | Quality | Cell Merge | Memory | Reflections | |---------|------------|---------|------------------| | Low | 4x4 | ~5MB | Cubemap only | | Medium | 2x2 | ~10MB | SSR | | High | 1x1 | ~15MB | SSR | | Ultra | 1x1 | ~80MB | SSR + Planar | ### Files Changed - New: src/rendering/water/UnifiedWaterMesh.ts - New: src/rendering/water/WaterMemoryManager.ts - New: src/rendering/water/PlanarReflection.ts - New: src/rendering/water/index.ts - New: src/rendering/tsl/WaterMaterial.ts - Modified: src/rendering/EnvironmentManager.ts (use new system) - Modified: src/rendering/tsl/WebGPURenderer.ts (device lost handling) - Modified: src/components/game/hooks/useWebGPURenderer.ts (recovery flow) - Modified: public/config/graphics-presets.json (water settings) - Modified: docs/architecture/rendering.md (documentation) - Deprecated: src/rendering/WaterMesh.ts (kept for reference) https://claude.ai/code/session_016r1L1acesrhCt9DKqr8dA2
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a66731f1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Mark renderer as needing reinitialization | ||
| // The caller (GameCanvas) should detect this and reinitialize the scene | ||
| isInitializedRef.current = false; | ||
| isRecoveringRef.current = false; | ||
|
|
There was a problem hiding this comment.
Reset recovery attempt counter after success
After a successful recovery, recoveryAttemptsRef.current is never reset, so the counter keeps climbing across independent device-loss events. This means a user who has two or three successful recoveries over time will eventually hit the MAX_RECOVERY_ATTEMPTS guard and get a permanent failure message even though recovery is still viable. Consider resetting the attempt counter on success so future losses can still recover.
Useful? React with 👍 / 👎.
- Remove deprecated WaterMesh.ts (939 lines) - no longer imported anywhere - Update OVERVIEW.md file tree to show new water/ directory - Remove deprecated file reference from rendering.md https://claude.ai/code/session_016r1L1acesrhCt9DKqr8dA2
No description provided.