Smart Rendering Mode

Hi,
I was looking into optimizing the # of render calls or CPU utilization in general. In our usecase we don’t have any animations. This means that we would need to perform any redraws only if the camera was moved or the scenegraph changed in any way (including properties of materials and meshes).

I didn’t find any way how Babylon would support smth like that out of the box. My best guess would be now to add all kinds of observables and trigger a redraw based on these callbacks. The problem I discovered so far is just that some of the callbacks are not called as they need a scene.render() call in the first place to be triggered.

Does anyone have a good idea how a smart rendering mode could achieved?

I would suggest to keep it outside the babylon code as it might be simpler to know if anything happens from the experience side.

The only problem would be related to camera interactions which I guess could be “infered” from pointer and keyboard events, @PolygonalSun ?

So is the idea that the canvas would only frames is there’s a change to scene like camera movement? I could potentially see doing something along the lines of having some code in the onInputChangedObservable object to make sure that the rendering is active and setting a timeout to turn it back off once the input is processed. If there’s an active timeout when more input is received, you could just reset the timeout and that might work.

Camera movement alone is obviously not enough. The following cases come to my mind:

  • active camera is changed
  • active camera extrinsics or intrinsics change
  • mesh added to the scene
  • mesh removed from the scene
  • mesh attributes are updated
  • mesh material is changed
  • any uniforms or textures of an active material changes

I’d say these are the usual updates that typically happen. If one needs postprocessing effects then these have to be taken into account as well. We are porting parts of our own C++ render engine to the web and use BabylonJS for that and I was quite surprised that there is no smart render mode.
Do you think that could be interesting for you?

Yes it would be nice to have as long as it does not impact for the performances of the general case which is always a hard balance to find.

This thread shows how to render on camera changed: What is the correct way to render on demand - #28 by vimcaw

But I agree, it would be interesting to be able to track other options, too.

scene has many observables, but I am not sure, if we can track change of attributes. My work around is rather to render only every x frames, which reduces gpu consumptions already by a lot! However, I am unable to track, if there are active animations. Is there a way to figure this out?
I have used scene.onBeforeAnimationsObservable but it triggers always. And when I check objects such as the animated object or scene, they do not seem to store information on i.e. scene.animations. Anyway to track if animations are active?

1 Like

found a way :slight_smile: https://www.babylonjs-playground.com/#9WUJN#1986
scene.animatables is the right place to search for

2 Likes