Seeing very odd behaviour with SSAO and FOG and the use of multi compile.
I have a v basic shader
Shader "SSAO_FOGtest"
{
SubShader
{
Tags {"RenderPipeline" = "UniversalPipeline" "RenderType"="Opaque" "Queue"="Geometry" }
Pass
{
Name "ForwardLit"
ZTest LEqual
Blend One Zero
HLSLPROGRAM
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fog
#pragma vertex cs
#pragma fragment fs
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
half3 normalOS : NORMAL;
half4 tangentOS : TANGENT;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionWSAndFogFactor : TEXCOORD1;
float4 positionCS : SV_POSITION;
};
Varyings cs(Attributes input)
{
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS);
Varyings output;
output.positionCS = vertexInput.positionCS;
output.positionWSAndFogFactor = float4(vertexInput.positionWS, ComputeFogFactor(vertexInput.positionCS.z));
return output;
}
half4 fs(Varyings input) : SV_TARGET
{
half3 col= MixFog(half3(1,1,1), input.positionWSAndFogFactor.w);
return half4(col,1);
}
ENDHLSL
}
}
}
And these shader keywords combos
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fog
When I compile metal shader variants, no variants with both FOG_EXP2 and _SCREEN_SPACE_OCCLUSION set appear, i.e. they are stripped, even though they don’t conflict.
If I remove
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
or
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
Doesn’t matter which. Then recompiling the shader, FOG_EXP2 and SSAO appear in variant combinations that are compiled.
I’m guessing that this is a bug in the Shader Stripping logic, does anyone know if there tend to be issues with Unity incorrectly stripping valid combinations?
This hit me after upgrading and seeing missing shaders due to variants being stripped that are unexpected to be stripped.
(Note changing fog stripping settings in project → graphics doesn’t change the behaviour)

