title: Unity3D visible seams on borders when tiling texture
body: <p>For my game I have written a shader that allows my texture to tile nicely over multiple objects. I do that by choosing the uv not based on the relative position of the vertex, but on the absolute world position. The custom shader is as follows. Basically it just tiles the texture in a grid of 1x1 world units.</p>
  
  <pre><code>Shader "MyGame/Tile" 
  {
      Properties 
      {
          _MainTex ("Texture", 2D) = "white" {}
      }
      SubShader 
      { 
          Tags { "RenderType"="Opaque" }
          LOD 200
  
          CGPROGRAM
          #pragma surface surf Lambert
          sampler2D _MainTex;
  
          struct Input 
          {
              float2 uv_MainTex;
              float3 worldPos;
          };
  
          void surf (Input IN, inout SurfaceOutput o) 
          {
              //adjust UV for tiling
              float2 cell = floor(IN.worldPos.xz);
              float2 offset = IN.worldPos.xz - cell;
              float2 uv = offset;
  
              float4 mainTex = tex2D(_MainTex, uv);
              o.Albedo = mainTex.rgb;
          }
          ENDCG
      } 
      FallBack "Diffuse"
  }
  </code></pre>
  
  <p>I have done this approach in Cg and in HLSL shaders on XNA before and it always worked like a charm. With the Unity shader, however, I get a very visible seam on the edges of the texture. I tried a Unity surface shader as well as a vertex/fragment shader, both with the same results.</p>
  
  <p><img src="https://i.stack.imgur.com/uqmSP.jpg" alt="visible seams"></p>
  
  <p>The texture itself looks as follows. In my game it is actually a <em>.tga</em>, not a <em>.png</em>, but that doesn't cause the problem. The problem occurs on all texture filter settings and on repeat or clamp mode equally.</p>
  
  <p><img src="https://i.stack.imgur.com/qeErp.png" alt="texture"></p>
  
  <p>Now I've seen someone have a similar problem here: <a href="http://answers.unity3d.com/questions/429810/visible-seams-on-borders-when-tiling-texture.html" rel="nofollow noreferrer">Seams between planes when lightmapping</a>.
  There was, however, no definitive answer on how to solve such a problem. Also, my problem doesn't relate to a lightmap or lighting at all. In the fragment shader I tested, there was no lighting enabled and the issue was still present.</p>
  
  <p>The same question was also posted on the Unity answers site, but I received no answers and not a lot of views, so I am trying it here as well: <a href="http://answers.unity3d.com/questions/429810/visible-seams-on-borders-when-tiling-texture.html" rel="nofollow noreferrer">Visible seams on borders when tiling texture</a></p>