Runtime texture image downscaling for improving memory usage

Hi forum,

I have 3D models that perform fine in most of the devices, they require 500MB of memory. To get better performance on mobiles, I would like to reduce the memory allocation to 200MB or less. I manually generate several versions of these models for each device type to accomplish better performance, but in some cases, I would like to reduce texture images in runtime in order to fit device needs.

I thought I could downscale the loaded textures in runtime, by example from 2048x2048 to 512x512 when needed.

Which would be the best way to reduce texture images in runtime? The 3D models are gltf and the source images are png and jpg.

Thanks!

1 Like

Hi everybody,

Here is how I have figured it out in case somebody else is looking for a possible solution.

Once the 3D models are loaded, I traverse all the objects looking for materials and their textures. For each texture, I override the image property by one rescaled down. Yes, I mutate the texture object. Since the 3D models are not added yet to the scene seems that they can be updated without side effects.
In addition to the image, the size properties must also be updated for the new ones.

Thanks

1 Like

May I know how do you reduce the texture resolution?

a. You are replacing the image with an existing image file (at lower res).
b. You generate a lower resolution image on runtime using canvas.

I have done B, but A would work better if the asset is available.

1 Like