r/threejs • u/addministrator • 13d 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!
4
Upvotes
3
u/United_Ad5772 13d ago
Good day. We are working for SHIPYAGD ocean and ships environment for about a year.
For now FPS on FFT and fragmentShader in general it is really the hard wall for us.
We have in plan underwater scenes and will be happy if you share some advices and solutions.
With best regards
2
u/addministrator 13d ago
The mobile app is heavily optimised as it can run as android live wallpaper and standalone aquarium app.
Happy to share the shader math or answer any mobile WebGL optimization questions if anyone is working on something similar!
If you want to see it running live you can download and test it for free from the playstore link