Getting Unrecognized sampler 'sampler_base_texture' error from shader

I have a simple shader graph shader that calls a function from a node to do some lighting. The shader works but I get errors in the console:

Shader error in 'Shader Graphs/Master': Fragment program 'frag': Unrecognized sampler 'sampler_base_texture' - does not match any texture and is not a recognized inline name (should contain filter and wrap modes).
at line 1466 (on d3d11)

Which is caused by this line in my HLSL code:

    normal = UnpackNormal(SAMPLE_TEXTURE2D(_Normal_Map, sampler_Normal_Map, uv));

Reading various threads from people with similar issues this seems to come down to the compiler thinking the Normal Map is not used and removing it. But the shader works fine in the editor, the normals work as expected, so why am I getting this error when the shader works and how do I stop the error?

The error says it’s not complaining about the normal map - the resulting shader doesn’t seem to use something that’s called “base_texture”

Well yes, but the fact remains if that line is removed then the error goes away. There is a texture called _Base_Texture and the sampler is used all over the place in the rest of the shader.
If you can explain why removing that line stops the error about sampler_base_texture and why even though there is an error the shader compiles and works?

A few lines above where the error is happening sampler_base_texture is used:

    c = SAMPLE_TEXTURE2D(_Blend_4, sampler_Base_Texture, uv);
    maincol.rgb = lerp(maincol.rgb, c.rgb, blend.a * c.a);
    smooth = lerp(smooth, _Blend_4_Smoothness, blend.a * c.a);    // smoothness blends could be in one vector4

    // Smoothness
    smoothness = smooth * _Smoothness;    //1.0;    // - SAMPLE_TEXTURE2D(_SmoothnessTex, sampler_Clear_Texture, Uv).r;

    // Metallic
    metallic = 0.0;    //SAMPLE_TEXTURE2D(_Metal_Texture, sampler_Clear_Texture, Uv).r;

    normal = UnpackNormal(SAMPLE_TEXTURE2D(_Normal_Map, sampler_Base_Texture, uv));   // * 2 - 1;

That still gives an error about about unrecognized sampler_base_texture. So how is that possible?

I don’t see anything actually using base_texture in the code you pasted. Only the sampler.

    float4 maincol = SAMPLE_TEXTURE2D(_Base_Texture, sampler_Base_Texture, uv);

    float smooth = maincol.a;

    float4 c = SAMPLE_TEXTURE2D(_Blend_1, sampler_Base_Texture, uv);
    maincol.rgb = lerp(maincol.rgb, c.rgb, blend.r * c.a);
    smooth = lerp(smooth, _Blend_1_Smoothness, blend.r * c.a);

    smooth = lerp(smooth, _Blend_4_Smoothness, blend.a * c.a);    // smoothness blends could be in one vector4

    // Smoothness
    smoothness = smooth * _Smoothness;

    // Metallic
    metallic = 0.0;    //SAMPLE_TEXTURE2D(_Metal_Texture, sampler_Clear_Texture, Uv).r;

    normal = UnpackNormal(SAMPLE_TEXTURE2D(_Normal_Map, sampler_Base_Texture, uv));   // * 2 - 1;
 
    // final color
    color.rgb = maincol.rgb;
    color.a = 0;

    // Adjust normal for normal amount
    normal = float3(normal.xy * _Normal_Amount, lerp(1, normal.z, saturate(_Normal_Amount)));
   
    // fresnel
    fresnel = SHADERGRAPH_REFLECTION_PROBE(viewDir, norm, 0);
    fresnel *= pow((1.0 - saturate(dot(norm, viewDir))), _Rim_Power) * _Rim_Amount;    //_Fresnel_Power);    //fpow);    //_Fresnel_Power);

It is used, as I said the shader works, so clearly the base texture is being read and output as the color, so again the question is why is it saying that sample_base_texture is unrecognised when it is clearly being used, the base_texture is being used and the shader works in the editor.

for info only
that error could be commonly found due to a missing SS sampler state macro.

But the sampler it complains about is there and being used, the shader works and works as expected, I have done hundreds of shaders in my time and this is the first time I have ever come across this problem. If I change the line with UnpackNormal to say normal = 0; then the error goes away. It is clearly a bug.

The error could come from the DepthNormals pass where the _BaseTexture is not actually used. This usually throws errors only on build and not in editor.

As a quick test try to multiply the sampled abledo by 0 (to have 0 effect) and add it to your normal (to be sure the sampler exists).

I gave up on using and reusing samplers from textures a long time ago, because unity adds a few new samplers per year for various effects and you quickly run out of them when using multiple textures. Even some unity shaders have this issue.

Instead I use the albedo sampler as is, and use RepeatBilinear/clamp/etc dependign on the case for the rest. Hope it helps.

If it doesn’t contribute to the final output, the compiler will optimizes the base_texture and won’t report that it’s used.

It does contribute, its goes into the color value which is an out from the method that is connected up in the shader graph. Color, normal, fresnel, smooth and metallic are all outputs. And I see the texture on the object, so I think that indicates that it is being used if the texture shows up on the object?

void Track_float(float2 Uv, float3 norm, float3 viewDir, float3 tanViewDir, out float4 color, out float3 normal, out float smoothness, out float metallic, out float3 fresnel)

That is basically what I am doing just using the sampler_Base_Texture for everything but Unity keeps giving the error that it can’t find it even though the shader works.