title: Unity Surface Shader - Runtime UV mapping
body: <p>I want to map a 2D Texture onto a procedurally generated plane, using vertex local position, in Unity. This is the code:</p>
  
  <pre><code>Shader "Custom/planeTest"
  {
  Properties
  {
      _MainTex("Albedo (RGB)", 2D) = "white" {}
      _Scale("Scale of texture", Vector) = (0.0, 0.0, 0.0)
      _Offset("Offset of texture", Vector) = (0.0, 0.0, 0.0)
  }
  
  SubShader
  {
      CGPROGRAM
  
      #pragma surface surf Standard vertex:vert
      #pragma target 3.0
  
      sampler2D _MainTex;
      float3 _Scale;
      float3 _Offset;
  
      struct Input {
          float2 uv_MainTex;
      };
  
      void vert(inout appdata_full v, out Input o)
      {
          UNITY_INITIALIZE_OUTPUT(Input, o);
          o.uv_MainTex = mul(unity_ObjectToWorld, v.vertex).xz;
      }
  
      void surf(Input IN, inout SurfaceOutputStandard o)
      {
          float2 _uv = (IN.uv_MainTex.x * _Scale.x, IN.uv_MainTex.y * _Scale.y) + _Offset.xy;
          o.Albedo = tex2D(_MainTex, _uv).rgb;
      }
  
      ENDCG
  }
  
  Fallback "Diffuse"
  }
  </code></pre>
  
  <p>I don't understand why, but this makes the plane's color uniform.
  The only option I can use is <strong>_Offset</strong>, that changes the color of the entire plane. I think <strong>(IN.uv_MainTex.x * _Scale.x, IN.uv_MainTex.y * _Scale.y)</strong> it's always zero, but I don't understand why.</p>
  
  <p>Please help me understanding what I'm doing wrong</p>