WIP: Real Scale Planet

Hello,

After testing a CDLOD on flat terrain, the next logical step was to apply it to a sphere :grin: This kind of approach is usually found in C++, but I wanted to see how far I could push it with JavaScript!

Features

  • Floating origin camera
  • Real-scale planet (1:1)
  • Quadsphere with a uniform mesh
  • Asynchronous CDLOD/Quadtree using Web Workers
  • Volumetric Atmospheric Scattering Shader

Interesting Aspects

  • Floating Origin Camera:
    Instead of moving the camera, objects move around it to handle large-scale rendering efficiently.
    Babylon.js Floating Origin Documentation

  • Quadsphere with CDLOD:
    I’m using a quadsphere with a CDLOD per face, ensuring that the triangles remain uniform across the sphere.
    Reference

  • Web Workers for Chunk Generation:
    The most interesting part is the use of Web Workers to generate the quadtree chunks. Initially, this was handled synchronously on the main thread, and performance was acceptable with a quadtree 6-7 levels deep.
    The goal was to free up the main thread for rendering by managing chunk generation in a pool of Web Workers (one worker per chunk).

WebGL2 Planet CDLOD take off wireframe
  • Scaling Web Workers:
    Strangely, as soon as I exceed 3-4 Web Workers, only Firefox is able to create them properly.
    The solution was to use a blob object (MDN Reference) for Web Workers, eliminating URL calls.
    This now allows up to 256 or even 512 Web Workers before the browser crashes!
WebGL2 Planet CDLOD with 1 web worker
WebGL2 Planet CDLOD with 16 web workers
WebGL2 Planet CDLOD stress test

Performance

  • With this approach, I can now reach 10-12 quadtree levels without lag.
  • CPU usage has increased from less than 10% to around 20-25%, and it works quite well.
  • The next bottleneck is draw calls!

The code is still a bit messy, and there’s no demo available yet, but I’ll update the post this weekend with more details!


Volumetric Atmospheric Scattering Shader Source

Demo

Github project

L = Show LOD
² = Debug Layer

13 Likes

Wow the Lod transitions are so smooth I am impressed :ok_hand:

For the part about scaling the number of workers, you might be interested in Navigator: hardwareConcurrency property - Web APIs | MDN that gives you a rough estimate of how many workers you can run efficiently in parallel.

Can’t wait to see more of it :eyes:

2 Likes

Very impressive!

2 Likes

Thanks! I added Navigator.hardwareConcurrency

Finally, the demo is ready! I’m going to take a break—there are still plenty of ideas to improve LOD management.

I lowered quadtree level to make it more accessible, I hope it will work well :slight_smile:

Press L to display LODs.
Press ² to display BabylonJS debug layer.

Demo

Github project

4 Likes