Skip to content

Commit e7a2db2

Browse files
Automatically enable Alpha-To-Coverage when alpha clipping is on (#6599)
* Remove option from shaders * Remove form shadergraph * Remove framesetting and doc * Mention in docs * Update Alpha-Clipping.md * Update Frame-Settings.md * Update Upgrading-from-2022.1-to-2022.2.md Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 4bd7578 commit e7a2db2

36 files changed

+36
-120
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
9292
- 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.
9393
- Render Graph object pools are now cleared with render graph cleanup
9494
- Updated Physically Based Sky documentation with more warnings about warmup cost.
95+
- Force Alpha To Coverage to be enabled when MSAA is enabled. Remove the Alpha to Mask UI control.
9596

9697
## [13.1.2] - 2021-11-05
9798

com.unity.render-pipelines.high-definition/Documentation~/Alpha-Clipping.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ The **Alpha Clipping** option controls whether your Material acts as a [Cutout S
44

55
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.
66

7+
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.
8+
79
If you enable this feature, HDRP exposes the following properties for you to use to customize the Alpha Clipping effect:
810

911
| Property | Description |
1012
| ------------------------ | ------------------------------------------------------------ |
1113
| **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. |
1214
| **Use Shadow Threshold** | Enable the checkbox to set another threshold value for alpha clipping shadows. |
1315
| **- Shadow Threshold** | Set the alpha value limit that HDRP uses to determine whether it should render shadows for a pixel. |
14-
| **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. |
1516

1617
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.
1718

com.unity.render-pipelines.high-definition/Documentation~/Frame-Settings.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ These settings determine the method that the Cameras and Reflection Probes using
2727
| **Lit Shader Mode** | Select the Shader Mode HDRP uses for the Lit Shader when the rendering component using these Frame Settings renders the Scene. |
2828
| - **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**. |
2929
| - **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**. |
30-
| - **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. |
31-
| - **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**.|
30+
| - **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. |
3231
| **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. |
3332
| **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. |
3433
| **Decals** | Enable the checkbox to make HDRP process decals. Enable this on cameras that you want to render decals. |

com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2022.1-to-2022.2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ While Physically Based Sky is used, Directional lights can have a surface textur
99
## XR
1010

1111
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**.
12+
13+
## Material
14+
15+
### Alpha to mask
16+
17+
Starting from HDRP 14.x, Alpha to Mask option have been removed. Alpha to Mask is always enabled now when MSAA is enabled.

com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,7 @@ void ResetFloatProperty(string propName)
692692

693693
static void AlphaToMaskUIFix(Material material, ShaderID id)
694694
{
695-
if (material.HasProperty(kAlphaToMask) && material.HasProperty(kAlphaToMaskInspector))
696-
{
697-
material.SetFloat(kAlphaToMaskInspector, material.GetFloat(kAlphaToMask));
698-
HDShaderUtils.ResetMaterialKeywords(material);
699-
}
695+
// Not used anymore, alpha to mask option is removed
700696
}
701697

702698
static void MigrateDecalRenderQueue(Material material, ShaderID id)

com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
4343
builtinData.transparencyFog = eyeMasterNode.m_TransparencyFog;
4444
builtinData.addPrecomputedVelocity = eyeMasterNode.m_AddPrecomputedVelocity;
4545
builtinData.depthOffset = eyeMasterNode.m_depthOffset;
46-
builtinData.alphaToMask = eyeMasterNode.m_AlphaToMask;
4746

4847
lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular;
4948
lightingData.receiveDecals = eyeMasterNode.m_ReceiveDecals;

com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
4141
builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog;
4242
builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity;
4343
builtinData.depthOffset = fabricMasterNode.m_depthOffset;
44-
builtinData.alphaToMask = fabricMasterNode.m_AlphaToMask;
4544

4645
lightingData.blendPreserveSpecular = fabricMasterNode.m_BlendPreserveSpecular;
4746
lightingData.receiveDecals = fabricMasterNode.m_ReceiveDecals;

com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
4444
builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec;
4545
builtinData.addPrecomputedVelocity = hairMasterNode.m_AddPrecomputedVelocity;
4646
builtinData.depthOffset = hairMasterNode.m_depthOffset;
47-
builtinData.alphaToMask = hairMasterNode.m_AlphaToMask;
4847

4948
builtinData.alphaTestShadow = hairMasterNode.m_AlphaTestShadow;
5049
builtinData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering;

com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary<Blo
131131
builtinData.transparentWritesMotionVec = hdLitMasterNode.m_TransparentWritesMotionVec;
132132
builtinData.addPrecomputedVelocity = hdLitMasterNode.m_AddPrecomputedVelocity;
133133
builtinData.depthOffset = hdLitMasterNode.m_depthOffset;
134-
builtinData.alphaToMask = hdLitMasterNode.m_AlphaToMask;
135134

136135
builtinData.alphaTestShadow = hdLitMasterNode.m_AlphaTestShadow;
137136
builtinData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubShaderUtilities.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static void AddStencilShaderProperties(PropertyCollector collector, Syste
144144

145145
public static void AddBlendingStatesShaderProperties(
146146
PropertyCollector collector, SurfaceType surface, BlendMode blend, int sortingPriority,
147-
bool alphaToMask, bool transparentZWrite, TransparentCullMode transparentCullMode,
147+
bool transparentZWrite, TransparentCullMode transparentCullMode,
148148
OpaqueCullMode opaqueCullMode, CompareFunction zTest,
149149
bool backThenFrontRendering, bool fogOnTransparent)
150150
{
@@ -156,8 +156,6 @@ public static void AddBlendingStatesShaderProperties(
156156
collector.AddFloatProperty("_DstBlend", 0.0f);
157157
collector.AddFloatProperty("_AlphaSrcBlend", 1.0f);
158158
collector.AddFloatProperty("_AlphaDstBlend", 0.0f);
159-
collector.AddToggleProperty("_AlphaToMask", alphaToMask);
160-
collector.AddToggleProperty("_AlphaToMaskInspectorValue", alphaToMask);
161159
collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? transparentZWrite : true);
162160
collector.AddToggleProperty(kTransparentZWrite, transparentZWrite);
163161
collector.AddFloatProperty("_CullMode", (int)CullMode.Back);

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ public static class Uniforms
683683
public static readonly string dstBlend = "[_DstBlend]";
684684
public static readonly string alphaSrcBlend = "[_AlphaSrcBlend]";
685685
public static readonly string alphaDstBlend = "[_AlphaDstBlend]";
686-
public static readonly string alphaToMask = "[_AlphaToMask]";
686+
public static readonly string alphaCutoffEnable = "[_AlphaCutoffEnable]";
687687
public static readonly string cullMode = "[_CullMode]";
688688
public static readonly string cullModeForward = "[_CullModeForward]";
689689
public static readonly string zTestDepthEqualForOpaque = "[_ZTestDepthEqualForOpaque]";
@@ -739,7 +739,7 @@ public static class Uniforms
739739
{
740740
{ RenderState.Cull(Uniforms.cullMode) },
741741
{ RenderState.ZWrite(ZWrite.On) },
742-
{ RenderState.AlphaToMask(Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) },
742+
{ RenderState.AlphaToMask(Uniforms.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
743743
{ RenderState.Stencil(new StencilDescriptor()
744744
{
745745
WriteMask = Uniforms.stencilWriteMaskDepth,
@@ -753,7 +753,7 @@ public static class Uniforms
753753
{
754754
{ RenderState.Cull(Uniforms.cullMode) },
755755
{ RenderState.ZWrite(ZWrite.On) },
756-
{ RenderState.AlphaToMask(Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) },
756+
{ RenderState.AlphaToMask(Uniforms.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
757757
{ RenderState.Stencil(new StencilDescriptor()
758758
{
759759
WriteMask = Uniforms.stencilWriteMaskMV,
@@ -1402,15 +1402,6 @@ static class CoreKeywordDescriptors
14021402
scope = KeywordScope.Local
14031403
};
14041404

1405-
public static KeywordDescriptor AlphaToMask = new KeywordDescriptor()
1406-
{
1407-
displayName = "Alpha To Mask",
1408-
referenceName = "_ALPHATOMASK_ON",
1409-
type = KeywordType.Boolean,
1410-
definition = KeywordDefinition.ShaderFeature,
1411-
scope = KeywordScope.Local,
1412-
};
1413-
14141405
public static KeywordDescriptor TransparentColorShadow = new KeywordDescriptor()
14151406
{
14161407
displayName = "Transparent Color Shadow",

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/EyeMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
124124
public CompareFunction m_ZTest;
125125
public bool m_SupportLodCrossFade;
126126
public bool m_DOTSInstancing;
127-
public bool m_AlphaToMask;
128127
public int m_MaterialNeedsUpdateHash;
129128
public string m_ShaderGUIOverride;
130129
public bool m_OverrideEnabled;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/FabricMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
127127
public CompareFunction m_ZTest;
128128
public bool m_SupportLodCrossFade;
129129
public bool m_DOTSInstancing;
130-
public bool m_AlphaToMask;
131130
public int m_MaterialNeedsUpdateHash;
132131
public string m_ShaderGUIOverride;
133132
public bool m_OverrideEnabled;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDLitMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
183183
public CompareFunction m_ZTest;
184184
public bool m_SupportLodCrossFade;
185185
public bool m_DOTSInstancing;
186-
public bool m_AlphaToMask;
187186
public int m_MaterialNeedsUpdateHash;
188187
public string m_ShaderGUIOverride;
189188
public bool m_OverrideEnabled;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDUnlitMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public enum AlphaMode
3434
public bool m_DistortionOnly;
3535
public bool m_DistortionDepthTest;
3636
public bool m_AlphaTest;
37-
public bool m_AlphaToMask;
3837
public int m_SortPriority;
3938
public bool m_DoubleSided;
4039
public bool m_ZWrite;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HairMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask)
134134
public CompareFunction m_ZTest;
135135
public bool m_SupportLodCrossFade;
136136
public bool m_DOTSInstancing;
137-
public bool m_AlphaToMask;
138137
public int m_MaterialNeedsUpdateHash;
139138
public string m_ShaderGUIOverride;
140139
public bool m_OverrideEnabled;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/StackLitMasterNode1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public enum SpecularOcclusionConeFixupMethod
122122
public DistortionMode m_DistortionMode;
123123
public bool m_DistortionDepthTest;
124124
public bool m_AlphaTest;
125-
public bool m_AlphaToMask;
126125
public int m_SortPriority;
127126
public DoubleSidedMode m_DoubleSidedMode;
128127
public NormalDropOffSpace m_NormalDropOffSpace;

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ protected override void CreatePropertyGUI()
9191
context.globalIndentLevel--;
9292

9393
// Alpha Test
94-
// TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData?
9594
AddProperty(alphaCutoffEnableText, () => systemData.alphaTest, (newValue) => systemData.alphaTest = newValue);
9695
if (systemData.alphaTest)
9796
{
9897
context.globalIndentLevel++;
9998
AddProperty(useShadowThresholdText, () => builtinData.alphaTestShadow, (newValue) => builtinData.alphaTestShadow = newValue);
100-
AddProperty(alphaToMaskText, () => builtinData.alphaToMask, (newValue) => builtinData.alphaToMask = newValue);
10199
context.globalIndentLevel--;
102100
}
103101

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ protected override void CollectPassKeywords(ref PassDescriptor pass)
148148
pass.keywords.Add(CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true));
149149

150150
if (pass.IsDepthOrMV())
151-
{
152-
pass.keywords.Add(CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true));
153151
pass.keywords.Add(CoreKeywordDescriptors.WriteMsaaDepth);
154-
}
155152

156153
pass.keywords.Add(CoreKeywordDescriptors.SurfaceTypeTransparent);
157154
pass.keywords.Add(CoreKeywordDescriptors.BlendMode);
@@ -369,7 +366,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
369366
systemData.surfaceType,
370367
systemData.blendMode,
371368
systemData.sortPriority,
372-
builtinData.alphaToMask,
373369
systemData.transparentZWrite,
374370
systemData.transparentCullMode,
375371
systemData.opaqueCullMode,

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public bool transparentWritesMotionVec
4646
set => m_TransparentWritesMotionVec = value;
4747
}
4848

49-
[SerializeField]
50-
bool m_AlphaToMask = false;
51-
public bool alphaToMask
52-
{
53-
get => m_AlphaToMask;
54-
set => m_AlphaToMask = value;
55-
}
56-
5749
[SerializeField]
5850
bool m_DepthOffset;
5951
public bool depthOffset

com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
4444
builtinData.distortionDepthTest = stackLitMasterNode.m_DistortionDepthTest;
4545
builtinData.addPrecomputedVelocity = stackLitMasterNode.m_AddPrecomputedVelocity;
4646
builtinData.depthOffset = stackLitMasterNode.m_depthOffset;
47-
builtinData.alphaToMask = stackLitMasterNode.m_AlphaToMask;
4847

4948
lightingData.normalDropOffSpace = stackLitMasterNode.m_NormalDropOffSpace;
5049
lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular;

0 commit comments

Comments
 (0)