From b57358ff2f44f3b2b021f64fe0515fc2f818c23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Fri, 26 Mar 2021 12:56:40 +0100 Subject: [PATCH] [XPipeline]Unification of sorting priority across Materials --- .../CHANGELOG.md | 1 + .../Renderer-And-Material-Priority.md | 2 +- .../UIBlocks/AdvancedOptionsUIBlock.cs | 4 +- .../Runtime/RenderPipeline/HDRenderQueue.cs | 51 ++++++++++--------- .../CHANGELOG.md | 1 + .../Editor/ShaderGUI/BaseShaderGUI.cs | 11 +--- 6 files changed, 33 insertions(+), 37 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2834116f6b4..dca13db7ee8 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -180,6 +180,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The default LookDev volume profile is now copied and referened in the Asset folder instead of the package folder. - Changed normal used in path tracing to create a local light list from the geometric to the smooth shading one. - Embed the HDRP config package instead of copying locally, the `Packages` folder is versionned by Collaborate. (case 1276518) +- Materials with Transparent Surface type, the property Sorting Priority is clamped on the UI from -50 to 50 instead of -100 to 100. ## [11.0.0] - 2020-10-21 diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Renderer-And-Material-Priority.md b/com.unity.render-pipelines.high-definition/Documentation~/Renderer-And-Material-Priority.md index 3cb01522e60..f218c4df690 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Renderer-And-Material-Priority.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Renderer-And-Material-Priority.md @@ -16,7 +16,7 @@ The resulting queue is a list of GameObjects that are first sorted by their Mate ## Sorting by Material -Materials with a **Transparent Surface Type** have a **Sorting Priority** property that you can use to sort groups of Meshes that use different Materials. This property is an integer value clamped between -100 and 100. +Materials with a **Transparent Surface Type** have a **Sorting Priority** property that you can use to sort groups of Meshes that use different Materials. This property is an integer value clamped between -50 and 50. This property can be found on the *Advanced Options* section. ![](Images/RendererAndMaterialPriority1.png) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/AdvancedOptionsUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/AdvancedOptionsUIBlock.cs index 89e936d74a8..5e7c0f8ec8a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/AdvancedOptionsUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/AdvancedOptionsUIBlock.cs @@ -47,9 +47,9 @@ internal class Styles } MaterialProperty specularOcclusionMode = null; - MaterialProperty addPrecomputedVelocity = null; - const string kSpecularOcclusionMode = "_SpecularOcclusionMode"; + + MaterialProperty addPrecomputedVelocity = null; const string kAddPrecomputedVelocity = HDMaterialProperties.kAddPrecomputedVelocity; Features m_Features; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderQueue.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderQueue.cs index 9816142c225..3d5d0d21b47 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderQueue.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderQueue.cs @@ -9,42 +9,42 @@ namespace UnityEngine.Rendering.HighDefinition internal static class HDRenderQueue { - const int k_TransparentPriorityQueueRange = 100; + const int k_TransparentPriorityQueueRangeStep = 100; public enum Priority { - Background = UnityEngine.Rendering.RenderQueue.Background, + Background = RenderQueue.Background, - Opaque = UnityEngine.Rendering.RenderQueue.Geometry, - OpaqueDecal = UnityEngine.Rendering.RenderQueue.Geometry + 225, // Opaque Decal mean Opaque that can receive decal - OpaqueAlphaTest = UnityEngine.Rendering.RenderQueue.AlphaTest, - OpaqueDecalAlphaTest = UnityEngine.Rendering.RenderQueue.AlphaTest + 25, + Opaque = RenderQueue.Geometry, + OpaqueDecal = RenderQueue.Geometry + 225, // Opaque Decal mean Opaque that can receive decal + OpaqueAlphaTest = RenderQueue.AlphaTest, + OpaqueDecalAlphaTest = RenderQueue.AlphaTest + 25, // Warning: we must not change Geometry last value to stay compatible with occlusion - OpaqueLast = UnityEngine.Rendering.RenderQueue.GeometryLast, + OpaqueLast = RenderQueue.GeometryLast, - AfterPostprocessOpaque = UnityEngine.Rendering.RenderQueue.GeometryLast + 1, - AfterPostprocessOpaqueAlphaTest = UnityEngine.Rendering.RenderQueue.GeometryLast + 10, + AfterPostprocessOpaque = RenderQueue.GeometryLast + 1, + AfterPostprocessOpaqueAlphaTest = RenderQueue.GeometryLast + 10, // For transparent pass we define a range of 200 value to define the priority // Warning: Be sure no range are overlapping - PreRefractionFirst = 2750 - k_TransparentPriorityQueueRange, + PreRefractionFirst = 2750 - k_TransparentPriorityQueueRangeStep, PreRefraction = 2750, - PreRefractionLast = 2750 + k_TransparentPriorityQueueRange, + PreRefractionLast = 2750 + k_TransparentPriorityQueueRangeStep, - TransparentFirst = UnityEngine.Rendering.RenderQueue.Transparent - k_TransparentPriorityQueueRange, - Transparent = UnityEngine.Rendering.RenderQueue.Transparent, - TransparentLast = UnityEngine.Rendering.RenderQueue.Transparent + k_TransparentPriorityQueueRange, + TransparentFirst = RenderQueue.Transparent - k_TransparentPriorityQueueRangeStep, + Transparent = RenderQueue.Transparent, + TransparentLast = RenderQueue.Transparent + k_TransparentPriorityQueueRangeStep, - LowTransparentFirst = 3400 - k_TransparentPriorityQueueRange, + LowTransparentFirst = 3400 - k_TransparentPriorityQueueRangeStep, LowTransparent = 3400, - LowTransparentLast = 3400 + k_TransparentPriorityQueueRange, + LowTransparentLast = 3400 + k_TransparentPriorityQueueRangeStep, - AfterPostprocessTransparentFirst = 3700 - k_TransparentPriorityQueueRange, + AfterPostprocessTransparentFirst = 3700 - k_TransparentPriorityQueueRangeStep, AfterPostprocessTransparent = 3700, - AfterPostprocessTransparentLast = 3700 + k_TransparentPriorityQueueRange, + AfterPostprocessTransparentLast = 3700 + k_TransparentPriorityQueueRangeStep, - Overlay = UnityEngine.Rendering.RenderQueue.Overlay + Overlay = RenderQueue.Overlay } public enum RenderQueueType @@ -107,7 +107,8 @@ internal static RenderQueueType MigrateRenderQueueToHDRP10(RenderQueueType rende public static int Clamps(this RenderQueueRange range, int value) => Math.Max(range.lowerBound, Math.Min(value, range.upperBound)); - public static int ClampsTransparentRangePriority(int value) => Math.Max(-k_TransparentPriorityQueueRange, Math.Min(value, k_TransparentPriorityQueueRange)); + public const int sortingPriortyRange = 50; + public static int ClampsTransparentRangePriority(int value) => Math.Max(-sortingPriortyRange, Math.Min(value, sortingPriortyRange)); public static RenderQueueType GetTypeByRenderQueueValue(int renderQueue) { @@ -170,7 +171,7 @@ public static RenderQueueType GetTransparentEquivalent(RenderQueueType type) return type; case RenderQueueType.Overlay: case RenderQueueType.Background: - throw new ArgumentException("Unknow RenderQueueType conversion to transparent equivalent, was " + type); + throw new ArgumentException("Unknown RenderQueueType conversion to transparent equivalent, was " + type); } } @@ -189,7 +190,7 @@ public static RenderQueueType GetOpaqueEquivalent(RenderQueueType type) return type; case RenderQueueType.Overlay: case RenderQueueType.Background: - throw new ArgumentException("Unknow RenderQueueType conversion to opaque equivalent, was " + type); + throw new ArgumentException("Unknown RenderQueueType conversion to opaque equivalent, was " + type); } } @@ -272,9 +273,9 @@ public static string GetShaderTagValue(int index) { // Special case for transparent (as we have transparent range from PreRefractionFirst to AfterPostprocessTransparentLast // that start before RenderQueue.Transparent value - if (HDRenderQueue.k_RenderQueue_AllTransparent.Contains(index) - || HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent.Contains(index) - || HDRenderQueue.k_RenderQueue_LowTransparent.Contains(index)) + if (k_RenderQueue_AllTransparent.Contains(index) + || k_RenderQueue_AfterPostProcessTransparent.Contains(index) + || k_RenderQueue_LowTransparent.Contains(index)) { int v = (index - (int)RenderQueue.Transparent); return "Transparent" + ((v < 0) ? "" : "+") + v; diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index a8b83ac8994..e3f3929ae3a 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Changed UniversalRenderPipelineCameraEditor to URPCameraEditor - Reduced the size of the fragment input struct of the TerrainLitPasses and LitGBufferPass, SimpleLitForwardPass and SimpleLitGBufferPass lighting shaders. - Bokeh Depth of Field performance improvement: moved some calculations from GPU to CPU. +- Advanced Options > Priority has been renamed to Sorting Priority ### Fixed - Fixed an issue where ShadowCaster2D was generating garbage when running in the editor. [case 1304158](https://issuetracker.unity3d.com/product/unity/issues/guid/1304158/) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs b/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs index 4826727bb09..187c8f2350c 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs @@ -91,7 +91,7 @@ protected class Styles public static readonly GUIContent fixNormalNow = EditorGUIUtility.TrTextContent("Fix now", "Converts the assigned texture to be a normal map format."); - public static readonly GUIContent queueSlider = EditorGUIUtility.TrTextContent("Priority", + public static readonly GUIContent queueSlider = EditorGUIUtility.TrTextContent("Sorting Priority", "Determines the chronological rendering order for a Material. High values are rendered first."); } @@ -265,14 +265,7 @@ public virtual void DrawAdvancedOptions(Material material) protected void DrawQueueOffsetField() { if (queueOffsetProp != null) - { - EditorGUI.BeginChangeCheck(); - EditorGUI.showMixedValue = queueOffsetProp.hasMixedValue; - var queue = EditorGUILayout.IntSlider(Styles.queueSlider, (int)queueOffsetProp.floatValue, -queueOffsetRange, queueOffsetRange); - if (EditorGUI.EndChangeCheck()) - queueOffsetProp.floatValue = queue; - EditorGUI.showMixedValue = false; - } + materialEditor.IntSliderShaderProperty(queueOffsetProp, -queueOffsetRange, queueOffsetRange, Styles.queueSlider); } public virtual void FillAdditionalFoldouts(MaterialHeaderScopeList materialScopesList) {}