Question about AdvancedDynamicTexture

Hi team,

I’m trying on thie PG to implement a joystick controller to drive the avatar walking.

the joystick puck attach to a AdvancedDynamicTexture, when I touch and update the punk Ellipse, it triggers the update() function of _checkUpdate() in AdvancedDynamicTexture.js

I measure the execution time on the Iphone12pro, it takes 50ms for update() function,

I got two troubles here:

  1. where is the update() implementation, I cannot trace from the AdvancedDynamicTexture script.
  2. why it costs much time when update() is triggered, does it have any default settings to save the time?

thank you in advance for your help

Cc @PolygonalSun

Since AdvancedDynamicTexture inherits from DynamicTexture and has no overridden version of update(), it’s probably using DynamicTexture’s version (dynamicTexture.ts, lines 149-159). This will then call updateDynamicTexture, which is added using prototype in engine.dynamicTexture.ts. Since there are two versions (WebGPU and WebGL?), I’m going to assume that the non-WebGPU version is being used.

As far as default settings to speed things up, I’m not really seeing anything that stands out to me (maybe you have an idea @sebavan or @Evgeni_Popov?)

1 Like

The update might take a long time due to either the frequency of it being called or the size of the canvas you use for the dynamic texture ? Basically every time something happens you are drawing in a canvas 2d then copying it on the GPU to render full screen.

In case of controls like such I would advice to try and rely on WebGL only on maybe a second orthographic camera rendering only meshes looking like your shapes ?


A couple of things:

  1. updateDynamicTexture does have a allowGPUOptimization parameter which is by default false. You could experiment with overwriting the ADT’s update method to call updateDynamicTexture with this parameter set to true, and see if that makes a difference.
  2. You can try limiting the update calls to something like 10/second. This will result in a less responsive GUI but your framerate overall will be improved.

Thank you for your reply, I tried allowGPUOptimization and different canvas size with different devicePixelRatio with setHardwareScalingLevel the time changes. The most obvious influence on the update might be the size of canvas. the PG call the CreateFullscreenUI and have higher resolution on the device, so is there any approach to minimize the CreateFullscreenUI texture size without decrease the resolution of the canvas?

Just an odd idea, but what about create for plane instead of FS and use a second camera. Would that avoid rendering the FS canvas because of the AdvancedTexture? I really don’t know but it might be worth giving it a try?

1 Like

Hi just checking in, was your question answered? @RavenLee