Search Unity

SRP Batcher not working on Android with custom shader

Discussion in 'Universal Render Pipeline' started by Oskar_Madcore_Games, Apr 16, 2021.

  1. Oskar_Madcore_Games

    Oskar_Madcore_Games

    Joined:
    Jul 17, 2018
    Posts:
    4
    Hi guys, need help.

    We've got this custom shader. SRP Batcher works great with it on MacOS, Windows and iOS, but breaks on Android. Can you help? We get:

    Screenshot 2021-04-16 at 14.01.28.png

    Code (CSharp):
    1. Shader "Tap Anywhere/UnlitWithShadows"
    2. {
    3.     Properties
    4.     {
    5.         [MainColor] _BaseColor("BaseColor", Color) = (1,1,1,0)
    6.         [MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
    7.         _Alpha("Alpha", Range(0, 1)) = 1
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}
    13.         Blend SrcAlpha OneMinusSrcAlpha
    14.         Cull Back
    15.  
    16.         Pass
    17.         {
    18.             Tags { "LightMode"="UniversalForward" "RenderType"="Transparent" }
    19.  
    20.             HLSLPROGRAM
    21.             #pragma vertex vert
    22.             #pragma fragment frag
    23.  
    24.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    25.                      
    26.             struct Attributes
    27.             {
    28.                 float4 positionOS   : POSITION;
    29.                 float2 uv           : TEXCOORD0;
    30.             };
    31.  
    32.             struct Varyings
    33.             {
    34.                 float2 uv           : TEXCOORD0;
    35.                 float3 positionWS   : TEXCOORD1;
    36.                 float4 positionHCS  : SV_POSITION;
    37.             };
    38.  
    39.             CBUFFER_START(UnityPerMaterial)
    40.             float4 _BaseMap_ST;
    41.             float4 _BaseColor;
    42.             float _Alpha;
    43.             CBUFFER_END
    44.  
    45.             TEXTURE2D(_BaseMap);
    46.             SAMPLER(sampler_BaseMap);
    47.  
    48.             Varyings vert(Attributes IN)
    49.             {
    50.                 Varyings OUT;
    51.  
    52.                 VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz);
    53.                 OUT.positionHCS = positionInputs.positionCS;
    54.                 OUT.positionWS = positionInputs.positionWS;
    55.                 OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
    56.                 return OUT;
    57.             }
    58.  
    59.             half4 frag(Varyings IN) : SV_Target
    60.             {
    61.                 float4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
    62.                 color.rgb = color.rgb * saturate(1-_BaseColor.a) + _BaseColor.rgb * saturate(_BaseColor.a);
    63.                 color.a = _Alpha;
    64.                 return color;
    65.             }
    66.             ENDHLSL
    67.         }
    68.     }
    69. }