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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Custom shader glitches on android

Discussion in 'Shaders' started by mavv, Jan 21, 2023.

  1. mavv

    mavv

    Joined:
    Feb 4, 2014
    Posts:
    29
    Hi, I found long time ago nice shader to tile texture on simple figures like cube, but holding scale, so cube 3x1x1 will still have same texture scale, but repeated 3x. You get the idea. For any level im creating walls and mix them in one object with one texture. And everything is great, but on android I have some white glitches.

    Hm, when I want to edit post I can see this video, but in topic, no.
    Link:
    https://imgur.com/a/ZJZoEn6

    GIF isn't perfect for video, but Im pretty sure you can see glitches on walls.
    Shader code:
    Code (Boo):
    1. Shader "Custom/Wall"
    2. {
    3.   Properties
    4.   {
    5.     _Color ("Main Color", Color) = (1,1,1,1)
    6.     _MainTex ("Base (RGB)", 2D) = "white" {}
    7.     _Scale ("Texture Scale", Float) = 1.0
    8.   }
    9.  
    10.   SubShader
    11.   {
    12.  
    13.     Tags { "RenderType"="Opaque" }
    14.     LOD 200
    15.  
    16.     CGPROGRAM
    17.     #pragma surface surf Lambert fullforwardshadows
    18.  
    19.     #pragma target 3.0
    20.     sampler2D _MainTex;
    21.     fixed4 _Color;
    22.     float _Scale;
    23.  
    24.     struct Input
    25.     {
    26.       float3 worldNormal;
    27.       float3 worldPos;
    28.     };
    29.  
    30.     void surf (Input IN, inout SurfaceOutput o)
    31.     {
    32.       float2 UV;
    33.       fixed4 c;
    34.         float4 col = _Color;
    35.       if(abs(IN.worldNormal.x)>0.5)
    36.       {
    37.         UV = IN.worldPos.yz; // side
    38.         c = tex2D(_MainTex, UV* _Scale); // use WALLSIDE texture
    39.         col.rgb*=0.6f;
    40.       }
    41.       else if(abs(IN.worldNormal.z)>0.5)
    42.       {
    43.         UV = IN.worldPos.xy; // front
    44.         c = tex2D(_MainTex, UV* _Scale); // use WALL texture
    45.         col.rgb*=0.6f;
    46.       }
    47.       else
    48.       {
    49.         UV = IN.worldPos.xz; // top
    50.         c = tex2D(_MainTex, UV* _Scale); // use FLR texture
    51.       }
    52.  
    53.       o.Albedo = c.rgb * col;
    54.     }
    55.     ENDCG
    56.   }
    57.  
    58.   Fallback "VertexLit"
    59. }
     
  2. mavv

    mavv

    Joined:
    Feb 4, 2014
    Posts:
    29
    Anyone? It is in wrong section?
     
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,854
    There's an Android subforum, better ask there.