Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Terrain Texture on Android Device Pixelize

Discussion in 'Android' started by pssoft7, Dec 26, 2012.

  1. pssoft7


    Dec 11, 2011

    I am building something for Android. Everything seems fine until one day I notice a "pixelation" on the ground texture.
    Not sure how this come about, I tried to play around with the mipmaps without luck. I decided to remove all texture but leave one to see what happen.

    Apparently up to certain area, the same texture seems to pixelize/show boxes. The area of the map is 500x500 but this separation from "good" looking into bad seems to happen around 60% through. It happens only in Android device (Galaxy Note). Running it on Editor seems fine. Any clue why this is happening? :(

    Last edited: Dec 26, 2012
  2. miksumortti


    Apr 7, 2012
    Same problem here, it happens because the gpu of the device doesn't use enough precision for the multiple times tiled textures' uv-coordinates. I have tried to tile them less, edit the terrain shader, resize the texture, and edit other terrain settings, but still always pixelation and jitter:(

    Odd thing is that every second texture assigned to the terrain looks a bit better.
    Here the textures marked with 'x' look a lot worse than the others, these look just some weird rectangles glitching...
    It seems to be always the first, third and so on, that look worse.

    Here is pic of the "better" textures (the second and fourth) on Galaxy Tab 7.0 Plus GT-P6210
    Still some jitter and pixelation though...

    And here one of the "worse" texture (the third one) on same device
    Just some mushy rectangles

    How it looks on computer:

    The textures are a bit blurry as i tried to tile them less to see if it helps...

    Does anyone have found a way to fix this? The "worse" textures look so bad that they are useless, and with only 2 textures the terrain will look a bit boring. (and assigning over 4 textures and using only the better looking will cause unnecessary draw calls and triangle count will go up)
  3. miksumortti


    Apr 7, 2012
    After investigating this problem more I found that the textures' pixelation scales from the Terrain's origin as you can see from the following screenshots. The car is aligned to same direction in every pic - front pointing to Z-Axis.

    This is from the terrain pivot, no pixelation or any jitter. Here everything works well, but after like couple of hundred meters the problems starts:

    This is the right corner from the pivot, pixelation and jitter. And as you can see the rectangles are scaled only on X-Axis (like thin stripes):

    This is the up corner from the pivot, pixelation and jitter like in last one but scaled on Z-Axis:

    This is the diagonal corner from the pivot, pixelation and jitter are worst here, and the rectangles biggest (they scale as squares along the diagonal from the pivot):

    I tried to split the terrain to 4 smaller terrains but the pixelation and jitter were still almost as bad:(

    Can the accuracy of the uv's be improved somehow? Or can the uv coordinate's value be "reseted" to 0 on every start of a new terrain "chunk"/the-area-where-the-tiled-textures-are-used, I mean calculating the uv's on each chunk individually so they wouldn't get so high. (I don't know much about uv mapping so this could be a stupid question...)
    With the "chunk" i mean this area:
  4. miksumortti


    Apr 7, 2012
    Hey, found a trick that helps a bit.
    Setting the offset on the terrain's splat textures to negative half of the terrains dimensions will make the center area of the terrain look better (same like the pivot point with 0 offsets). For example my terrain is 2000x2000, so I set the offsets on all terrain textures to -1000. And in your -pssoft7- case you would set the offsets to -250, also if you can use bigger texture and tile it less it helps a bit. (Of course this helps only if your main playing area is more in the center of the map instead of the edges)
  5. elias_t


    Sep 17, 2010
    Welcome to the world of low precision of tegra2 and mali400.

    I have struggled with these issues for more then a year now.

    You have NO hope to make something with a sm2 shader.

    The only acceptable solution was to make a custom shader using the old shader lab syntax where the textures would blend according to vertex colors.
  6. pssoft7


    Dec 11, 2011
    Thanks, miksumortti. A great experiment you did there. I am gonna try your advice.
  7. miksumortti


    Apr 7, 2012
    Thanks for the info elias_t, but isn't the terrain generated on load from the heightmap, so the vertex colors would need to be painted on runtime/start with some script/shader or something, right?

    Ok, hope it works, I can post here if I found anything that helps more :)
  8. elias_t


    Sep 17, 2010
    I am using mesh terrain, split in pieces (to reduce even more the accuracy issues). The vertex colors/alpha is done in the editor. The vertex colors then are used by the shader as a splatmap.
  9. miksumortti


    Apr 7, 2012
    Thanks again :)
  10. pssoft7


    Dec 11, 2011
    adjusting offset is still not satisfying me. I still can see some pixelation (but more uniform) in my second texture.
    It'll be great if you could share links to tutorials like what you did, elias_t. :)
  11. miksumortti


    Apr 7, 2012
    Yes, I noticed after more testing that the offset thing didn't work so well as it seemed first, the problems "moved" a bit though...
    By the way how many textures you need on your terrain? Because if you only need 2 you can assign some 32x32 textures on the 1st and 3rd slot in the terrain and use only the 2nd and 4th.
    I also got an idea now to make some low res textures that have almost no contrast, like one color only. And then use those in the 1st and 3rd slot, and paint them to give some color on top of the better textures. I try the result soon on my device to see if it works.

    Hey, great news pssoft7 the low contrast color texture fix works great!:)

    Here's how it looks with 512x512 normal texture, not good at all:

    And here with 32x32 low contrast texture (almost one color) in the same place, no pixelation problems at all! (the contrast is from cliff texture that is blended with the "sand color texture"):

    Here's what I did to get it like that.
    1. take a normal terrain texture (that is assigned in the terrain in 1st or 3rd slot)
    2. edit it with image editor to make it have almost none details (or just paint an empty texture with some color, but I did it like this...)

    3. import it in Unity with 32x32 resolution (actually this could be all that is needed, as it will blur the texture maybe enough, but I'm not sure)
    4. add it to the terrain (on 1st or 3rd slot in the splat textures)
    5. paint it on top of the 2nd or 4th texture with lowered opacity (if you paint with 100% opacity it looks just a plain color)

    Of course you won't get details from the 1st and 3rd texture with this workaround, but you can blend the 2nd and 4th texture with the color only textures to get some more variation.;)
    Last edited: Jan 3, 2013
  12. kilik128


    Jul 15, 2013
    any new about this please ? thank's
    some one have try with vertex color
    Last edited: Jul 3, 2014
  13. forcepusher


    Jun 25, 2012
    I have found that whatever you do, terrain or mesh - you can't use surface shading if you tile too much on Android.
    I solved this issue today by making unlit terrain shader that uses fragment shading only.
    Copy-paste this into new shader, then make a new material, select AndroidTerrain/Unlit as a material shader, then paste it into terrain material slot.

    Code (CSharp):
    2. // Unlit shader.
    3. // - no lighting
    4. // - no lightmap support
    6. Shader "AndroidTerrain/Unlit" {
    7. Properties {
    8.    [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
    9.    [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    10.    [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    11.    [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    12.    [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    13.    // used in fallback on old cards & base map
    14.    [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    15.    [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
    16. }
    17. SubShader {
    18.    Tags {
    19.      "SplatCount" = "4"
    20.      "Queue" = "Geometry-100"
    21.      "RenderType" = "Opaque"
    22.    }
    24.    Pass {
    25.      CGPROGRAM
    26.        #pragma vertex vert
    27.        #pragma fragment frag
    29.        #include "UnityCG.cginc"
    31.        struct appdata_t {
    32.          float4 vertex : POSITION;
    33.          float2 uv_Control : TEXCOORD0;
    34.          //float2 uv_Splat : TEXCOORD1;
    35.          float2 uv_Splat0 : TEXCOORD1;
    36.          //float2 uv_Splat1 : TEXCOORD2;
    37.          //float2 uv_Splat2 : TEXCOORD3;
    38.         //float2 uv_Splat3 : TEXCOORD4;
    39.        };
    41.        struct v2f {
    42.          float4 vertex : SV_POSITION;
    43.          float2 uv_Control : TEXCOORD0;
    44.          //float2 uv_Splat : TEXCOORD1;
    45.          float2 uv_Splat0 : TEXCOORD1;
    46.          //float2 uv_Splat1 : TEXCOORD2;
    47.          //float2 uv_Splat2 : TEXCOORD3;
    48.          //float2 uv_Splat3 : TEXCOORD4;
    49.        };
    51.        //sampler2D _MainTex;
    52.        //float4 _MainTex_ST;
    54.        sampler2D _Control;
    55.        float4 _Control_ST;
    56.        sampler2D _Splat0;
    57.        sampler2D _Splat1;
    58.        sampler2D _Splat2;
    59.        sampler2D _Splat3;
    60.        //float4 _Splat_ST;
    61.        float4 _Splat0_ST;
    62.        //float4 _Splat1_ST;
    63.        //float4 _Splat2_ST;
    64.        //float4 _Splat3_ST;
    66.        v2f vert (appdata_t v)
    67.        {
    68.          v2f o;
    69.          o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    70.          o.uv_Control = TRANSFORM_TEX(v.uv_Control, _Control);
    71.          //o.uv_Splat = TRANSFORM_TEX(v.uv_Splat, _Splat);
    72.          o.uv_Splat0 = TRANSFORM_TEX(v.uv_Splat0, _Splat0);
    73.          //o.uv_Splat1 = TRANSFORM_TEX(v.uv_Splat1, _Splat1);
    74.          //o.uv_Splat2 = TRANSFORM_TEX(v.uv_Splat2, _Splat2);
    75.          //o.uv_Splat3 = TRANSFORM_TEX(v.uv_Splat3, _Splat3);
    76.          return o;
    77.        }
    79.        fixed4 frag (v2f i) : SV_Target
    80.        {
    81.          //fixed4 col = tex2D(_Control, i.uv_Control);
    82.          //return col;
    84.          fixed4 splat_control = tex2D (_Control, i.uv_Control);
    85.          fixed3 col;
    86.          col  = splat_control.r * tex2D (_Splat0, i.uv_Splat0).rgb;
    87.          col += splat_control.g * tex2D (_Splat1, i.uv_Splat0).rgb;
    88.          col += splat_control.b * tex2D (_Splat2, i.uv_Splat0).rgb;
    89.          col += splat_control.a * tex2D (_Splat3, i.uv_Splat0).rgb;
    91.          fixed4 output;
    92.          output.rgb = col;
    93.          output.a = 0.0f;
    94.          return output;
    95.        }
    96.      ENDCG
    97.    }
    98. }
    100. Dependency "AddPassShader" = "AndroidTerrain/Unlit"
    101. Dependency "BaseMapShader" = "Diffuse"
    102. Dependency "Details0"  = "Hidden/TerrainEngine/Details/Vertexlit"
    103. Dependency "Details1"  = "Hidden/TerrainEngine/Details/WavingDoublePass"
    104. Dependency "Details2"  = "Hidden/TerrainEngine/Details/BillboardWavingDoublePass"
    105. Dependency "Tree0"  = "Hidden/TerrainEngine/BillboardTree"
    107. // Fallback to Diffuse
    108. Fallback "Diffuse"
    110. }
    I think I might add lightmap support if I will need it myself, but for now you can adjust "Control" texture brightness in different areas to make parts of terrain darker.
    There is two limitations: you can't set different tiling on textures, tiling of the first texture will be used while others are ignored, also you can't use more then 4 textures.
    If anybody knows how to get more then 2 uv texcoords or more then 4 textures into this without hardcoding it into shader, please mod it and post back here.
    Last edited: Apr 20, 2015
    Alekxss and LightingBox2 like this.
  14. kilik128


    Jul 15, 2013
    thank's and you try perf
  15. kilik128


    Jul 15, 2013
    any one can help i'am fighting always with this trouble
  16. elias_t


    Sep 17, 2010
    There is no real solution to this problem. Some mobile gpus cannot support high precission on texture tiling.

    The best solution for terrains is to break it in smaller pieces and texture each piece with as less as possible texture tiling.
  17. LightingBox2


    Mar 31, 2015
    this solve my pro

    this solve my problem thanks man
    Alekxss likes this.