Search Unity

Shader malfunction on Android

Discussion in 'Shaders' started by Sh_Black_Hole, Jun 11, 2019.

  1. Sh_Black_Hole

    Sh_Black_Hole

    Joined:
    May 22, 2011
    Posts:
    40
    I write simple shader to blend some textures by some texture masks. It work perfect on PC but on Android devices, It has noise in some locations. I use this shader for terrain that create by 3d mesh. please watch video to know what I mean.

     

    Attached Files:

  2. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    In any case, imho, this is not correct blending
    Code (CSharp):
    1. fixed3 RedColor = tex2D(_RedTex, IN.uv_RedTex);
    2.         finalColor = finalColor * (1 - MainColor.r) + RedColor * MainColor.r;
    3.  
    4.         fixed3 GreenColor = tex2D(_GreenTex, IN.uv_GreenTex);
    5.         finalColor = finalColor * (1 - MainColor.g) + GreenColor * MainColor.g;
    6.  
    7.         fixed3 BlueColor = tex2D(_BlueTex, IN.uv_BlueTex);
    8.         finalColor = finalColor * (1 - MainColor.b) + BlueColor * MainColor.b;
    if you have MainColor.r == 1 and MainColor.g == 1 and MainColor.b == 1
    then finalColor will be not blended by R not G, but finalColor == 0 + BlueColor * MainColor.b == BlueColor

    what about artifacts, I don't know.. may be it related to content in your textures, you have 6 (!) of tex, with unknown content

    may be artifacts due to precision (if you change to float- the device also may be uncapable of float precision)
     
    Last edited: Jun 19, 2019
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Yeah, that looks like it might be a half precision UV issue. You can try using something like:
    fixed3 RedColor = tex2D(_RedTex, frac(IN.uv_RedTex));

    But that'll create its own problems. The only real solution is try to limit the range of the UVs per mesh patch, including scaling done via the material's texture scale property.