Advanced Dynamic Texture for Mesh: CheckUpdate depending on Camera?

Hi,

In my scene I have an ADT attached to a mesh and I have multiple cameras rendering the scene. Checking in the performance monitor on Dev Tools I can see that the ADT render is being called for each camera, which I would like to turn off as the ADT only needs to be rendered once (and it is taking >15ms per render). I can see in the source code that if I have a fullscreen ADT thejn I can prevent the render by using layers so that _checkUpdate returns without rendering however there doesn’t seem to be a way to do this when using ADTs for mesh. The relevant code in ADT._CheckUpdate is

    if (this._layerToDispose) {
        if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
            return;
        }
    }

and _layerToDispose is only set when using a fullscreen ADT.

When I render with subsequent cameras I can call scene.render(false, true) to ignore animations/physics but the ADT still updates. Ideally the ADT would also not update if ignoreAnimations is true but failing that a way to specify whether the ADT should update for the current camera would be good. Is there a way to achieve this? Perhaps removing the ADT._renderObserver and then re-adding it? Or clearing it and replacing it with an observer that checks the camera first then calls _checkUpdate if required? Or is there another way to global prevent ADTs from updating?

Removing the observer and adding your own one that would check the camera before calling _checkUpdate is probably the best thing to do. However, I don’t understand why the ADT would be updated for each camera, because once it is updated for the first camera, the isDirty flags should be reset to false and we should not reach the code that render/update the texture:

private _checkUpdate(camera: Camera): void {
    [...]
    if (!this._isDirty && !this._rootContainer.isDirty) {
        return;
    }
    this._isDirty = false;
    this._render();
    this.update(this.applyYInversionOnUpdate, this.premulAlpha);
}

(the call to this._render() should reset the this._rootContainer.isDirty flag).

Ah, interesting. I will check tomorrow and see if something is triggering isDirty.
Thanks.

Update: Ok, I had a scene.onBeforeRenderObservable that was setting some text on the ADT which meant the ADT was always dirty. Wrapping the update of the text inside a conditional check helps but it will still hit twice when that condition is met. I will need to refactor the ADT somehow, at least I know where the issue is and need to be cautious when updating ADT on before scene render.

Also related, the first camera render is triggering an ADT.render which also fires a few container layouts. This is when I don’t think anything should have changed. The render from the second camera is respecting the isDirty and so ADT.render is not called and the layout is not recalculated. I suspect if I check isDirty on the first camera it will be dirty (when it shouldn’t be) so perhaps somehow the containers are triggering a dirty state. The ADT has a couple of sliders and stack panels. Again, following my previous comment, it might be time to refactor my ADT layout.

It does seem that ADT.render is an expensive operation.