This property, compatible in both Built-in RP and Scriptable RP, controls which face of a polygon will be removed in the pixel depth processing. What does this mean? Recall that a polygon object has inner faces and outer ones. By default, the outer faces are visible (Cull Back); however, we can activate the inner faces by following the scheme shown below.
- Cull Off. Both faces of the object are rendered.
- Cull Back. The back faces of the object are rendered, by default.
- Cull Front. The front faces of the object are rendered.
This command has three values which are: Back, Front and Off. By default, “Back” is active, however, generally, the line of code associated with culling is not visible in the shader for optimization purposes. If we want to modify the culling options, we must add the word “Cull” followed by the mode we want to use.
Shader “InspectorPath / shaderName”
{
Properties {} ...
SubShader
{
// Cull Off
// Cull Front
Cull Back
}
}
We can also dynamically configure the Culling options in the Unity Inspector through the dependency “UnityEngine.Rendering.CullMode” which is declared from the Enum drawer and passed as an argument in the function.
Shader "InspectorPath/shaderName"
{
Properties
{
[Enum(UnityEngine.Rendering.CullMode)]
_Cull ("Cull", Float) = 0
}
SubShader
{
Cull [_Cull]
}
}
Another helpful option occurs through the semantics SV_IsFrontFace, which allows us to project different colors and textures on both mesh faces. To do so, we simply declare a boolean variable and assign such semantics as an argument in the fragment shader stage.
fixed4 frag (v2f i, bool face : SV_IsFrontFace) : SV_Target
{
fixed4 colFront = tex2D(_FrontTexture, i.uv);
fixed4 colBack = tex2D(_BackTexture, i.uv);
return face ? colFront : colBack;
}
It is worth mentioning that this option only works when the “Cull” command has been previously set to “Off” in the shader.