Cloning Materials and maxTextureImageUnits

My understanding is that a graphics card has a maximum number of texture units. When a texture is cloned, it seems as though that should use up a texture unit, but that doesn’t seem to be the case, as we’re not running out of slots. Is there some documentation about how many CLONED textures we can load?

A slot is used only when a texture is used in a shader: the maxTexturesImageUnits is the maximum number of textures you can use in a shader at once.

You can create/clone textures as much as you want (limited by the RAM you have, however).

Thanks! Just to dig a little deeper, if I load a GLTF which has 50 meshes, and each mesh has a PBR texture, and each of those textures is cloned, then shouldn’t I be using:

  1. 3 texture units per mesh
  2. 150 total COMBINED texture units, which WebGL Report says is more slots than I have?

I’m asking this because I’m trying to understand how to calculate how many total meshes I can load if each one has a PBR texture, as per a specific graphics card.

The number of slots you have available is per draw call, it’s not a global value for all of your meshes.

So, as long as your shader does not use more textures than the number of available slots you are ok. A PBR shader can use lots of textures if you enable all effects, but basically it uses:

  • BRDF texture
  • reflection texture
  • albedo texture
  • normal texture
  • metallic/roughness texture

So it’s 5 textures. If you use AO, it’s one more texture, if you use clear coat texture, again one more, and so on. I think WebGL 2 guarantees you have at least 8 slots available, and most of the GPU have more (16). So, except if you enable a lot of effects in the PBR (clear coat, sheen, refraction, …), you will be ok even with the default minimum number of slots.


So then my confusion is around gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS)

Does this mean that each mesh gets its own draw call and therefore won’t exceed the total image slots?

Yes indeed. You will exceed the max only if you are using shaders that are using more than MAX_COMBINED_TEXTURE_IMAGE_UNITS textures.

1 Like