Skip to content

Commit 1eceaae

Browse files
Revert "Automatically enable Alpha-To-Coverage when alpha clipping is on (#6599)" (#6650)
This reverts commit e7a2db2. # Conflicts: # com.unity.render-pipelines.high-definition/CHANGELOG.md # com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2022.1-to-2022.2.md
1 parent f949d2a commit 1eceaae

36 files changed

+120
-36
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
9797
- 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.
9898
- Render Graph object pools are now cleared with render graph cleanup
9999
- Updated Physically Based Sky documentation with more warnings about warmup cost.
100-
- Force Alpha To Coverage to be enabled when MSAA is enabled. Remove the Alpha to Mask UI control.
101100
- Improved the probe placement of APV when dealing with scenes that contains objects smaller than a brick.
102101
- Replaced the geometry distance offset in the Probe Volume component by a minimum renderer volume threshold to ignore small objects when placing probes.
103102
- Small improvement changes in the UX for the Unlit Distortion field.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ 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-
97
If you enable this feature, HDRP exposes the following properties for you to use to customize the Alpha Clipping effect:
108

119
| Property | Description |
1210
| ------------------------ | ------------------------------------------------------------ |
1311
| **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. |
1412
| **Use Shadow Threshold** | Enable the checkbox to set another threshold value for alpha clipping shadows. |
1513
| **- 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. |
1615

1716
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.
1817

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ 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. When enabled, all materials with Alpha Clipping will also enable Alpha To Coverage to benefit from MSAA. |
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**.|
3132
| **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. |
3233
| **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. |
3334
| **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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,11 @@ void ResetFloatProperty(string propName)
692692

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

698702
static void MigrateDecalRenderQueue(Material material, ShaderID id)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ 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;
4647

4748
lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular;
4849
lightingData.receiveDecals = eyeMasterNode.m_ReceiveDecals;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ 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;
4445

4546
lightingData.blendPreserveSpecular = fabricMasterNode.m_BlendPreserveSpecular;
4647
lightingData.receiveDecals = fabricMasterNode.m_ReceiveDecals;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ 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;
4748

4849
builtinData.alphaTestShadow = hairMasterNode.m_AlphaTestShadow;
4950
builtinData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ 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;
134135

135136
builtinData.alphaTestShadow = hdLitMasterNode.m_AlphaTestShadow;
136137
builtinData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering;

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

Lines changed: 3 additions & 1 deletion
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 transparentZWrite, TransparentCullMode transparentCullMode,
147+
bool alphaToMask, bool transparentZWrite, TransparentCullMode transparentCullMode,
148148
OpaqueCullMode opaqueCullMode, CompareFunction zTest,
149149
bool backThenFrontRendering, bool fogOnTransparent)
150150
{
@@ -156,6 +156,8 @@ 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);
159161
collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? transparentZWrite : true);
160162
collector.AddToggleProperty(kTransparentZWrite, transparentZWrite);
161163
collector.AddFloatProperty("_CullMode", (int)CullMode.Back);

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

Lines changed: 12 additions & 3 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 alphaCutoffEnable = "[_AlphaCutoffEnable]";
686+
public static readonly string alphaToMask = "[_AlphaToMask]";
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.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
742+
{ RenderState.AlphaToMask(Uniforms.alphaToMask), 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.alphaCutoffEnable), new FieldCondition(Fields.AlphaToMask, true) },
756+
{ RenderState.AlphaToMask(Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) },
757757
{ RenderState.Stencil(new StencilDescriptor()
758758
{
759759
WriteMask = Uniforms.stencilWriteMaskMV,
@@ -1402,6 +1402,15 @@ 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+
14051414
public static KeywordDescriptor TransparentColorShadow = new KeywordDescriptor()
14061415
{
14071416
displayName = "Transparent Color Shadow",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ 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;
127128
public int m_MaterialNeedsUpdateHash;
128129
public string m_ShaderGUIOverride;
129130
public bool m_OverrideEnabled;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ 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;
130131
public int m_MaterialNeedsUpdateHash;
131132
public string m_ShaderGUIOverride;
132133
public bool m_OverrideEnabled;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ 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;
186187
public int m_MaterialNeedsUpdateHash;
187188
public string m_ShaderGUIOverride;
188189
public bool m_OverrideEnabled;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public enum AlphaMode
3434
public bool m_DistortionOnly;
3535
public bool m_DistortionDepthTest;
3636
public bool m_AlphaTest;
37+
public bool m_AlphaToMask;
3738
public int m_SortPriority;
3839
public bool m_DoubleSided;
3940
public bool m_ZWrite;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ 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;
137138
public int m_MaterialNeedsUpdateHash;
138139
public string m_ShaderGUIOverride;
139140
public bool m_OverrideEnabled;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public enum SpecularOcclusionConeFixupMethod
122122
public DistortionMode m_DistortionMode;
123123
public bool m_DistortionDepthTest;
124124
public bool m_AlphaTest;
125+
public bool m_AlphaToMask;
125126
public int m_SortPriority;
126127
public DoubleSidedMode m_DoubleSidedMode;
127128
public NormalDropOffSpace m_NormalDropOffSpace;

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

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

9393
// Alpha Test
94+
// TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData?
9495
AddProperty(alphaCutoffEnableText, () => systemData.alphaTest, (newValue) => systemData.alphaTest = newValue);
9596
if (systemData.alphaTest)
9697
{
9798
context.globalIndentLevel++;
9899
AddProperty(useShadowThresholdText, () => builtinData.alphaTestShadow, (newValue) => builtinData.alphaTestShadow = newValue);
100+
AddProperty(alphaToMaskText, () => builtinData.alphaToMask, (newValue) => builtinData.alphaToMask = newValue);
99101
context.globalIndentLevel--;
100102
}
101103

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ 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));
151153
pass.keywords.Add(CoreKeywordDescriptors.WriteMsaaDepth);
154+
}
152155

153156
pass.keywords.Add(CoreKeywordDescriptors.SurfaceTypeTransparent);
154157
pass.keywords.Add(CoreKeywordDescriptors.BlendMode);
@@ -366,6 +369,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
366369
systemData.surfaceType,
367370
systemData.blendMode,
368371
systemData.sortPriority,
372+
builtinData.alphaToMask,
369373
systemData.transparentZWrite,
370374
systemData.transparentCullMode,
371375
systemData.opaqueCullMode,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ 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+
4957
[SerializeField]
5058
bool m_DepthOffset;
5159
public bool depthOffset

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ 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;
4748

4849
lightingData.normalDropOffSpace = stackLitMasterNode.m_NormalDropOffSpace;
4950
lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular;

0 commit comments

Comments
 (0)