Maximum ps_4_0 sampler register index (16) exceeded? How to get around having too many textures?

Since you’re using target 4.0, you should be able to define textures separately from samplers, cutting down on your sampler usage. Unity has macros to make this easier (since different platforms do it differently and it will handle that for you).

Use UNITY_DECLARE_TEX2D(_SomeTexture); to declare a texture and a sampler. And for all other textures that will share a sampler, define them as UNITY_DECLARE_TEX2D_NOSAMPLER(_SomeOtherTexture);
Then you can sample them with UNITY_SAMPLE_TEX2D(_SomeTexture, someTextureUV); and UNITY_SAMPLE_TEX2D_SAMPLER(_SomeOtherTexture, _SomeTexture, someTextureUV);

UNITY_DECLARE_TEX2D(_MainTex);
UNITY_DECLARE_TEX2D_NOSAMPLER(_SomeOtherTex);

struct Input
{
    float2 uv_MainTex;
}

void surf (Input IN, inout SurfaceOutputStandard o)
{
    float2 uvMain = IN.uv_MainTex;
    float4 col = UNITY_SAMPLE_TEX2D(_MainTex, uvMain);
    float4 someOtherCol = UNITY_SAMPLE_TEX2D_SAMPLER(_SomeOtherTex, _MainTex, uvMain);
}

UNITY_SAMPLE_TEX2D_SAMPLER is basically saying “Use the sampler from this other Texture Object”.

1 Like