diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs index ebf1feb103d..16de4d209a7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs @@ -39,7 +39,7 @@ bool GeneratesWithShaderGraph() shaderGraphOutput.GetOrRefreshShaderGraphObject().generatesWithShaderGraph; } - public override bool supportsMaterialOffset + public override bool supportsSortingPriority { get { @@ -147,18 +147,18 @@ public override string GetRenderQueueStr() private int GetRenderQueueOffset() { var renderQueueType = GetRenderQueueType(); - var materialOffset = GetMaterialOffset(); + var materialSortingPriority = GetMaterialSortingPriority(); return owner is VFXDecalHDRPOutput ? - HDRenderQueue.Clamps(k_RenderQueue_AllOpaque, ChangeType(renderQueueType, 0, owner.hasAlphaClipping) + materialOffset) : - ChangeType(renderQueueType, materialOffset, owner.hasAlphaClipping); + HDRenderQueue.Clamps(k_RenderQueue_AllOpaque, ChangeType(renderQueueType, 0, owner.hasAlphaClipping) + materialSortingPriority) : + ChangeType(renderQueueType, materialSortingPriority, owner.hasAlphaClipping); } - private int GetMaterialOffset() + private int GetMaterialSortingPriority() { - if (supportsMaterialOffset) + if (supportsSortingPriority) { - int rawMaterialOffset = owner.GetMaterialOffset(); - return ClampsTransparentRangePriority(rawMaterialOffset); + int rawMaterialSortingPriority = owner.GetMaterialSortingPriority(); + return ClampsTransparentRangePriority(rawMaterialSortingPriority); } return 0; } diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 6982e353f44..3901e18bcd8 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Prevent VFX Graph compilation each time a property's min/max value is changed - Prevent vfx re-compilation in some cases when a value has not changed - Eye dropper in the color fields kept updating after pressing the Esc key +- Rename "Material Offset" to "Sorting Priority" in output render state settings [Case 1365257](https://issuetracker.unity3d.com/product/unity/issues/guid/1365257/) ## [12.0.0] - 2021-01-11 ### Added diff --git a/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md b/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md index 49da596e487..68e41e26d28 100644 --- a/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md +++ b/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md @@ -12,7 +12,7 @@ All outputs share these settings and property ports. The only exception is the S | --------------------------- | -------- | ------------------------------------------------------------ | | **Blend Mode** | Enum | Specifies the blending method for the system and determines how to use the alpha. The options are :
• **Opaque**: Does not use the alpha value and renders the output in the opaque pass. This also writes to the depth buffer.
• **Alpha**: Uses the [standard alpha blend](https://docs.unity3d.com/Manual/SL-Blend.html) mode and renders the output in the transparent pass. By default, this enables GPU sorting for particle outputs (which you can override using the **Sort** setting).
• **Premultiplied Alpha**: Uses the [premultiplied alpha blend mode](https://docs.unity3d.com/Manual/SL-Blend.html) and renders the output in the transparent pass. By default, this enables GPU sorting for particle outputs (which you can override using the **Sort** setting).
• **Additive**: Uses the [additive blend mode](https://docs.unity3d.com/Manual/SL-Blend.html) for alpha and renders the output in the transparent pass. | | **Use Alpha Clipping** | Bool | Indicates whether the system uses alpha clipping and discards pixels under a certain alpha threshold. If you enable this property, use the **Alpha Threshold** input to set the alpha value below which the system discards pixels. | -| **Material Offset** | Int | **(Inspector)** An offset Unity applies to the rendering order. This setting corresponds to the Material [Sorting Priority](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest?subfolder=/manual/Renderer-And-Material-Priority.html) in HDRP and Material [Priority](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest?subfolder=/manual/simple-lit-shader.html) in URP. It is equivalent to modifying the [Material.renderQueue](https://docs.unity3d.com/ScriptReference/Material-renderQueue.html) property. This value can be negative or positive. URP clamps this value between -50 and 50, and HDRP clamps this value between -100 and 100. | +| **Sorting Priority** | Int | **(Inspector)** An offset Unity applies to the rendering order. This setting corresponds to the Material [Sorting Priority](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest?subfolder=/manual/Renderer-And-Material-Priority.html) in HDRP and Material [Sorting Priority](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest?subfolder=/manual/simple-lit-shader.html) in URP. It is equivalent to modifying the [Material.renderQueue](https://docs.unity3d.com/ScriptReference/Material-renderQueue.html) property. This value can be negative or positive. HDRP and URP clamps this value between -50 and 50. | | **Generate Motion Vectors** | Bool | **(Inspector)** Indicates whether particles in the system write motion vectors and thus whether the System generates a motion vector pass. This is useful when you want temporal effects, like temporal anti-aliasing or motion blur, to take the output into account. Not all outputs can generate motion vectors and in that case, this setting is not visible.
If you enable this setting with a transparent output, an **Alpha Threshold** input port appears. Use this port to specify the minimum alpha the system requires a pixel to have to write motion vectors for it. This is because motion vectors cannot be blended. | | **Exclude From TAA** | Bool | **(Inspector)** Indicates whether the render pipeline excludes particles from temporal anti-aliasing (TAA). This is useful when particles look blurry when TAA is enabled and especially useful for fast moving particles. Not all outputs can exclude TAA and in that case, this setting is not visible. | | **Cast Shadows** | Bool | **(Inspector)** Indicates whether particles in the system cast shadows and thus whether the System generates a shadow pass.
If you enable this settings with a transparent output, an **Alpha Threshold** port appears. Use this port to specify the minimum alpha the system requires a pixel to have to write it to the shadow pass. This is because shadows cannot be transparent. | diff --git a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs index 7767157267f..9848b61f5ba 100644 --- a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs +++ b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs @@ -153,7 +153,7 @@ void OnReorder(ReorderableList list) { for (int i = 0; i < m_OutputContexts.Count(); ++i) { - m_OutputContexts[i].sortPriority = i; + m_OutputContexts[i].vfxSystemSortPriority = i; } } @@ -184,7 +184,7 @@ void OnEnable() { m_CurrentGraph = resource.GetOrCreateGraph(); m_CurrentGraph.systemNames.Sync(m_CurrentGraph); - m_OutputContexts.AddRange(m_CurrentGraph.children.OfType().OrderBy(t => t.sortPriority)); + m_OutputContexts.AddRange(m_CurrentGraph.children.OfType().OrderBy(t => t.vfxSystemSortPriority)); } m_ReorderableList = new ReorderableList(m_OutputContexts, typeof(IVFXSubRenderer)); @@ -647,7 +647,7 @@ public override void OnInspectorGUI() VisualEffectResource resource = asset.GetResource(); m_OutputContexts.Clear(); - m_OutputContexts.AddRange(resource.GetOrCreateGraph().children.OfType().OrderBy(t => t.sortPriority)); + m_OutputContexts.AddRange(resource.GetOrCreateGraph().children.OfType().OrderBy(t => t.vfxSystemSortPriority)); m_ReorderableList.DoLayoutList(); diff --git a/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs b/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs index 55fea4bdf4c..f308bfd66f5 100644 --- a/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs +++ b/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs @@ -66,10 +66,11 @@ public virtual SerializedProperty DoInspectorGUI() { var fieldInfo = prop.Key.field; EditorGUI.BeginChangeCheck(); - var attrs = fieldInfo.GetCustomAttributes(typeof(StringProviderAttribute), true); - if (attrs.Length > 0) + var stringAttribute = fieldInfo.GetCustomAttributes(true); + var rangeAttribute = fieldInfo.GetCustomAttributes(false).FirstOrDefault(); + if (stringAttribute.Any()) { - var strings = StringPropertyRM.FindStringProvider(attrs)(); + var strings = StringPropertyRM.FindStringProvider(stringAttribute.ToArray())(); int selected = prop.Value.hasMultipleDifferentValues ? -1 : System.Array.IndexOf(strings, prop.Value.stringValue); int result = EditorGUILayout.Popup(ObjectNames.NicifyVariableName(prop.Value.name), selected, strings); @@ -109,6 +110,19 @@ public virtual SerializedProperty DoInspectorGUI() EditorGUILayout.IntPopup(prop.Value, enumNames, enumValues); } + else if (fieldInfo.FieldType == typeof(int) + && rangeAttribute != null + && fieldInfo.GetCustomAttributes().Any()) + { + //Workaround: Range & Delayed attribute are incompatible, avoid the slider usage to keep the delayed behavior + var newValue = EditorGUILayout.DelayedIntField(ObjectNames.NicifyVariableName(prop.Value.name), prop.Value.intValue); + if (EditorGUI.EndChangeCheck()) + { + newValue = Mathf.Clamp(newValue, (int)rangeAttribute.min, (int)rangeAttribute.max); + prop.Value.intValue = newValue; + modifiedSetting = prop.Value; + } + } else { bool visibleChildren = EditorGUILayout.PropertyField(prop.Value); diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/IVFXSubRenderer.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/IVFXSubRenderer.cs index 29c5c746c4a..d3c9820e8e4 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/IVFXSubRenderer.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/IVFXSubRenderer.cs @@ -9,7 +9,7 @@ interface IVFXSubRenderer bool hasShadowCasting { get; } bool hasMotionVector { get; } // TODO Add other per output rendering settings here - int sortPriority { get; set; } + int vfxSystemSortPriority { get; set; } // Allow to setup material generated during import void SetupMaterial(Material material); diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs index 493468d5471..3c979012b72 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs @@ -89,8 +89,8 @@ protected enum FlipbookLayout [VFXSetting, SerializeField, Tooltip("When enabled, transparent particles fade out when near the surface of objects writing into the depth buffer (e.g. when intersecting with solid objects in the level).")] protected bool useSoftParticle = false; - [VFXSetting(VFXSettingAttribute.VisibleFlags.None), SerializeField, Header("Rendering Options"), Tooltip("")] - protected int sortPriority = 0; + [VFXSetting(VFXSettingAttribute.VisibleFlags.None), FormerlySerializedAs("sortPriority"), SerializeField, Header("Rendering Options"), Tooltip("")] + protected int vfxSystemSortPriority = 0; [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("Specifies whether to use GPU sorting for transparent particles.")] protected SortMode sort = SortMode.Auto; @@ -148,17 +148,17 @@ public virtual VFXOutputUpdate.Features outputUpdateFeatures } } - int IVFXSubRenderer.sortPriority + int IVFXSubRenderer.vfxSystemSortPriority { get { - return sortPriority; + return vfxSystemSortPriority; } set { - if (sortPriority != value) + if (vfxSystemSortPriority != value) { - sortPriority = value; + vfxSystemSortPriority = value; Invalidate(InvalidationCause.kSettingChanged); } } @@ -573,7 +573,7 @@ public override IEnumerable additionalMappings { get { - yield return new VFXMapping("sortPriority", sortPriority); + yield return new VFXMapping("sortPriority", vfxSystemSortPriority); if (HasIndirectDraw()) { yield return new VFXMapping("indirectDraw", 1); diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs index 82d9bf59016..93924d41fb0 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs @@ -4,6 +4,7 @@ using System.Reflection; using UnityEditor; using UnityEngine; +using UnityEngine.Serialization; namespace UnityEditor.VFX { @@ -31,12 +32,12 @@ public enum BlendMode public virtual bool isBlendModeOpaque { get { return blendMode == BlendMode.Opaque; } } - [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), Delayed, SerializeField, Tooltip("Specifies an offset applied to the material render queue.")] - protected int materialOffset = 0; + [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), Range(-50, 50), FormerlySerializedAs("materialOffset"), Delayed, SerializeField, Tooltip("Specifies an offset applied to the material render queue.")] + protected int sortingPriority = 0; - public virtual int GetMaterialOffset() + public virtual int GetMaterialSortingPriority() { - return materialOffset; + return sortingPriority; } public virtual bool hasMotionVector @@ -70,8 +71,8 @@ protected override IEnumerable filteredOutSettings foreach (var setting in base.filteredOutSettings) yield return setting; - if (!subOutput.supportsMaterialOffset) - yield return nameof(materialOffset); + if (!subOutput.supportsSortingPriority) + yield return nameof(sortingPriority); } } diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXStaticMeshOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXStaticMeshOutput.cs index 936e5ac8474..1991580aca6 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXStaticMeshOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXStaticMeshOutput.cs @@ -3,6 +3,7 @@ using UnityEditor.VFX; using UnityEngine; using UnityEngine.Rendering; +using UnityEngine.Serialization; using UnityEngine.VFX; namespace UnityEditor.VFX @@ -13,8 +14,8 @@ class VFXStaticMeshOutput : VFXContext, IVFXSubRenderer [VFXSetting, Tooltip("Specifies the shader with which the mesh output is rendered.")] private Shader shader; // not serialized here but in VFXDataMesh - [VFXSetting(VFXSettingAttribute.VisibleFlags.None), SerializeField, Header("Rendering Options")] - protected int sortPriority = 0; + [VFXSetting(VFXSettingAttribute.VisibleFlags.None), FormerlySerializedAs("sortPriority"), SerializeField, Header("Rendering Options")] + protected int vfxSystemSortPriority = 0; [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("When enabled, the mesh output will cast shadows.")] protected bool castShadows = false; @@ -25,17 +26,17 @@ class VFXStaticMeshOutput : VFXContext, IVFXSubRenderer public virtual bool hasMotionVector { get { return false; } } //TODO - int IVFXSubRenderer.sortPriority + int IVFXSubRenderer.vfxSystemSortPriority { get { - return sortPriority; + return vfxSystemSortPriority; } set { - if (sortPriority != value) + if (vfxSystemSortPriority != value) { - sortPriority = value; + vfxSystemSortPriority = value; Invalidate(InvalidationCause.kSettingChanged); } } @@ -233,7 +234,7 @@ public override IEnumerable additionalMappings { get { - yield return new VFXMapping("sortPriority", sortPriority); + yield return new VFXMapping("sortPriority", vfxSystemSortPriority); yield return new VFXMapping("castShadows", castShadows ? 1 : 0); } } diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs index b5c28bd676f..389ea4d2ece 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs @@ -25,7 +25,7 @@ public void Init(VFXAbstractRenderedOutput owner) public virtual bool supportsExposure { get { return false; } } public virtual bool supportsMotionVector { get { return false; } } public virtual bool supportsExcludeFromTAA { get { return false; } } - public virtual bool supportsMaterialOffset { get { return true; } } + public virtual bool supportsSortingPriority { get { return true; } } // Sealed override as SRP suboutputs cannot have dependencies public sealed override void CollectDependencies(HashSet objs, bool ownedOnly = true) { } @@ -65,9 +65,9 @@ public virtual string GetRenderQueueStr() throw new NotImplementedException("Unknown blend mode"); } - int rawMaterialOffset = owner.GetMaterialOffset(); - int materialOffset = Mathf.Clamp(rawMaterialOffset, -50, +50); - return baseRenderQueue + materialOffset.ToString("+#;-#;+0"); + int rawMaterialSortingPriority = owner.GetMaterialSortingPriority(); + int queueOffset = Mathf.Clamp(rawMaterialSortingPriority, -50, +50); + return baseRenderQueue + queueOffset.ToString("+#;-#;+0"); } public virtual IEnumerable> GetStencilStateOverridesStr() diff --git a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs index 6667855fe8d..4213b0fa10a 100644 --- a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs +++ b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using System.Reflection; +using System.Text; using UnityEditor.ShaderGraph.Internal; using UnityEngine; using UnityEngine.Rendering; @@ -64,17 +65,17 @@ public override void DisplayWarnings() var shaderGraphParticleOutput = (VFXShaderGraphParticleOutput)target; var shaderGraph = shaderGraphParticleOutput.GetOrRefreshShaderGraphObject(); var materialShadowOverride = VFXLibrary.currentSRPBinder.TryGetCastShadowFromMaterial(shaderGraph, shaderGraphParticleOutput.materialSettings, out var castShadow); - var materialQueueOffsetOverride = VFXLibrary.currentSRPBinder.TryGetQueueOffset(shaderGraph, shaderGraphParticleOutput.materialSettings, out var queueOffset) && shaderGraphParticleOutput.subOutput.supportsMaterialOffset; + var materialSortingPriorityOverride = VFXLibrary.currentSRPBinder.TryGetQueueOffset(shaderGraph, shaderGraphParticleOutput.materialSettings, out var queueOffset) && shaderGraphParticleOutput.subOutput.supportsSortingPriority; // Indicate material override from shaderGraph which is hiding output properties. - if (materialShadowOverride || materialQueueOffsetOverride) + if (materialShadowOverride || materialSortingPriorityOverride) { - var msg = "The ShaderGraph material is overriding some settings:"; + var msg = new StringBuilder("The ShaderGraph material is overriding some settings:"); if (materialShadowOverride) - msg += string.Format("\n - castShadow = {0}", castShadow ? "true" : "false"); - if (materialQueueOffsetOverride) - msg += string.Format("\n - materialOffset = {0}", queueOffset); - EditorGUILayout.HelpBox(msg, MessageType.Info); + msg.AppendFormat("\n - Cast Shadow = {0}", castShadow ? "true" : "false"); + if (materialSortingPriorityOverride) + msg.AppendFormat("\n - Sorting Priority = {0}", queueOffset); + EditorGUILayout.HelpBox(msg.ToString(), MessageType.Info); } // Indicate caution to the user if transparent motion vectors are disabled and motion vectors are enabled. @@ -201,7 +202,7 @@ public override bool hasShadowCasting } } - public override int GetMaterialOffset() + public override int GetMaterialSortingPriority() { var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null && shaderGraph.generatesWithShaderGraph && VFXLibrary.currentSRPBinder != null) @@ -211,7 +212,7 @@ public override int GetMaterialOffset() return queueOffset; } } - return base.materialOffset; + return sortingPriority; } public BlendMode GetMaterialBlendMode() @@ -399,7 +400,7 @@ protected override IEnumerable filteredOutSettings yield return nameof(castShadows); if (VFXLibrary.currentSRPBinder.TryGetQueueOffset(shaderGraph, materialSettings, out var queueOffset)) - yield return nameof(materialOffset); + yield return nameof(sortingPriority); } } }