Undeclared Identifier

Hello,
I’m still just a beginner when it comes to shaders, but managed to modify a shaderforge texture to do what i wanted it to do - swap colours so that I could do old-school palette swapping on sprites. And it worked beautifully.
But recently I wanted to do some modifications to it, and managed to break it… simply by adding more identifiers and trying to reference them.
I was confused since I had the identifiers declared at the top of the shader, along with the ones that did work. So I tried renaming the existing identifiers that did work and suddenly those didn’t work anymore either. I’m stumped.

So here’s the shader below, and the error is on line 98, undeclared identifier _CompareBG

Shader "NES_DualSprite" {
    Properties {
        [PerRendererData]_MainTex ("MainTex", 2D) = "white" {}
        _Color ("Color", Color) = (1,1,1,1)
        _CompareBG ("Compare Background", Color) = (0.5,0.5,0.5,1)
        _CompareBright ("Compare Bright", Color) = (0.5,0.5,0.5,1)
        _CompareMid ("Compare Mid", Color) = (0.5,0.5,0.5,1)
        _CompareDark ("Compare Dark", Color) = (0.5,0.5,0.5,1)
        _ColorBG ("Color Background", Color) = (1,1,1,1)
        _ColorBright ("Color Bright", Color) = (0.5,0.5,0.5,1)
        _ColorMid ("Color Mid", Color) = (0,0,0,1)
        _ColorDark ("Color Dark", Color) = (0,0,0,0)
               
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        _Stencil ("Stencil ID", Float) = 0
        _StencilReadMask ("Stencil Read Mask", Float) = 255
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilComp ("Stencil Comparison", Float) = 8
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilOpFail ("Stencil Fail Operation", Float) = 0
        _StencilOpZFail ("Stencil Z-Fail Operation", Float) = 0
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
            "CanUseSpriteAtlas"="True"
            "PreviewType"="Plane"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            ZWrite Off
           
            Stencil {
                Ref [_Stencil]
                ReadMask [_StencilReadMask]
                WriteMask [_StencilWriteMask]
                Comp [_StencilComp]
                Pass [_StencilOp]
                Fail [_StencilOpFail]
                ZFail [_StencilOpZFail]
            }
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #pragma multi_compile _ PIXELSNAP_ON
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase
            #pragma only_renderers d3d9 d3d11 glcore gles
            #pragma target 3.0
            uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
            uniform float4 _Color;
            uniform float4 _ColorA;
            uniform float4 _ColorB;
            uniform float4 _ColorC;
            uniform float4 _ColorD;
            uniform float4 _CompareA;
            uniform float4 _CompareB;
            uniform float4 _CompareC;
            uniform float4 _CompareD;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 vertexColor : COLOR;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.vertexColor = v.vertexColor;
                o.pos = UnityObjectToClipPos( v.vertex );
                #ifdef PIXELSNAP_ON
                    o.pos = UnityPixelSnap(o.pos);
                #endif
                return o;
            }
            float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
                float isFrontFace = ( facing >= 0 ? 1 : 0 );
                float faceSign = ( facing >= 0 ? 1 : -1 );


                float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
                float3 original_RGB = (_MainTex_var.rgb*_Color.rgb*i.vertexColor.rgb); // RGB
               
                float RGB_is_BG = ( step(original_RGB,_CompareBG.rgb) == step(_CompareBG.rgb,original_RGB) ? 1 : 0);
                float RGB_is_Bright = ( step(original_RGB,_CompareBright.rgb) == step(_CompareBright.rgb,original_RGB) ? 1 : 0);
                float RGB_is_Mid = ( step(original_RGB,_CompareMid.rgb) == step(_CompareMid.rgb,original_RGB) ? 1 : 0);
                float RGB_is_Dark = ( step(original_RGB,_CompareDark.rgb) == step(_CompareDark.rgb,original_RGB) ? 1 : 0);
           
                float original_alpha = (_MainTex_var.a*_Color.a*i.vertexColor.a);
               
                if (RGB_is_BG == 1) { return fixed4(_ColorBG.rgb, original_alpha); }
                if (RGB_is_Bright == 1) { return fixed4(_ColorBright.rgb, original_alpha); }
                if (RGB_is_Mid == 1) { return fixed4(_ColorMid.rgb, original_alpha); }
                if (RGB_is_Dark == 1) { return fixed4(_ColorDark.rgb, original_alpha); }
           
                if (RGB_is_BG == 0 && RGB_is_Bright == 0 && RGB_is_Mid == 0 && RGB_is_Dark == 0) { return fixed4(_ColorD.rgb, 0); }
                return fixed4(original_RGB, original_alpha);
            }
            ENDCG
        }
        Pass {
            Name "ShadowCaster"
            Tags {
                "LightMode"="ShadowCaster"
            }
            Offset 1, 1
            Cull Off
           
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_SHADOWCASTER
            #pragma multi_compile _ PIXELSNAP_ON
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcaster
            #pragma only_renderers d3d9 d3d11 glcore gles
            #pragma target 3.0
            struct VertexInput {
                float4 vertex : POSITION;
            };
            struct VertexOutput {
                V2F_SHADOW_CASTER;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.pos = UnityObjectToClipPos( v.vertex );
                #ifdef PIXELSNAP_ON
                    o.pos = UnityPixelSnap(o.pos);
                #endif
                TRANSFER_SHADOW_CASTER(o)
                return o;
            }
            float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
                float isFrontFace = ( facing >= 0 ? 1 : 0 );
                float faceSign = ( facing >= 0 ? 1 : -1 );
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

You need to add a declaration near the other uniforms.
uniform float4 _CompareBG;

1 Like

I feel dumb now, I kept on scrolling past that area and never looked at it.
Thank you!