Visible seam on texture transition

I needed some very high resolution Moon maps so I searched and found that I can make my own shader that will put smaller textures together into big one. So I wrote this code

Shader "Custom/surface8" {
    Properties {
        _MainTex0 ("Base (RGB)", 2D) = "white" {}
        _MainTex1 ("Base (RGB)", 2D) = "white" {}
        _MainTex2 ("Base (RGB)", 2D) = "white" {}
        _MainTex3 ("Base (RGB)", 2D) = "white" {}
        _MainTex4 ("Base (RGB)", 2D) = "white" {}
        _MainTex5 ("Base (RGB)", 2D) = "white" {}
        _MainTex6 ("Base (RGB)", 2D) = "white" {}
        _MainTex7 ("Base (RGB)", 2D) = "white" {}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _MainTex0;
        sampler2D _MainTex1;
        sampler2D _MainTex2;
        sampler2D _MainTex3;
        sampler2D _MainTex4;
        sampler2D _MainTex5;
        sampler2D _MainTex6;
        sampler2D _MainTex7;

        struct Input {
            float2 uv_MainTex0;
        };


        float2 dbl_uv_MainTex0;

        void surf (Input IN, inout SurfaceOutput o) {


            dbl_uv_MainTex0 = IN.uv_MainTex0*float2(4,2);


            half4 c0 = tex2D (_MainTex0, dbl_uv_MainTex0);
            half4 c1 = tex2D (_MainTex1, dbl_uv_MainTex0);
            half4 c2 = tex2D (_MainTex2, dbl_uv_MainTex0);
            half4 c3 = tex2D (_MainTex3, dbl_uv_MainTex0);
            half4 c4 = tex2D (_MainTex4, dbl_uv_MainTex0);
            half4 c5 = tex2D (_MainTex5, dbl_uv_MainTex0);
            half4 c6 = tex2D (_MainTex6, dbl_uv_MainTex0);
            half4 c7 = tex2D (_MainTex7, dbl_uv_MainTex0);


            if(IN.uv_MainTex0.x >= 0.75)
            {
                if(IN.uv_MainTex0.y >=0.5){
                    c0.rgb = c1.rgb = c2.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb =0;
                }
                if(IN.uv_MainTex0.y <0.500){
                c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c5.rgb=c6.rgb=0;
                }
          
            }
            if(IN.uv_MainTex0.x > 0.5){
                if(IN.uv_MainTex0.x < 0.75)
            {
              
                if(IN.uv_MainTex0.y >= 0.5){
                c3.rgb = c1.rgb = c0.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
                }
                else{
                c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c5.rgb=c7.rgb=0;
                }
          
            }
            }
            if(IN.uv_MainTex0.x >0.25){
                if(IN.uv_MainTex0.x < 0.5)
            {
              
                if(IN.uv_MainTex0.y >= 0.5){
                c3.rgb = c2.rgb = c0.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
                }
                else{
                c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c6.rgb=c7.rgb=0;
                }
          
                }
            }
                if(IN.uv_MainTex0.x <= 0.25)
            {
              
                if(IN.uv_MainTex0.y >= 0.5){
                c3.rgb = c2.rgb = c1.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
              

                }
                else{
                c0.rgb=c1.rgb=c2.rgb=c3.rgb=c5.rgb=c6.rgb=c7.rgb=0;
                }
                }
          
          
          


            o.Albedo = c0.rgb + c1.rgb + c2.rgb + c3.rgb+c4.rgb+c5.rgb+c6.rgb+c7.rgb;

            o.Alpha = c0.a + c1.a + c2.a + c3.a+c4.a+c5.a+c6.a+c7.a ;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

and everything works but there is a seam visible where two textures touch. Screenshot is attached. So, if anybody could help me? I personally split that big texture in Gimp so there is not any dark edge around textures so the seam is not from this.

Can’t help with the code, but have you double checked that it all goes back together in gimp? Had similar times where feathering/antialiasing was enabled on gimp’s selection tool

Could be the texture importer settings. I’ve had a few issues using texture atlases with small sprites and the sprite not showing up the same as in gimp/photoshop.

Make sure the max size is big enough, try changing the format to something like RGBA 32bit, and wrap mode to clamp. Unity’s default settings for a texture may cause compression artifacts. I also used Advanced Texture type to get more control of what happens with the texture.

Try disabling mip maps. If you want multiple textures to stitch together their mips need to stitch as perfectly the base texture. That can be hard to do without custom filtering, and can create visual issues like this one. Also make sure the texture mode is set to Clamp.

1 Like

OK, I will check in GIMP again and set different settings for Textures and let you know.

You can disable MIPS in the Unity import settings. Unity will auto gen mips unless you create them yourself in a format that supports them like dds.

Hmm, I don’t know how to put them together in Gimp again. The setting don’t change anything so it must be some error while cutting the images in GIMP.

It was problem with the filtering. When I set it to Point, the seam disappears, but it appears when using Bilinear or Trilinear.

1 Like

Is there a way to use filtering on all texture except from say 5 pixels from each border?

Yes. Use the UV logic in your shader.

I have searched all day now and I can’t figure out how I can change filter settings from shader code. How about some help?

Never mind, I figured I will leave textures with border so there won’t be black seam anymore around the edges.