Hey community, is it possible to create a small scene in babylonJs render it off screen and have a camera that is inside the scene overlay the image at a larger scale in the main camera and sync the rotation of the skybox camera with the main scene camera ignoring panning and directional movement?
Think Half-Life 2 skyboxes.
Im trying to figure out the best way I can go about adding distant detail to my main scene. As the main scene is very very large using the traditional method here actually causes a lot of Z fighting on screen and some objects at a distance are rendered behind the skybox.
I use a floating origin but even so users can zoom out to see the entire solar system. Without the skybox there is no issue but at those extreme distances with the sykbox texture it will either jitter around like crazy or objects will Z fight with the skybox texture.
The current size and scale does stop the jittering which im assuming is a floating point issue for the texture co-ordinance… The only items you can see that zoomed out is the Star and the orbital lines.
But I may rethink the controls as the only reason to zoom out is to see the scale and nothing more. Selecting Planets, moons, POI is done via a UI search box.
Edit while writing…
I’ve noticed that the skybox may not be the best method. While by default the scene does eat a lot of memory (chrome reports ~2GB, while the dev tool heap is 280mb). Enabling the skybox causes it to jump to 4.99GB. It will then garbage collect and return to around 1.5GB then over the course of 2mins climb back to 5GB before repeating the cycle.
I am also using the BabylonJs inspector and debug layer. Without them it drops around 200mb in memory.
The skybox completely breaks down when attaching it to the camera. If the skybox initial size is less than 100000 it will flicker in the center of the screen as a small texture square or not appear at all. If its 100000 or more the skybox will render, but then everything else in the scene will not render. Zooming out will cause the skybox to jitter around eventually turning black.
It will be difficult to give anyone access to the repo as its a Private and the SolarSystem is quite integrated into a backend API system that would take a good week to separate and im not even sure it will work properly outside my current dev environment without a 1:1 talk through a setup procedure.
For the weekend I’ll get a Playground up and running with the same scale and see if it reproduces there.
This simple demo replicates the same issues im having. This demo does not seem to be affected by the same memory leak. I will investigate on my side. The main difference is my bodies have rotations and all child objects that are parented to each body move. There can be around ~150 objects on each of the meshes surface.
One thing that came to mind to avoid the precision issues is you could render the skybox in a separate scene with a camera synchronized to your main camera?
That was my original question. I wasn’t sure if it was possible with Babylonjs to grab a camera viewport from a scene that is off canvas and composite the final image from my main scene and the “skybox” scene.