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.