On-demand rendering solution broken since 5.29

I implemented a simple way to do on-demand rendering: Playground

This used to work up to 5.28 and is broken with 5.29+ (also works with 4.2.1 which is available in the online PG).

Any ideas on how to fix it or a more appropriate approach to do on-demand rendering would be highly appreciated.

Cheers,
Tom

1 Like

It seems it is related to inputs, so let’s summon @PolygonalSun.

1 Like

Just an update, I believe that I found the root cause. Recently, we added an optimization to our inputs that would only pick when necessary. Originally, when we performed a pick, we would also fire a picking ray that would call, through a chain of functions, getViewMatrix(). It’s in here that we call the onViewMatrixChangedObservable observers. Since we’re not picking with every move, we’re not firing that ray and never getting to that point. I believe that the fix is easy but I want to verify that it’s correct and doesn’t affect performance unnecessarily. I’ll let you know when there’s a PR live.

1 Like

@PolygonalSun , thanks a lot for looking into this issue.

As I said, I’m also open to better ideas to avoid idle rendering. We run a medical software on compact, fan-less hardware and I’m afraid of thermal throttling when the iGPU is busy all the time.

Independent from picking or not (it’s a good thing that you avoid unnecessary picking): Shouldn’t any change to the view matrix (e.g. rotating including momentum-based rotation) call all view matrix observers?

I’m not familiar with the internals of course, just going by the function names.

In the code originally, we generally updated the view matrix with each rendered frame or if there was some camera movement with a PointerInfo object. Technically, this should be decoupled from the picking/pointer info and added to the camera.update function (assuming there was pending movement for a camera). I am looking into how best to do without adversely affecting performance but I did think of a slight workaround that could work for you in the meantime:

function render() {
        camera.update()
       // In your render loop, you could check for pending camera movements and call
       // the function below to update everything.
        if (camera.inertialAlphaOffset !== 0 || 
            camera.inertialBetaOffset !== 0 ||
            camera.inertialRadiusOffset !== 0 ||
            camera.inertialPanningX !== 0 ||
            camera.inertialPanningY !== 0
        ) {
            scene.updateTransformMatrix();
        }
        if (dirty > 0) {
            console.log("RENDER");
            scene.render(false);
            dirty--;
        }
    }

You could also simplify this further by using that camera change criteria to directly call the render function (which has a function that calls the updateTransformMatrix (ultimately calling the onViewMatrixChangedObserverable)

function render() {
        camera.update()
        if (camera.inertialAlphaOffset !== 0 || 
            camera.inertialBetaOffset !== 0 ||
            camera.inertialRadiusOffset !== 0 ||
            camera.inertialPanningX !== 0 ||
            camera.inertialPanningY !== 0
        ) {
            console.log("RENDER");
            scene.render(false);
        }
    }

I’m not sure if this will work for your specific use case but I wanted to give you a couple of options to unblock you while I work on this.

NOTE: Those 5 inertial values are only applicable to the ArcRotateCamera. The other cameras use cameraRotation and cameraDirection.

1 Like

Sorry for the late reply, but I was travelling. Thanks a lot for the detailed proposals. I’ll have a look at both, but after Christmas. :santa:

Have a great holiday! Thank your so much for Babylon and the 1st class support! :pray:

2 Likes

To make your proposal work, I had to add another dirty++; after

Thanks a lot for the workaround.
I think we would both love to see a better solution. :wink:

Hey @7om,

Sorry about the time that this took but I have a tentative fix that I’m running by the team now. If there are no issues with it, I should be able to create a PR fix that should restore the initial functionality. I’ll give you an update once I hear back about my fix.

1 Like

Fix is in PR: Camera: Add code to update View and Projection Matrices in update function by PolygonalSun · Pull Request #13552 · BabylonJS/Babylon.js (github.com)

3 Likes

PR is merged

1 Like