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

Custom shader renders only one quarter of the screen on Android

Discussion in 'Shaders' started by Romaleks360, Jul 14, 2020.

  1. Romaleks360

    Romaleks360

    Joined:
    Sep 9, 2017
    Posts:
    69
    I use my custom toon shader for everything on the scene. But on an actual phone (quite old) it renders only one quarter of the screen. The chip is Adreno 506.
    Picture 1 is the screenshot from the editor, picture 2 is the screenshot from my phone.

    1.png

    The masking here is not straight, because it cut off triangles, not pixels.
    What's going on? I'm totally clueless.

    Shader code:
    Code (CSharp):
    1. Shader "Unlit/ColoredTexture"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Texture", 2D) = "white" {}
    6.         _Color("Color", Color) = (1,1,1,1)
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque" "LightMode" = "ForwardBase" }
    11.         LOD 100
    12.  
    13.         Pass
    14.         {
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             // make fog work
    19.             #pragma multi_compile_fog
    20.             #pragma multi_compile_instancing
    21.             #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
    22.             #include "UnityCG.cginc"
    23.             #include "UnityLightingCommon.cginc"
    24.             #include "AutoLight.cginc"
    25.             #pragma target 3.0
    26.  
    27.             struct appdata
    28.             {
    29.                 half4 vertex : POSITION;
    30.                 half2 uv : TEXCOORD0;
    31.                 half3 normal : NORMAL;
    32.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    33.             };
    34.  
    35.             struct v2f
    36.             {
    37.                 half2 uv : TEXCOORD0;
    38.                 UNITY_FOG_COORDS(1)
    39.                 SHADOW_COORDS(2)
    40.                 half3 worldNormal: TEXCOORD3;
    41.                 half4 vertex : SV_POSITION;
    42.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    43.             };
    44.  
    45.             sampler2D _MainTex;
    46.             half4 _MainTex_ST;
    47.             UNITY_INSTANCING_BUFFER_START(Props)
    48.             UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
    49.             UNITY_INSTANCING_BUFFER_END(Props)
    50.  
    51.             v2f vert (appdata v)
    52.             {
    53.                 v2f o;
    54.  
    55.                 UNITY_SETUP_INSTANCE_ID(v);
    56.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    57.  
    58.                 o.vertex = UnityObjectToClipPos(v.vertex);
    59.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    60.  
    61.                 o.worldNormal = UnityObjectToWorldNormal(v.normal);
    62.  
    63.                 TRANSFER_SHADOW(o)
    64.                 UNITY_TRANSFER_FOG(o,o.vertex);
    65.                 return o;
    66.             }
    67.  
    68.             fixed4 frag (v2f i) : SV_Target
    69.             {
    70.                 UNITY_SETUP_INSTANCE_ID(i);
    71.                 half NdotL = clamp(dot(i.worldNormal, _WorldSpaceLightPos0.xyz) * 25 * SHADOW_ATTENUATION(i), 0.5, 1);
    72.                 fixed4 col = tex2D(_MainTex, i.uv) * UNITY_ACCESS_INSTANCED_PROP(Props, _Color) * NdotL;
    73.                 UNITY_APPLY_FOG(i.fogCoord, col);
    74.                 return col;
    75.             }
    76.             ENDCG
    77.         }
    78.     }
    79.             Fallback "VertexLit"
    80. }
    81.  

    EDIT: actually, I'm using two custom shaders - the second one doesn't have a self-shadow part in frag, because it looks weird on cubes (but looks cool on spheres). It only receives shadows. One line difference. However, when playing on a high-end Samsung, the shader I showed you (with self-shadows) doesn't render at all, as if it was completely transparent. But its simplified version with no self-shadows appears fine.
    Maybe it is somehow related to shader instruction count?..
     
  2. Romaleks360

    Romaleks360

    Joined:
    Sep 9, 2017
    Posts:
    69
  3. Mythses

    Mythses

    Joined:
    Aug 25, 2023
    Posts:
    5
    i have the same problem but with text