Jump to content

AssetManager & sceneOptimizer contribution

Pierre Glibert

Recommended Posts

Hi community,

I want to propose you some addition to assetManager and sceneOptimizer.

If the solution already exist, said me ;)


assetManager :

1. Get loading percent, not on x file loaded but on stream data loaded when it's possible.

     > for more precision and to show state if you load some big files.

2. Add "abort" function and "onAbort" callback to cancel running tasks and loading files.

     > Currently "clean" function delete tasks in assetManager but not abort current loads. That mean if you have a big file in loading, it don't stop.


sceneOptimizer :

1. Add a starter level to try optimizing render :

     > I tested the current sceneOptimizer and the problem is it try the best render first. If you have an older device, the website crash and the browser reload page before that sceneOptimizer can downgrade the render. So, it's a loop without ending.

2. Create two steps to optimize render :

     > First : upgrading. The sceneOptimizer try to reach "x" FPS with the starter level. If it's ok, it upgrade render again until when it can't reach "x" FPS.

     > Second : dowgrading. If the last try (or the first try with the starter level ) not reach FPS, the sceneOptimizer downgrade until when it can reach FPS. If the sceneOptimizer reach "x" FPS, it stop.

     > Of course, we keep "trackerDuration" : time in milliseconds between passes.

     > You will can restart the sceneOptimizer when you add or change something like the current version ;)


What do you think about this ?

Have a nice day !

Link to comment
Share on other sites

Hi @Deltakosh,

Thank you for your quick answer.

I will begin with sceneOptimizer first. I think it's more easier and faster to do ;)

For assetManager and "abort", I must to see which files i need to change.

I have a lot of work at this moment. So ... soon as possible.

I hope add this before babylon 3.0 ;)

Have a nice day,


Link to comment
Share on other sites

  • 1 month later...

Hi community,

I can't just change the current code for sceneOptimizer...

So, I make a new proposition called renderGradingSceneOptimizer and write it in sceneOptimizer file : https://github.com/pierreglibert/Babylon.js/blob/76ed247b1c81f24913c458f0501d06d5667ae8b4/src/Tools/babylon.sceneOptimizer.ts

What's the purpose of this ? :

- Associate render performance ( accessibility ) and dynamic loading performance ( plug and play ) in one new user friendly optimization system.


The code not working at this moment, I just write class and method to illustrate how it could work.

for exemple :

- 1. You can preset some "grades" render like : low, medium and hight quality render.

- 2. You can add scene or mesh asset you need for low "grade". So if your hardware is not enough powerfull for medium "grade", you don't need to load and show asset of this "grade".

- 3. On asset, you can add LOD version for textures, meshes and (NEW) animations.

- 4. Of course, you can also add, like before, optimization like HardwareScalingOptimization, etc.


Here, renderGradingSceneOptimizer load asset by "grade" but you can also activate the dynamic load by distance ( calculate on a virtual box and the frustrum of camera).

All bounding boxes of meshes, that are not in frustrum, is disabled.


There is more feature, see the commented code to see more.


what do you think about that ?

Have a nice day,





Link to comment
Share on other sites

  • 3 weeks later...

Hi @Deltakosh,

I'm almost finished a first version :)

But I have some questions :


1) About FPS average in performanceMonitor class :

I saw that, before 1 seconde, the fps increases like if the average is not good calculated. ( I test it with nothing in my scene )



2) About some textures optimization :

- Is it possible to rescale textures based on a picture without reload a smaller version ?

That will be really powerful for optimization to rescale a texture dynamically.


3) Disable to not render without dispose function.

- Is it possible to disable entities ( textures, particules, ... ) like mesh.isVisible to not render it ?

For exemple, to not render bump.


4) About culling :

- Is culling, or occlusion culling already exist ?


5) About demo :

- How can i share a demo ? On a playground after a commit ?


If some fonctionnalities are not already exist, is it possible to create it ? ( of course, with my help :) ).


I will not include a load system directly in new optimizer class to remplace the old and to not create an extension.

Of course, I will correct AssetManager like mentioned  in the first post ;) .

Thank you in advance for your answer,



Link to comment
Share on other sites


1. Yes the accumulator needs 1s worth of data but you can still rely on https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.performanceMonitor.ts#L56

2. you can use TextureTools.CreateResizedCopy: https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.textureTools.ts

3.You can turn individual channels with these booleans: https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/babylon.standardMaterial.ts#L1419

4.Culling is on by default. You can turn it off with material.backFaceCulling = false. Occlusion queries are coming to webgl2 part of the engine ;)

5.Once your extensions will be in the Extension repo, you will be able to use it in the PG ;)

Link to comment
Share on other sites

Hi @Deltakosh:)

I have some others questions and remarks ...

1) About particules :

     Is it possible to not render particules without 'stop' function ? ( like particulesSystem.isVisible = false )

     The stop function don't stop immediatly the render of particules.

2) About textureTools :

     I have a problem with textureTools.CreateResizedCopy. I need to know if the textures are loaded before to resize ... 

     Here an example of what I'm looking for : https://playground.babylonjs.com/#7BI0R2#2

     EDIT : FOUND : https://playground.babylonjs.com/#7BI0R2#3 ;)

3) About bump textures

     I saw that renderTargetsEnabled disable bump ... So, I think that it's not important to disable bumpTexture for this version.

     EDIT : In fact, it disable diffuseTexture too ... is it normal ?

     EDIT : It's on my side. It's working here : https://playground.babylonjs.com/#95UJ4P :(


Have a nice day,


Link to comment
Share on other sites

hi @Deltakosh :),


I see that 'textureTools.CreateResizedCopy' create a BABYLON.renderTargetTexture if I copy a BABYLON.Texture.

That's why I had a bug with scene.renderTargetEnabled = false ... My texture disappeared ^^

so ... some questions ;) :

1) What's the difference between the both ? ( performance, dynamics/static textures, ... ? )

2) Do you think that will be good to add a condition on 'textureTools.CreateResizedCopy' ?

     If ( instance of renderTargetTexture )

          ... return renderTargetTexture.

     else ( instance of texture )

          ... return texture.


Have a nice day,


Link to comment
Share on other sites

1. I need a RTT to resize the initial texture using shaders. I have no other options. A RTT is just a texture where the content will be defined using a render list of meshes or shaders. perfromance wise a texture is similar to a RTT.

2. Unfortunately as mentioned in 1 I cannot do that. 


Do you have a PG with your initial bug with scene.renderTargetEnabled = false? This is not supposed to break the CreateResizedCopy

Link to comment
Share on other sites

Thanks for your answers, it's clear :)

Here, the playground https://playground.babylonjs.com/#95UJ4P#5

Uncomment the 42th line to see the RTT disappears ;)


- RTT.scale() not working too ...

- Material.DiffuseTextureEnabled = false not disable diffuse channel ... ( same thing with others channels like bump )

- Normally with RTT.scale(), can I scale to 0.5 first and rescale to 1 later without degradations ?


Link to comment
Share on other sites

Hi @Deltakosh :),

Thanks again for all your answers.


I have others problems with renderTargetEnabled and shadows :

     1) Poisson shadow look different if all others shadows type are false...

     2) renderTargetEnabled destroy or make disappear shadows ...

I made a playground for that : https://playground.babylonjs.com/#S3YG63#1 ;)


I hope it's not a big bug ...


Link to comment
Share on other sites

1. this is also expected: when you set a specific shadow to false it actually set the filter to NONE: https://github.com/BabylonJS/Babylon.js/blob/2abd0c332ac26b8fbfa47eaec330f6cc68a955b3/src/Lights/Shadows/babylon.shadowGenerator.ts#L189. I will update this behavior to make it a bit more obvious :)

2. is absolutely expected. Shadows are renderTargets :)


Link to comment
Share on other sites

  • 3 weeks later...

Hi @Deltakosh :)

I did a PR for the new grading scene optimizer : https://github.com/BabylonJS/Extensions/tree/master/gradingSceneOptimizer

I will create the demo when the PR will accepted.

I will do a bigger description for the next post with the demo. I have some questions and comments to do ;).

Have a nice day,


ps : how can I call an extension in a playground ? thanks.

Link to comment
Share on other sites

  • 4 weeks later...

Hi @Deltakosh :)

Sorry for the late post, I have full works at this moment ^^.

I write the doc for the new optimizer here : https://github.com/pierreglibert/Extensions/tree/master/gradingSceneOptimizer

I will do the demo tomorrow and add comments on the next post.

I hope you enjoy.

Have a nice day,


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...