Skip to content

Claude/fix map editor black screen r v vfr#1313

Merged
braedonsaunders merged 4 commits into
mainfrom
claude/fix-map-editor-black-screen-rVVfr
Feb 3, 2026
Merged

Claude/fix map editor black screen r v vfr#1313
braedonsaunders merged 4 commits into
mainfrom
claude/fix-map-editor-black-screen-rVVfr

Conversation

@braedonsaunders

Copy link
Copy Markdown
Owner

No description provided.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +382 to +386
// Mark renderer as needing reinitialization
// The caller (GameCanvas) should detect this and reinitialize the scene
isInitializedRef.current = false;
isRecoveringRef.current = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

claude and others added 2 commits February 3, 2026 17:01
- 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
@braedonsaunders braedonsaunders merged commit b2f1852 into main Feb 3, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants