Why does a difference in variable names in the Standard Surface Shader lead to different results?

The variable worldPos and worldPos1 giving me different results.

Shader "Custom/point_shader"
{
    Properties
    {
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Color1 ("Color 1", Color) = (1,0,0,1) // Red
        _Color2 ("Color 2", Color) = (0,1,0,1) // Green
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" }

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0 // Explicitly set target shader model

      
        // Declare properties
        half _Glossiness;
        float4 _Color1, _Color2;
        float _Value;

        struct Input {
            // it cant be empty
            //float3 worldPos1 : WORLD_POSITION;
            float3 worldPos : WORLD_POSITION;
            float3 normal : NORMAL;
            float2 uv_MainTex; 
        };

        void surf(Input input, inout SurfaceOutputStandard o) {

          

            // Use the normal components to set Albedo
            o.Albedo.rg = input.worldPos.xy * 0.5 + 0.5;
            //o.Albedo.rg = input.worldPos1.xy * 0.5 + 0.5;
            o.Smoothness = _Glossiness;
            //o.Smoothness = _Smoothness;
        }

        ENDCG
    }

    Fallback "Diffuse"  // always need for surface shaders
}

Because the surface shader analyser doesn’t check the semantic (WORLD_POSITION) - it does string comparison for the name of the variable on the Input struct.

  • input.worldPos is automatically handled by Unity in Surface Shaders.
  • If you manually declare worldPos1, it won’t be automatically interpolated unless explicitly set in a VertexFunction.
  • For consistency, if you need manual control, compute the world position in a vertex function and pass it to Input.

Rohit
Wellness Hub