Skip to content

Commit

Permalink
[XPipeline]Unification of sorting priority across Materials
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-vazquez-unity3d committed Mar 26, 2021
1 parent 24b68dc commit b57358f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Expand Up @@ -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

Expand Down
Expand Up @@ -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)

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Expand Up @@ -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/)
Expand Down
Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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) {}
Expand Down

0 comments on commit b57358f

Please sign in to comment.