<blockquote>
<p>I want to avoid making shader variations just for texture types.</p>
</blockquote>
<p>Then you should rethink that decision.</p>
<p>Skybox rendering is so rare compared to rendering everything else that having a separate shader specifically for that has negligible costs.</p>
<p>And there's really no reason not to just make everything else an array texture, even if there is only one array layer in most of them.</p>

CC BY-SA 4.0
2022-11-06T04:17:41.110Z
2022-11-06T04:17:41.110Z
Nicol Bolas
<p>I use uber-shader approach and am having issues fitting within 16 texture units.</p>
<p>My material uses 3 textures: albedo, special, and normal map.
However, any of these textures can be regular 2D, or 2D array (eg. for animations), or Cube maps (eg. for skyboxes). Therefore, I have 9 samplers in my shader, even if I only use 3 of them.</p>
<p>Similar issue applies to shadow maps.</p>
<pre><code>layout(binding = CAGE_SHADER_TEXTURE_ALBEDO) uniform sampler2D texMaterialAlbedo2d;
layout(binding = CAGE_SHADER_TEXTURE_ALBEDO_ARRAY) uniform sampler2DArray texMaterialAlbedoArray;
layout(binding = CAGE_SHADER_TEXTURE_ALBEDO_CUBE) uniform samplerCube texMaterialAlbedoCube;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL) uniform sampler2D texMaterialSpecial2d;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL_ARRAY) uniform sampler2DArray texMaterialSpecialArray;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL_CUBE) uniform samplerCube texMaterialSpecialCube;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL) uniform sampler2D texMaterialNormal2d;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL_ARRAY) uniform sampler2DArray texMaterialNormalArray;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL_CUBE) uniform samplerCube texMaterialNormalCube;
layout(binding = CAGE_SHADER_TEXTURE_SSAO) uniform sampler2D texSsao;
layout(binding = CAGE_SHADER_TEXTURE_SHADOWMAP2D0) uniform sampler2D texShadows2d[CAGE_SHADER_MAX_SHADOWMAPS2D];
layout(binding = CAGE_SHADER_TEXTURE_SHADOWMAPCUBE0) uniform samplerCube texShadowsCube[CAGE_SHADER_MAX_SHADOWMAPSCUBE];
</code></pre>
<p>I have read that it is valid to have different textures bound to same texture unit if they are different targets, but it is not valid to use them for sampling.</p>
<p>I want to avoid making shader variations just for texture types.</p>
<p>What other possibilities are there that may help with this?</p>
<p>Thanks</p>

CC BY-SA 4.0
2022-11-08T11:48:54.190Z
There are many techniques to get around texture unit limits, why not use one of those?
pmw1234
CC BY-SA 4.0
2022-11-09T12:12:13.127Z
@pmw1234 can you be more specific please?
Tomas
CC BY-SA 4.0
2022-11-09T14:51:35.317Z
like using arrays for everything as the answer suggests
pmw1234
<glsl><texture>
combinatoric explosion of sampler2D, sampler2DArray, samplerCube
Tomas
# combinatoric explosion of sampler2D, sampler2DArray, samplerCube

(Asked by: username_0 on 2022-11-05)

I use uber-shader approach and am having issues fitting within 16 texture units.

My material uses 3 textures: albedo, special, and normal map.
However, any of these textures can be regular 2D, or 2D array (eg. for animations), or Cube maps (eg. for skyboxes). Therefore, I have 9 samplers in my shader, even if I only use 3 of them.

Similar issue applies to shadow maps.

```
layout(binding = CAGE_SHADER_TEXTURE_ALBEDO) uniform sampler2D texMaterialAlbedo2d;
layout(binding = CAGE_SHADER_TEXTURE_ALBEDO_ARRAY) uniform sampler2DArray texMaterialAlbedoArray;
layout(binding = CAGE_SHADER_TEXTURE_ALBEDO_CUBE) uniform samplerCube texMaterialAlbedoCube;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL) uniform sampler2D texMaterialSpecial2d;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL_ARRAY) uniform sampler2DArray texMaterialSpecialArray;
layout(binding = CAGE_SHADER_TEXTURE_SPECIAL_CUBE) uniform samplerCube texMaterialSpecialCube;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL) uniform sampler2D texMaterialNormal2d;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL_ARRAY) uniform sampler2DArray texMaterialNormalArray;
layout(binding = CAGE_SHADER_TEXTURE_NORMAL_CUBE) uniform samplerCube texMaterialNormalCube;
layout(binding = CAGE_SHADER_TEXTURE_SSAO) uniform sampler2D texSsao;
layout(binding = CAGE_SHADER_TEXTURE_SHADOWMAP2D0) uniform sampler2D texShadows2d[CAGE_SHADER_MAX_SHADOWMAPS2D];
layout(binding = CAGE_SHADER_TEXTURE_SHADOWMAPCUBE0) uniform samplerCube texShadowsCube[CAGE_SHADER_MAX_SHADOWMAPSCUBE];

```

I have read that it is valid to have different textures bound to same texture unit if they are different targets, but it is not valid to use them for sampling.

I want to avoid making shader variations just for texture types.

What other possibilities are there that may help with this?

Thanks

**Tags:** glsl, texture

> **Comments:**
> **username_1**: There are many techniques to get around texture unit limits, why not use one of those?  
> **username_0**: @username_1 can you be more specific please?  
> **username_1**: like using arrays for everything as the answer suggests  

---

## 1 answers

### Answer by username_2 on 2022-11-06. Score: 1

> I want to avoid making shader variations just for texture types.

Then you should rethink that decision.

Skybox rendering is so rare compared to rendering everything else that having a separate shader specifically for that has negligible costs.

And there's really no reason not to just make everything else an array texture, even if there is only one array layer in most of them.


---

