IPreprocessShaders.OnProcessShader have different behavior on Android

I test a simple shader with multi_compile_fragment

Shader "Test"
{
    Properties
    {
        [MainTexture] _BaseMap("Base Map", 2D) = "white"
    }

    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fragment _ _BLACK

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS   : POSITION;
                float2 uv           : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
                float2 uv           : TEXCOORD0;
            };

            TEXTURE2D(_BaseMap);
            SAMPLER(sampler_BaseMap);

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
            CBUFFER_END

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
            #ifdef _BLACK
                color = 0;
            #endif
                return color;
            }
            ENDHLSL
        }
    }
}

Log snippet.shaderType and data.count in OnProcessShader
PC and IOS have 1 vertex shader and 2 fragment shader variants
Android only has 2 vertex shader
Is this expected?
If I want to strip _BLACK, I need do a special process on Android?
Test on 2020.3.42 and 2021.3.14

We combine all stages together on Vulkan and OpenGL. You need to strip based on the presence of a keyword in the variant and check if it’s available in the stage you have: Unity - Scripting API: ShaderUtil.PassHasKeyword(Shader,Rendering.PassIdentifier,Rendering.LocalKeyword) (2021.3+).

1 Like