Declare shader feature for selection of targets - how?

Suppose I am going to declare a shader feature AAA, like
#pragma shader_feature AAA

Then I like to make it available only for
SHADER_API_D3D11
or for all shader apis, excluding this one.

How?

Two options:
Option 1. Define multiple SubShaders each with different possible targets and only add #pragma shader_feature AAA to the SubShaders with the appropriate targets.

Example:

SubShader {
  Pass {
    CGPROGRAM
    #pragma only_renderers d3d11
    #pragma shader_feature AAA
    // the rest of the shader ...
    ENDCG
  }
}
SubShader {
  Pass {
    CGPROGRAM
    #pragma exclude_renderers d3d11
    // the rest of the shader ...
    ENDCG
  }
}

Option 2. Take your #if defined(AAA) lines and add && defined(SHADER_API_D3D11) to them to ensure they only run if D3D11 is the current API.

Example:

#pragma shader_feature AAA

...

fixed4 frag(v2f i) : SV_Target {
    fixed4 col = tex2D(_MainTex, i.uv);
  
    #if defined(AAA) && defined(SHADER_API_D3D11)
        col.rgb *= 0.5;
    #endif

    return col;
}
1 Like