Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Visible seam on texture transition

Discussion in 'Editor & General Support' started by I14R10, Oct 25, 2014.

  1. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    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

    Code (JavaScript):
    1. Shader "Custom/surface8" {
    2.     Properties {
    3.         _MainTex0 ("Base (RGB)", 2D) = "white" {}
    4.         _MainTex1 ("Base (RGB)", 2D) = "white" {}
    5.         _MainTex2 ("Base (RGB)", 2D) = "white" {}
    6.         _MainTex3 ("Base (RGB)", 2D) = "white" {}
    7.         _MainTex4 ("Base (RGB)", 2D) = "white" {}
    8.         _MainTex5 ("Base (RGB)", 2D) = "white" {}
    9.         _MainTex6 ("Base (RGB)", 2D) = "white" {}
    10.         _MainTex7 ("Base (RGB)", 2D) = "white" {}
    11.     }
    12.     SubShader {
    13.         Tags { "RenderType"="Opaque" }
    14.         LOD 200
    15.  
    16.         CGPROGRAM
    17.         #pragma surface surf Lambert
    18.  
    19.         sampler2D _MainTex0;
    20.         sampler2D _MainTex1;
    21.         sampler2D _MainTex2;
    22.         sampler2D _MainTex3;
    23.         sampler2D _MainTex4;
    24.         sampler2D _MainTex5;
    25.         sampler2D _MainTex6;
    26.         sampler2D _MainTex7;
    27.  
    28.         struct Input {
    29.             float2 uv_MainTex0;
    30.         };
    31.  
    32.  
    33.         float2 dbl_uv_MainTex0;
    34.  
    35.         void surf (Input IN, inout SurfaceOutput o) {
    36.  
    37.  
    38.             dbl_uv_MainTex0 = IN.uv_MainTex0*float2(4,2);
    39.  
    40.  
    41.             half4 c0 = tex2D (_MainTex0, dbl_uv_MainTex0);
    42.             half4 c1 = tex2D (_MainTex1, dbl_uv_MainTex0);
    43.             half4 c2 = tex2D (_MainTex2, dbl_uv_MainTex0);
    44.             half4 c3 = tex2D (_MainTex3, dbl_uv_MainTex0);
    45.             half4 c4 = tex2D (_MainTex4, dbl_uv_MainTex0);
    46.             half4 c5 = tex2D (_MainTex5, dbl_uv_MainTex0);
    47.             half4 c6 = tex2D (_MainTex6, dbl_uv_MainTex0);
    48.             half4 c7 = tex2D (_MainTex7, dbl_uv_MainTex0);
    49.  
    50.  
    51.             if(IN.uv_MainTex0.x >= 0.75)
    52.             {
    53.                 if(IN.uv_MainTex0.y >=0.5){
    54.                     c0.rgb = c1.rgb = c2.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb =0;
    55.                 }
    56.                 if(IN.uv_MainTex0.y <0.500){
    57.                 c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c5.rgb=c6.rgb=0;
    58.                 }
    59.          
    60.             }
    61.             if(IN.uv_MainTex0.x > 0.5){
    62.                 if(IN.uv_MainTex0.x < 0.75)
    63.             {
    64.              
    65.                 if(IN.uv_MainTex0.y >= 0.5){
    66.                 c3.rgb = c1.rgb = c0.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
    67.                 }
    68.                 else{
    69.                 c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c5.rgb=c7.rgb=0;
    70.                 }
    71.          
    72.             }
    73.             }
    74.             if(IN.uv_MainTex0.x >0.25){
    75.                 if(IN.uv_MainTex0.x < 0.5)
    76.             {
    77.              
    78.                 if(IN.uv_MainTex0.y >= 0.5){
    79.                 c3.rgb = c2.rgb = c0.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
    80.                 }
    81.                 else{
    82.                 c0.rgb=c1.rgb=c2.rgb=c3.rgb=c4.rgb=c6.rgb=c7.rgb=0;
    83.                 }
    84.          
    85.                 }
    86.             }
    87.                 if(IN.uv_MainTex0.x <= 0.25)
    88.             {
    89.              
    90.                 if(IN.uv_MainTex0.y >= 0.5){
    91.                 c3.rgb = c2.rgb = c1.rgb =c4.rgb=c5.rgb=c6.rgb=c7.rgb= 0;
    92.              
    93.  
    94.                 }
    95.                 else{
    96.                 c0.rgb=c1.rgb=c2.rgb=c3.rgb=c5.rgb=c6.rgb=c7.rgb=0;
    97.                 }
    98.                 }
    99.          
    100.          
    101.          
    102.  
    103.  
    104.             o.Albedo = c0.rgb + c1.rgb + c2.rgb + c3.rgb+c4.rgb+c5.rgb+c6.rgb+c7.rgb;
    105.  
    106.             o.Alpha = c0.a + c1.a + c2.a + c3.a+c4.a+c5.a+c6.a+c7.a ;
    107.         }
    108.         ENDCG
    109.     }
    110.     FallBack "Diffuse"
    111. }

    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.
     

    Attached Files:

    • seam.jpg
      seam.jpg
      File size:
      64.7 KB
      Views:
      718
  2. oysterCAKE

    oysterCAKE

    Joined:
    Dec 3, 2012
    Posts:
    149
    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
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    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.
     
  4. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    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.
     
    Chris-Trueman likes this.
  5. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    OK, I will check in GIMP again and set different settings for Textures and let you know.
     
  6. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    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.
     
  7. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    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.
     
  8. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    It was problem with the filtering. When I set it to Point, the seam disappears, but it appears when using Bilinear or Trilinear.
     
    misterlee likes this.
  9. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    Is there a way to use filtering on all texture except from say 5 pixels from each border?
     
  10. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Yes. Use the UV logic in your shader.
     
  11. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    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.
     
    Last edited: Oct 29, 2014