Skybox lagging Big scenes

I am creating a solar system and there are huge distances between planets and the star. although I scaled it down, some planets still extend to more than 3000 in the x and z-direction. I am using a skybox to provide a background to the scene and give it a more space-like look, Although as the planet gets farther from the centre, it begins to lag the scene while without the skybox it works quite smoothly. is there any way to minimize this lag? or can I use some different method to apply the background?
the code for the skybox is -

class Background {

    constructor (scene) {

        this.skybox = BABYLON.Mesh.CreateBox("skyBox", 10000.0, scene);

        this.skyboxMaterial = new BABYLON.BackgroundMaterial("skyBox", scene);

        this.skyboxMaterial.backFaceCulling = false;

        this.skyboxMaterial.disableLighting = true;

        this.skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("static/Images/Textrues/Background/galaxybg", scene);

        this.skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;

        this.skybox.material = this.skyboxMaterial;

        this.skybox.infiniteDistance = true;



Welcome @Hasnain_Koser!

I can’t explain the lag you’re experiencing with skybox as I’ve not seen that myself, but have you taken a look at optimizing your scene, specifically “reducing calls to gl.clear()”?

You may not need both a huge 10000 size and infiniteDistance. Try smaller skybox size plus infiniteDistance maybe.

Are you needing to see all planets & their orbits at once i.e. unrealistic scale, or travelling from one body to another i.e. realistic scale? If the latter, I’d try empty LODs at distance for bodies and a stationary camera at world origin but the entire solar system frame of reference changes. That might minimise scale / precision issues but I doubt will do anything to fix your skybox lag.

Thank you for your response! I tried gl.clear() but it had little to no effect on the lag. Also with a smaller skybox size, the planets and their orbits disappear because I am going for the unrealistic scale as I want to view the whole solar system at once. I have scaled down the distance while scaling up the radii of the system so the system is still scaled properly. And the lag only occurs when I use the skybox, If I remove the code for the skybox there is no lag. I am also using a particle system for the sun, could it possibly be because of that?

I’m not sure. It’s difficult to advise without seeing the problem replicated in the playground. Would it be possible for you to do it there so the community can help?

It might be because of the cube texture you’re applying to the skybox. What texture resolution are you using?

1 Like

I will try to put it into the playground, and the texture resolution I am using is 1204 X 1204 pixels.

1 Like

Here is the playground mode simulation for the solar system I am creating, I have not used the real texture as I facing difficulty uploading it so I have used an existing skybox texture of the playground - Babylon.js Playground

The trailmesh is updating a vertex buffer that can be quite big each frame, and there’s a conversion taking place at each draw call.

Here’s a PR that will help performances by not performing this conversion each time (went from 23/24 fps to 60fps on my computer):

Note that you could also improve the fps a bit by limiting the GC by not performing all the new BABYLON.Vector3(...) each frame (in calc_gravity / move).

I am sorry but I am a beginner at babylon and Javascript, So I was unable to understand how I could implement the dynamic vertex update, It would be great if you could explain how I could implement it in my code. Thanks A lot

You can’t do it yourself, it’s an update of the Babylon engine itself: once the PR is merged (probably toaday) you will be able to get the change by getting the latest Babylon.js files.

How can I get the latest Babylon.js files, and is there any way I can get notified when this update occurs?

You get those files from the dist/preview release/ directory of the repo: Babylon.js/dist/preview release at master · BabylonJS/Babylon.js · GitHub

There’s no notifications but you can track the PR I have linked above.