Texture with frequent source changes (video, image, canvas, etc)

We have some meshes in our project that have frequent source changes (think television screen with the channels changing between images, videos and dynamic canvases). Would there be any performance gain to us writing our own texture class that is a combination of the existing texture classes like VideoTexture, HTMLElementTexture, etc.

We have been studying some of the underlying classes and can see, for example, the video texture when switching from a poster to the video just creates a new texture within the class and updates it in the engine. Not sure the exact under the hood mechanism, but somehow materials must know of this change in texture.

Would this approach to creating a custom texture type that switches between various sources (image, video, canvas, etc) have any advantage over just constantly swapping out the texture on a material to one of the existing texture types?

i.e is there any performance difference between
myMat.texture = mySpecialNewTextureTypeThatHandlesMultipleSourceTypes

vs

myMat.texture = builtInBabylonTextureTypesButIamChangingThisPropertyOften

I believe that the built-in Babylon way to deal with textures would be more performant just because there will be less extra code for the same task.
There is also Asset Manager | Babylon.js Documentation which helps to load different types of assets with callbacks onSuccess and onError.
Or just create an array and put all textures there, then show/load them on demand (there is may be no need to load a video for videotexture since you can stream it).

2 Likes

Hey @Vandy!

Maybe it’s worth to look at the new feature for fast material switching introduced in BJS5:

3 Likes