Single material with an array of sampler2D textures vs multiple materials

Godot Version

Godot 4.4.1

Question

I have around 100 meshes (people) that are basically the same, but they each have a different texture. They will not be shown at the same time, maybe 1-3 people at the same time at most.

I was wondering if having a single material with an array of sampler2D textures, and then a per-instance uniform for the index would be ideal or a material for each person would work better.

My question is more in terms of performance, since the target is mobile. I don’t know if having an array of sampler2D textures would make it so that all of them are loaded when the material is loaded, or if the texture at a given index is loaded until it’s actually used.

Each texture is 2048x2048 so it would be awful to load ~100 images at once when the material is loaded. I would test this, but I don’t even know how to test it without creating the 100-textures material, and then what would I even look for (VRAM usage?)

Thank you in advance!

1 Like

To answer my own question:

I created a small test project using only 5 images, and the results were:

test single sampler2d sampler2d array
Video Memory 232.5 MiB 439.8 MiB
Texture Memory 94.52 MiB 173.8 MiB
Time to load ~70ms ~192ms

So it seems like having a separate material per mesh is actually better. One thing to note is that there is no difference in performance if I change the “texture index” at runtime when using the sampler2d array, which suggests all the images are already loaded.

Please correct me if I’m wrong in my conclusion though.