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):
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:

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):

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.
[
Who could tell me why,please ? Thank you very much.![]()