Skip to content

Commit f5337cd

Browse files
[Backport 10.x.x][HDRP] Enable renderer sorting for mesh decals #5674 (#5703)
* Enable renderer sorting for mesh decals #5674 * reset to default shaderproperty for draworder * clamping Co-authored-by: Adrien de Tocqueville <adrien.tocqueville@unity3d.com>
1 parent 8a8ec02 commit f5337cd

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3939
- Fixed shadow sampling artifact when using the spot light shadow option 'custom spot angle'
4040
- Fixed issue with fading in SSR applying fade factor twice, resulting in darkening of the image in the transition areas.
4141
- Fixed error when disabling opaque objects on a camera with MSAA.
42+
- Fixed sorting for mesh decals.
4243

4344
## [10.6.0] - 2021-04-29
4445

com.unity.render-pipelines.high-definition/Documentation~/Decal-Shader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ These properties allow you to change the rendering behavior of the decal.
4848

4949
| **Property** | **Description** |
5050
| -------------------------- | ------------------------------------------------------------ |
51-
| **Draw Order** | Controls the order in which HDRP draws decals in the Scene. HDRP draws decals with lower values first, so it draws decals with a higher draw order value on top of those with lower values. This feature works for decals projected on opaque and transparent surfaces.<br />**Note**: This property only applies to decals the [Decal Projector](Decal-Projector.md) creates and has no effect on Mesh decals. Additionally, if you have multiple Decal Materials with the same **Draw Order**, the order HDRP renders them in depends on the order you create the Materials. HDRP renders Decal Materials you create first before those you create later with the same **Draw Order**. |
51+
| **Draw Order** | Controls the order in which HDRP draws decals in the Scene. HDRP draws decals with lower values first, so it draws decals with a higher draw order value on top of those with lower values. This feature works for decals projected on opaque and transparent surfaces. Additionally, if you have multiple Decal Materials with the same **Draw Order**, the order HDRP renders them in depends on the order you create the Materials. HDRP renders Decal Materials you create first before those you create later with the same **Draw Order**.<br/>To control the order of Mesh decals using the same Material, you should set the priority value on the MeshRenderer of the Mesh decals. |
5252
| **Mesh Decal Bias Type** | Determines the type of bias that HDRP applies to the decal’s Mesh to stop it from overlapping with other Meshes. The options are:<br/>&#8226; **Depth Bias**: Applies a bias to the final depth value, <br/>&#8226; **View Bias**: Applies a world-space bias (in meters) alongside the view vector. |
5353
| **- Mesh Decal View Bias** | A world-space bias (in meters) that HDRP applies to the decal’s Mesh to stop it from overlapping with other Meshes along the view vector. A positive value draws the decal in front of any overlapping Mesh, while a negative value offsets the decal and draws it behind. This property only affects decal Materials directly attached to GameObjects with a Mesh Renderer, so Decal Projectors do not use this property. This property is only visible if **Mesh Decal Bias Type** is set to **View Bias**. |
5454
| **Mesh Decal Depth Bias** | A depth bias that HDRP applies to the decal’s Mesh to stop it from overlapping with other Meshes. A negative value draws the decal in front of any overlapping Mesh, while a positive value offsets the decal and draw it behind. This property only affects decal Materials directly attached to GameObjects with a Mesh Renderer, so Decal Projectors do not use this property. This property is only visible if **Mesh Decal Bias Type** is set to **Depth Bias**. |

com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalUI.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ static public void SetupCommonDecalMaterialKeywordsAndPass(Material material)
9999
// Set stencil state
100100
material.SetInt(kDecalStencilWriteMask, (int)StencilUsage.Decals);
101101
material.SetInt(kDecalStencilRef, (int)StencilUsage.Decals);
102+
103+
// Set render queue
104+
var renderQueue = -1;
105+
if (material.HasProperty(HDShaderIDs._DrawOrder))
106+
renderQueue = (int)RenderQueue.Geometry + material.GetInt(HDShaderIDs._DrawOrder);
107+
material.renderQueue = renderQueue;
108+
109+
// always instanced
110+
material.enableInstancing = true;
102111
}
103112

104113
protected const string kBaseColorMap = "_BaseColorMap";

com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSortingInputsUIBlock.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ public override void OnGUI()
7373

7474
void DrawSortingInputsGUI()
7575
{
76+
EditorGUI.BeginChangeCheck();
7677
materialEditor.ShaderProperty(drawOrder, Styles.drawOrderText);
78+
if (EditorGUI.EndChangeCheck())
79+
drawOrder.floatValue = Math.Max(-HDRenderQueue.meshDecalPriorityRange, Math.Min((int)drawOrder.floatValue, HDRenderQueue.meshDecalPriorityRange));
80+
7781
materialEditor.ShaderProperty(decalMeshBiasType, Styles.meshDecalBiasType);
7882
if ((int)decalMeshBiasType.floatValue == (int)DecalMeshDepthBiasType.DepthBias)
7983
{

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4009,7 +4009,7 @@ RendererListDesc PrepareMeshDecalsRendererList(CullingResults cullingResults, HD
40094009
{
40104010
var desc = new RendererListDesc(m_MeshDecalsPassNames, cullingResults, hdCamera.camera)
40114011
{
4012-
sortingCriteria = SortingCriteria.CommonOpaque,
4012+
sortingCriteria = SortingCriteria.CommonOpaque | SortingCriteria.RendererPriority,
40134013
rendererConfiguration = PerObjectData.None,
40144014
renderQueueRange = HDRenderQueue.k_RenderQueue_AllOpaque
40154015
};

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderQueue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ internal static RenderQueueType MigrateRenderQueueToHDRP10(RenderQueueType rende
109109

110110
public static int ClampsTransparentRangePriority(int value) => Math.Max(-k_TransparentPriorityQueueRange, Math.Min(value, k_TransparentPriorityQueueRange));
111111

112+
public const int meshDecalPriorityRange = 50; // This range is arbitrary and match sorting priority
113+
112114
public static RenderQueueType GetTypeByRenderQueueValue(int renderQueue)
113115
{
114116
if (renderQueue == (int)Priority.Background)

0 commit comments

Comments
 (0)