Question about UV calculate in shader after scalling Gameobject

Hi everyone,

Below shader written by CG language which set the object vertexs coordinates in object space as UV coordinate. It confuse me with when I uniform scale the Gameobject in Inspector ,It seems that the UV coordinate has not been correctly calculated.

Shader "Custom/Texgen_Obj_FragMine" {
   Properties {
        _MainTex ("Base", 2D) = "white"
    }
    SubShader {
        Pass {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            sampler2D _MainTex;
            struct v2f {
                float4  pos : SV_POSITION;
                float2  uv : TEXCOORD0;
            } ;
            v2f vert (appdata_base v)
            {
                v2f o;
                o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
                o.uv=v.vertex.xy;
                return o;
            }
            float4 frag (v2f i) : COLOR
            {
                float4 texCol = tex2D(_MainTex,i.uv);
                   
                return texCol;
            }
            ENDCG
        }
    }
}

Texture(repeat mode):1617182--98656--$2_6235_a0d0969bae0c473.png

Put this shader on an unit cube.In the cube object space , the cube coordinate of top-right-front vertex is (0.5,0.5,0.5) ,that is the center of texture (0.5,0.5),By parity of reasoning, we can get the mapped unit cube like that:

1617182--98657--$2_6235_c9a778e3945601f.png

and then,I set the non-uniform scale like (2,2,1),the top-right-front vertex coordinate is (1,1,0.5)and its UV is (1,1):

1617182--98658--$2_6235_541c8352ce67cfb.png

now the question is if I set the scale form (2,2,1) to(2,2,2),In face,if making uniform scale the result as same as the result of scalling (1,1,1) uint cube.

[1617182--98659--$2_6235_aed77b0c4f78133.png

Who could tell me why,please ? Thank you very much.:slight_smile:

uv coords are in the range 0 to 1.

Setting a value beyond this range will be converted to a 0-1 value ( either wrapped or clamped )