0
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ There are many techniques to get around texture unit limits, why not use one of those? $\endgroup$
    – pmw1234
    Commented Nov 8, 2022 at 11:48
  • $\begingroup$ @pmw1234 can you be more specific please? $\endgroup$
    – Tomas
    Commented Nov 9, 2022 at 12:12
  • $\begingroup$ like using arrays for everything as the answer suggests $\endgroup$
    – pmw1234
    Commented Nov 9, 2022 at 14:51

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.