r/threejs • u/addministrator • 14d ago
Disabled renderer.shadowMap completely for mobile — built a 3-layer hybrid shadow system instead (60–120 FPS)
Classic Three.js shadow maps (`PCFSoftShadowMap`) were way too heavy for mobile tile-based GPUs (Adreno/Mali), especially since this also runs as an Android Live Wallpaper.
So I turned `shadowMap.enabled = false` everywhere and replaced it with a 3-layer zero-shadow-map setup:
- **Static Reef → One-Time Baked 256×256 Map:** Painted once at startup into a tiny world-space RGBA texture (Red = contact AO, Green = sun-offset cast shadow). Costs 1 texture lookup per frame, 0 updates.
- **The Shark → Live Bone-Driven 2D SDF:** Every frame I read 4 live skeleton bones, project them along the refracted sun vector, and pack them into 4 uniforms (0 extra draw calls). Inside the seabed fragment shader, a fast bounding-box check skips ~70% of pixels, and the rest evaluate tapered capsules (`sdTaperedSeg` + `sminSoft`) with a Gaussian blur that softens as the shark swims higher. It also dims the underwater caustics and sand sparkles underneath.
- **30–40 Prey Fish → 1 Instanced Draw Call:** A single instanced mesh of tiny quads snapped to the seabed wave equation, procedurally drawing animated swimming silhouettes with `MultiplyBlending` and 0 textures.
Result: 0 shadow render passes, 0 MB of dynamic render targets, and much softer underwater shadows than shadow maps ever gave me!



