Visible seams on borders when tiling texture
Asked Answered
S

1

0

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.

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"
}

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.

The texture itself looks as follows. In my game it is actually a .tga, not a .png, but that doesn’t cause the problem. The problem occurs on all texture filter settings and on repeat or clamp mode equally.

9612-mountain.png

Now I’ve seen someone have a similar problem here: Seams between planes when lightmapping.
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.

Stickybeak answered 6/6, 2023 at 2:48 Comment(0)
S
0

As I also posted this question on stackoverflow, here is the answer from there: https://mcmap.net/q/80912/-unity3d-visible-seams-on-borders-when-tiling-texture

Stickybeak answered 3/4, 2013 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.