Interpolator ... not interpolating?

Hi!
I wrote a shader that basically generates quads, I have one interpolator that represents the distance to the centre of the quad but I see on the fragment shader that it has the value “of the vertex” and it´s not been interpolated. Here the code:

Shader "Unlit/ParticleShader"
{
    Properties
    {
    }
    SubShader
    {
        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            ZWrite Off
            ZTest Always
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.5
            #include "UnityCG.cginc"

            struct Particle
            {
                float4 Position;
                float2 Velocity;
            };
            StructuredBuffer<Particle> uParticles;

            struct appdata
            {
                uint vid : SV_VertexID;
            };
            struct v2f
            {
                float4 vertex    : SV_POSITION;
                float distCent    : TEXCOORD2;
            };
           
            v2f vert (appdata v)
            {
                v2f o;
                uint fetchId            = v.vid / 6;
                Particle tmpParticle    = uParticles[fetchId];
               
                float3 quad[6];
                quad[0] = float3(-1.0,  1.0, 0.0);
                quad[1] = float3( 1.0, -1.0, 0.0);
                quad[2] = float3(-1.0, -1.0, 0.0);

                quad[3] = float3(-1.0,  1.0, 0.0);
                quad[4] = float3( 1.0,  1.0, 0.0);
                quad[5] = float3( 1.0, -1.0, 0.0);

                float aspect = _ScreenParams.x / _ScreenParams.y;

                float dToCenter = distance(quad[v.vid % 6].xy, float2(0.0, 0.0));
                float3 pos    = tmpParticle.Position + quad[v.vid % 6];
                // ... and scale it down + aspect correction
                pos.x        /= aspect;
                pos            *= 0.1;

                o.vertex    = float4(pos, 1.0);
                o.distCent = dToCenter;
                return o;
            }
           
            float4 frag (v2f i) : SV_Target
            {
                return float4(i.distCent * 0.5,0.0,0.0,1.0);
            }
            ENDCG
        }
    }
}

Is this happening because the value is been generated on the shader?

Thanks a lot!

It’s working perfectly.

You’re passing the distance from the center of a quad each vertex. By definition each vertex of a square or rectangular quad is the same distance to the center. Thus the interpolated value is constant across the tris.

If you want the distance you’ll need to actually pass the quad’s xy position and do the distance() in the fragment shader.

I just realised that, sleeping is a great debugging tool! Thanks!