Coloring lot of people by object position via shader for batching

hi)
i create shader for coloring static people. a lot. material with this shader must be bathing, cause all materials of my people has similar properties. but…

in Scene view all looks like great. in Game view all objects has one color =(


what’s my problem? what am I doing wrong?
i use Unity 2018.3.14f1
shader code:

Shader "Custom/MaskedColorPeopleView"
{
    Properties
    {
        _Tex1 ("Albedo (RGB)", 2D) = "white" {}

        _NoiseMap ("Albedo (RGB)", 2D) = "gray" {}

        _SkinGrad ("Albedo (RGB)", 2D) = "white" {}
        _ClothGrad ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "Queue" = "Transparent" "RenderType"="Opaque" "PreviewType"="plane"}
        LOD 200
    
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
    
            #include "UnityCG.cginc"
    
            sampler2D _Tex1;
            sampler2D _NoiseMap;
            sampler2D _SkinGrad;
            sampler2D _ClothGrad;

            struct Input
            {
                float2 uv_MainTex;
                float4 objPos;
            };
    
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
                float4 worldPos : COLOR;
            };
        
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                o.worldPos = mul(unity_ObjectToWorld, float4(0,0,0,1));
                return o;
            }
        
            fixed4 frag (v2f i) : SV_Target
            {
                float3 pos = fmod(abs(i.worldPos / 10), fixed3(1,1,1));
                fixed4 noiseMap = tex2D(_NoiseMap, float2(pos.r, pos.b));
            
                fixed4 tex1 = tex2D(_Tex1, i.uv);

                fixed4 skinColor = tex2D(_SkinGrad, float2(noiseMap.r, 0.5)) * tex1.r * tex1.g;
                fixed4 shirtColor = tex2D(_ClothGrad, float2(noiseMap.g, 0.5)) * tex1.r * tex1.b;
                fixed4 pantsColor = tex2D(_ClothGrad, float2(noiseMap.b, 0.5)) * tex1.r * tex1.a;

                fixed4 col = skinColor + shirtColor + pantsColor;
                col.a = 1;
                return col;
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

аssets in attachments.
PS: I hope I will not be banned … I just create spectators in my game…

4505620–416347–PeopleView.zip (1.55 MB)

I suspect your objects are being combined by static batching.
In this case Unity will combine those objects into 1 which will mess up your position data.

can test it by adding this inside Tags {}

"DisableBatching"="True"

Yep, the propblem in batching… idea for perfomance, but perfomanse will destroy idea) thanks)

Posting this 2.5 years later, but I think it’s important to note
You can actually get both performance benefits of batching and your object position-depending shader working.

Instead of using object’s position (unity_ObjectToWorld in shader code or “Object” node in SRP Shader Graph) you need to use vertex data (v.vertex in shader code or “Position” node in SRP Shader Graph).
I use Shader Graph and it worked for me. I believe batching preserves original vertices positions (or maybe changes, but still preserves the difference of different vertex positions). Otherwise, nothing would render correctly at all

Yes, you do not use object position directly, but if you’re looking for differentiating objects based on their position, vertex data should be good enough