Skip to content

Automatically enable Alpha-To-Coverage when alpha clipping is on #6599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The rendering order of decals that have a similar draw order value was modified. The new order should be the reverse of the previous order.
- Render Graph object pools are now cleared with render graph cleanup
- Updated Physically Based Sky documentation with more warnings about warmup cost.
- Force Alpha To Coverage to be enabled when MSAA is enabled. Remove the Alpha to Mask UI control.

## [13.1.2] - 2021-11-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ The **Alpha Clipping** option controls whether your Material acts as a [Cutout S

Enable **Alpha Clipping** to create a transparent effect with hard edges between the opaque and transparent areas. HDRP achieves this effect by not rendering pixels with alpha values below the value you specify in the **Threshold** field. For example, a **Threshold** of 0.1 means that HDRP doesn't render alpha values below 0.1.

When using MSAA, the new edges of the object caused by the cutout are not be taken into account for antialiasing. In this case HDRP will automatically enable Alpha To Coverage on the shader to benefit from MSAA.

If you enable this feature, HDRP exposes the following properties for you to use to customize the Alpha Clipping effect:

| Property | Description |
| ------------------------ | ------------------------------------------------------------ |
| **Threshold** | Set the alpha value limit that HDRP uses to determine whether it should render each pixel. If the alpha value of the pixel is equal to or higher than the limit then HDRP renders the pixel. If the value is lower than the limit then HDRP does not render the pixel. The default value is 0.5. |
| **Use Shadow Threshold** | Enable the checkbox to set another threshold value for alpha clipping shadows. |
| **- Shadow Threshold** | Set the alpha value limit that HDRP uses to determine whether it should render shadows for a pixel. |
| **Alpha to Mask** | Enable the checkbox to turn on alpha-to-coverage. When MSAA is used, alpha-to-coverage modifies multisample coverage mask proportionally to the pixel Shader result alpha value. This is typically used for anti-aliasing vegetation and other alpha-tested shaders. |

If you set your [Surface Type](Surface-Type.md) to **Transparent**, HDRP exposes the **Transparent Depth Prepass** and **Transparent Depth Postpass** properties. HDRP allows you to set individual thresholds for these two passes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ These settings determine the method that the Cameras and Reflection Probes using
| **Lit Shader Mode** | Select the Shader Mode HDRP uses for the Lit Shader when the rendering component using these Frame Settings renders the Scene. |
| - **Depth Prepass within Deferred** | If you enable Decals then HDRP forces a depth prepass and you can not disable this feature. This feature fills the depth buffer with all Meshes, without rendering any color. It is an optimization option that depends on the Unity Project you are creating, meaning that you should measure the performance before and after you enable this feature to make sure it benefits your Project. This is only available if you set **Lit Shader Mode** to **Deferred**. |
| - **Clear GBuffers** | Enable the checkbox to make HDRP clear GBuffers for Cameras using these Frame Settings. This is only available if you set **Lit Shader Mode** to **Deferred**. |
| - **MSAA ** | Select the MSAA quality for the rendering components using these Frame Settings. This is only available if you set **Lit Shader Mode** to **Forward**. Note that using a different value for multiple different cameras will have a non negligible impact on memory consumption. |
| - **Alpha To Mask** | Enable the checkbox to make HDRP render with **Alpha to Mask** Materials that have enabled it. This is only available if you enable **MSAA within Forward**.|
| - **MSAA** | Select the MSAA quality for the rendering components using these Frame Settings. This is only available if you set **Lit Shader Mode** to **Forward**. Note that using a different value for multiple different cameras will have a non negligible impact on memory consumption. When enabled, all materials with Alpha Clipping will also enable Alpha To Coverage to benefit from MSAA. |
| **Opaque Objects** | Enable the checkbox to make HDRP render Materials that have their **Surface Type** set to **Opaque**. If you disable this settings, Cameras/Reflection Probes using these Frame Settings do not render any opaque GameObjects. |
| **Transparent Objects** | Enable the checkbox to make HDRP render Materials that have their **Surface Type** set to **Transparent**. If you disable this setting, Cameras/Reflection Probes using these Frame Settings do not render any transparent GameObjects. |
| **Decals** | Enable the checkbox to make HDRP process decals. Enable this on cameras that you want to render decals. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ While Physically Based Sky is used, Directional lights can have a surface textur
## XR

Starting from HDRP 14.x, Motion Blur is turned off by default when in XR. This behaviour can be changed in the XR section HDRP asset by enabling the option **Allow Motion Blur**.

## Material

### Alpha to mask

Starting from HDRP 14.x, Alpha to Mask option have been removed. Alpha to Mask is always enabled now when MSAA is enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,7 @@ void ResetFloatProperty(string propName)

static void AlphaToMaskUIFix(Material material, ShaderID id)
{
if (material.HasProperty(kAlphaToMask) && material.HasProperty(kAlphaToMaskInspector))
{
material.SetFloat(kAlphaToMaskInspector, material.GetFloat(kAlphaToMask));
HDShaderUtils.ResetMaterialKeywords(material);
}
// Not used anymore, alpha to mask option is removed
}

static void MigrateDecalRenderQueue(Material material, ShaderID id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
builtinData.transparencyFog = eyeMasterNode.m_TransparencyFog;
builtinData.addPrecomputedVelocity = eyeMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = eyeMasterNode.m_depthOffset;
builtinData.alphaToMask = eyeMasterNode.m_AlphaToMask;

lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular;
lightingData.receiveDecals = eyeMasterNode.m_ReceiveDecals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog;
builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = fabricMasterNode.m_depthOffset;
builtinData.alphaToMask = fabricMasterNode.m_AlphaToMask;

lightingData.blendPreserveSpecular = fabricMasterNode.m_BlendPreserveSpecular;
lightingData.receiveDecals = fabricMasterNode.m_ReceiveDecals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec;
builtinData.addPrecomputedVelocity = hairMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = hairMasterNode.m_depthOffset;
builtinData.alphaToMask = hairMasterNode.m_AlphaToMask;

builtinData.alphaTestShadow = hairMasterNode.m_AlphaTestShadow;
builtinData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary<Blo
builtinData.transparentWritesMotionVec = hdLitMasterNode.m_TransparentWritesMotionVec;
builtinData.addPrecomputedVelocity = hdLitMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = hdLitMasterNode.m_depthOffset;
builtinData.alphaToMask = hdLitMasterNode.m_AlphaToMask;

builtinData.alphaTestShadow = hdLitMasterNode.m_AlphaTestShadow;
builtinData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static void AddStencilShaderProperties(PropertyCollector collector, Syste

public static void AddBlendingStatesShaderProperties(
PropertyCollector collector, SurfaceType surface, BlendMode blend, int sortingPriority,
bool alphaToMask, bool transparentZWrite, TransparentCullMode transparentCullMode,
bool transparentZWrite, TransparentCullMode transparentCullMode,
OpaqueCullMode opaqueCullMode, CompareFunction zTest,
bool backThenFrontRendering, bool fogOnTransparent)
{
Expand All @@ -156,8 +156,6 @@ public static void AddBlendingStatesShaderProperties(
collector.AddFloatProperty("_DstBlend", 0.0f);
collector.AddFloatProperty("_AlphaSrcBlend", 1.0f);
collector.AddFloatProperty("_AlphaDstBlend", 0.0f);
collector.AddToggleProperty("_AlphaToMask", alphaToMask);
collector.AddToggleProperty("_AlphaToMaskInspectorValue", alphaToMask);
collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? transparentZWrite : true);
collector.AddToggleProperty(kTransparentZWrite, transparentZWrite);
collector.AddFloatProperty("_CullMode", (int)CullMode.Back);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public static class Uniforms
public static readonly string dstBlend = "[_DstBlend]";
public static readonly string alphaSrcBlend = "[_AlphaSrcBlend]";
public static readonly string alphaDstBlend = "[_AlphaDstBlend]";
public static readonly string alphaToMask = "[_AlphaToMask]";
public static readonly string alphaCutoffEnable = "[_AlphaCutoffEnable]";
public static readonly string cullMode = "[_CullMode]";
public static readonly string cullModeForward = "[_CullModeForward]";
public static readonly string zTestDepthEqualForOpaque = "[_ZTestDepthEqualForOpaque]";
Expand Down Expand Up @@ -739,7 +739,7 @@ public static class Uniforms
{
{ RenderState.Cull(Uniforms.cullMode) },
{ RenderState.ZWrite(ZWrite.On) },
{ RenderState.AlphaToMask(Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) },
{ RenderState.AlphaToMask(Uniforms.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
{ RenderState.Stencil(new StencilDescriptor()
{
WriteMask = Uniforms.stencilWriteMaskDepth,
Expand All @@ -753,7 +753,7 @@ public static class Uniforms
{
{ RenderState.Cull(Uniforms.cullMode) },
{ RenderState.ZWrite(ZWrite.On) },
{ RenderState.AlphaToMask(Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) },
{ RenderState.AlphaToMask(Uniforms.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
{ RenderState.Stencil(new StencilDescriptor()
{
WriteMask = Uniforms.stencilWriteMaskMV,
Expand Down Expand Up @@ -1402,15 +1402,6 @@ static class CoreKeywordDescriptors
scope = KeywordScope.Local
};

public static KeywordDescriptor AlphaToMask = new KeywordDescriptor()
{
displayName = "Alpha To Mask",
referenceName = "_ALPHATOMASK_ON",
type = KeywordType.Boolean,
definition = KeywordDefinition.ShaderFeature,
scope = KeywordScope.Local,
};

public static KeywordDescriptor TransparentColorShadow = new KeywordDescriptor()
{
displayName = "Transparent Color Shadow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
public CompareFunction m_ZTest;
public bool m_SupportLodCrossFade;
public bool m_DOTSInstancing;
public bool m_AlphaToMask;
public int m_MaterialNeedsUpdateHash;
public string m_ShaderGUIOverride;
public bool m_OverrideEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
public CompareFunction m_ZTest;
public bool m_SupportLodCrossFade;
public bool m_DOTSInstancing;
public bool m_AlphaToMask;
public int m_MaterialNeedsUpdateHash;
public string m_ShaderGUIOverride;
public bool m_OverrideEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
public CompareFunction m_ZTest;
public bool m_SupportLodCrossFade;
public bool m_DOTSInstancing;
public bool m_AlphaToMask;
public int m_MaterialNeedsUpdateHash;
public string m_ShaderGUIOverride;
public bool m_OverrideEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public enum AlphaMode
public bool m_DistortionOnly;
public bool m_DistortionDepthTest;
public bool m_AlphaTest;
public bool m_AlphaToMask;
public int m_SortPriority;
public bool m_DoubleSided;
public bool m_ZWrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
public CompareFunction m_ZTest;
public bool m_SupportLodCrossFade;
public bool m_DOTSInstancing;
public bool m_AlphaToMask;
public int m_MaterialNeedsUpdateHash;
public string m_ShaderGUIOverride;
public bool m_OverrideEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public enum SpecularOcclusionConeFixupMethod
public DistortionMode m_DistortionMode;
public bool m_DistortionDepthTest;
public bool m_AlphaTest;
public bool m_AlphaToMask;
public int m_SortPriority;
public DoubleSidedMode m_DoubleSidedMode;
public NormalDropOffSpace m_NormalDropOffSpace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ protected override void CreatePropertyGUI()
context.globalIndentLevel--;

// Alpha Test
// TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData?
AddProperty(alphaCutoffEnableText, () => systemData.alphaTest, (newValue) => systemData.alphaTest = newValue);
if (systemData.alphaTest)
{
context.globalIndentLevel++;
AddProperty(useShadowThresholdText, () => builtinData.alphaTestShadow, (newValue) => builtinData.alphaTestShadow = newValue);
AddProperty(alphaToMaskText, () => builtinData.alphaToMask, (newValue) => builtinData.alphaToMask = newValue);
context.globalIndentLevel--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ protected override void CollectPassKeywords(ref PassDescriptor pass)
pass.keywords.Add(CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true));

if (pass.IsDepthOrMV())
{
pass.keywords.Add(CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true));
pass.keywords.Add(CoreKeywordDescriptors.WriteMsaaDepth);
}

pass.keywords.Add(CoreKeywordDescriptors.SurfaceTypeTransparent);
pass.keywords.Add(CoreKeywordDescriptors.BlendMode);
Expand Down Expand Up @@ -369,7 +366,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
systemData.surfaceType,
systemData.blendMode,
systemData.sortPriority,
builtinData.alphaToMask,
systemData.transparentZWrite,
systemData.transparentCullMode,
systemData.opaqueCullMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public bool transparentWritesMotionVec
set => m_TransparentWritesMotionVec = value;
}

[SerializeField]
bool m_AlphaToMask = false;
public bool alphaToMask
{
get => m_AlphaToMask;
set => m_AlphaToMask = value;
}

[SerializeField]
bool m_DepthOffset;
public bool depthOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
builtinData.distortionDepthTest = stackLitMasterNode.m_DistortionDepthTest;
builtinData.addPrecomputedVelocity = stackLitMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = stackLitMasterNode.m_depthOffset;
builtinData.alphaToMask = stackLitMasterNode.m_AlphaToMask;

lightingData.normalDropOffSpace = stackLitMasterNode.m_NormalDropOffSpace;
lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular;
Expand Down
Loading