Shared Texture Loading for glTF/GLB Tiles?

Hi,

In Cesium for Unity, if multiple glTF or GLB tiles reference the same texture via external URL, is that texture loaded once and shared, or is it loaded separately for each asset?

Regards,

@jqntn In short: no, it’s loaded separately per asset, but we’d like to change that. The basis for implementing this exists in Cesium Native and is used in Cesium for Unreal, but currently Cesium for Unity lacks the necessary implementation to make it work. The shared asset system should make sure textures are only downloaded once, as long as they remain in the inactive asset cache (though this limit is set to only 16MiB), but the same texture will be created on the GPU once for every time it’s used.

Unfortunately, implementing this in Unity is a big task. You can take a look at the PR to implement it in Unreal to get an idea. The basic gist is that every time we create a texture from an ImageAsset, we need to hold on to the reference to that ImageAsset until the texture is released so that we can make sure to keep the texture “active.” Every time we create a new texture, we need to see if we already have a texture created for that ImageAsset and use that instead if possible. The real hard part is this all needs to be done without any race conditions, ensuring that we don’t accidentally create two textures from the same ImageAsset - even if another thread has already started creating a texture from that ImageAsset but hasn’t yet finished.

It’s definitely doable though if you’d like to give it a try!

1 Like

Hi @azrogers,

Thank you for the detailed explanations; they are very much appreciated.

Best regards

I opened a GitHub issue for this here, though I don’t have an estimate for when we’ll address it. But to echo what @azrogers mentioned, we’re always open to community contributions :smile:

1 Like