From d9eba8f4baf0b12d9c296a28e45237c088b81c59 Mon Sep 17 00:00:00 2001 From: Gabriel de la Cruz Date: Mon, 9 Oct 2023 11:51:01 +0000 Subject: [PATCH 1/6] [Backport][2023.1][VFX] Use empty shader to skip rendering sleeping systems Trying to access VFX renderer materials from scripts currently return a variable number of materials, depending on the number of active systems. This behavior is a side effect of an optimization, and it seems to be less intuitive than returning the entire lists of materials. We are restoring the previous behavior (return the entire list) while implementing an alternative optimization. The original problem: - VFX with sleeping systems still set up the shader, even though they will not be rendering anything - Renderer nodes by default create one "drawcall" per material, but it is possible to change it in the renderer. - SRP renderer can handle a number different from the material count, but editor rendering (picking, selection) can not. First optimization: - Renderer node uses a variable number of materials (GetMaterialCount and GetMaterial are virtual), only counting the materials of systems that are active. - Works with SRP renderer, that can handle a variable number of drawcalls, and the editor renderer, because the material count now matches the active - "materials" and "sharedMaterials" use the same functions, so the number of materials returned is variable, depending on the active systems New optimization: - Renderer node uses one "drawcall" per material, default behavior for renderers - Inactive systems replace the material data with a special material that is not using any passes, so it gets ignored by all renderers - "materials" and "sharedMaterials" go back to default behavior. The special empty material is not included in these lists --- .../Editor/Inspector/VFXManagerEditor.cs | 15 +++++++++------ .../Shaders/Empty.shader | 11 +++++++++++ .../Shaders/Empty.shader.meta | 9 +++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 Packages/com.unity.visualeffectgraph/Shaders/Empty.shader create mode 100644 Packages/com.unity.visualeffectgraph/Shaders/Empty.shader.meta diff --git a/Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXManagerEditor.cs b/Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXManagerEditor.cs index 5a1d150b0ce..7239cf5c2dd 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXManagerEditor.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXManagerEditor.cs @@ -105,12 +105,12 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); } - private static bool SetBuiltInShaderIfNeeded(SerializedObject obj, string shaderName, string shaderPath) + private static bool SetBuiltInShaderIfNeeded(SerializedObject obj, string shaderName, string shaderPath) where T : UnityObject { var shaderProperty = obj.FindProperty(shaderName); if (shaderProperty.objectReferenceValue == null) { - var shader = AssetDatabase.LoadAssetAtPath(shaderPath); + var shader = AssetDatabase.LoadAssetAtPath(shaderPath); if (shader != null) { shaderProperty.objectReferenceValue = shader; @@ -154,10 +154,13 @@ public static void CheckVFXManager() SerializedObject obj = new SerializedObject(vfxmanager); bool shaderModified = false; - shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_IndirectShader", "Packages/com.unity.visualeffectgraph/Shaders/VFXFillIndirectArgs.compute"); - shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_CopyBufferShader", "Packages/com.unity.visualeffectgraph/Shaders/VFXCopyBuffer.compute"); - shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_SortShader", "Packages/com.unity.visualeffectgraph/Shaders/Sort.compute"); - shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_StripUpdateShader", "Packages/com.unity.visualeffectgraph/Shaders/UpdateStrips.compute"); + shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_IndirectShader", "Packages/com.unity.visualeffectgraph/Shaders/VFXFillIndirectArgs.compute"); + shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_CopyBufferShader", "Packages/com.unity.visualeffectgraph/Shaders/VFXCopyBuffer.compute"); + shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_SortShader", "Packages/com.unity.visualeffectgraph/Shaders/Sort.compute"); + shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_StripUpdateShader", "Packages/com.unity.visualeffectgraph/Shaders/UpdateStrips.compute"); + + shaderModified |= SetBuiltInShaderIfNeeded(obj, "m_EmptyShader", "Packages/com.unity.visualeffectgraph/Shaders/Empty.shader"); + bool runtimeResourcesModified = false; runtimeResourcesModified = SetRuntimeResourcesIfNeeded(obj); diff --git a/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader b/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader new file mode 100644 index 00000000000..d61f1b21502 --- /dev/null +++ b/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader @@ -0,0 +1,11 @@ +Shader "Hidden/VFX/Empty" +{ + SubShader + { + Pass + { + Tags { "LightMode" = "None" } + } + } + Fallback Off +} diff --git a/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader.meta b/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader.meta new file mode 100644 index 00000000000..bd43de4ff82 --- /dev/null +++ b/Packages/com.unity.visualeffectgraph/Shaders/Empty.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 33a2079f6a2db4c4eb2e44b33f4ddf6b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: From 53e0749d1a7374c805f521416a7549c35a042097 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Mon, 9 Oct 2023 11:51:01 +0000 Subject: [PATCH 2/6] [Backport][2023.1][VFX] Reimport existing shader graph that support VFX when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://jira.unity3d.com/browse/UUM-12579 🎮To reproduce: 1. Open Unity and create the new "2D URP" project 2. Install the Visual Effect Graph from the Package Manager 3. In the Project View Right-Click and select Create > Visual Effects > Visual Effect Graph 4. Leave the default "New VFX" name and confirm it with the Enter button 5. Open the "New VFX.vfx" Asset in Visual Effect Graph Window 6. Under Output Particle Quad node, select Shadergraph 7. Ensure the filter has the "Show Packages results" field enabled to see the default VFX Shadergraph 👍Expected result In the "Select VFX Shader Graph" window you can see the "VFXSpriteLit" and the "VFXSpriteUnlit" Shader Graphs 👎Actual result In the "Select VFX Shader Graph" window you can't see Shader Graphs just the "None" option 🔸Notes: I’ve only managed to select those VFX Shader Graphs (the "VFXSpriteLit" and the "VFXSpriteUnlit") when I’ve copied them into the Project Asset directory 🏷Reproducible in Unity `2022.2.0a16`, `2022.2.0b6`, and `2023.1.0a8` 💬Developer notes: The issue happens because these ShadeGraph assets were already imported when the Visual Effect package is installed. So VFX code do not re-import them. But when they were first imported, the needed `ShaderGraphVfxAsset` resource had not been generated (because the VFX package was not installed yet). We already have a mechanism to re-import VFX assets when the package version change (which happens on package installation). So the fix rely on this mechanism and in addition to re-importing VFX assets we also re-import ShaderGraph (only those that are compatible with VFX). The symptom of this issue can be checked looking at the Shader asset like in the screenshots below Unity_IHgBLIm0xt But we expect this: jZuk0ULmGx --- .../Editor/Material/ShaderGraph/HDMetadata.cs | 9 ++ .../Material/ShaderGraph/HDSubTarget.cs | 1 + .../Editor/VFXGraph/VFXHDRPBinder.cs | 2 + .../ShaderGraph/Targets/UniversalSubTarget.cs | 1 + .../ShaderGraph/Targets/UniversalTarget.cs | 16 +-- .../Editor/ShaderGraph/UniversalMetadata.cs | 9 ++ .../Editor/VFXGraph/VFXURPBinder.cs | 5 + .../Editor/Data/Graphs/GraphData.cs | 2 +- .../Editor/Data/Graphs/GraphDataReadOnly.cs | 2 + .../Editor/Data/Interfaces/IMaySupportVFX.cs | 13 +-- .../Editor/Core/VFXSRPBinder.cs | 1 + .../Editor/Models/VFXGraph.cs | 105 ++++++++++++++---- 12 files changed, 117 insertions(+), 49 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDMetadata.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDMetadata.cs index 4b7f806f99a..ca58840e38f 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDMetadata.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDMetadata.cs @@ -26,6 +26,9 @@ sealed class HDMetadata : ScriptableObject [SerializeField] bool m_HasVertexModificationInMotionVector; + [SerializeField] + bool m_IsVFXCompatible; + public ShaderID shaderID { get => m_ShaderID; @@ -67,5 +70,11 @@ public bool hasVertexModificationInMotionVector get => m_HasVertexModificationInMotionVector; set => m_HasVertexModificationInMotionVector = value; } + + public bool isVFXCompatible + { + get => m_IsVFXCompatible; + set => m_IsVFXCompatible = value; + } } } diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 52c2f70121c..df7b046c5c0 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -77,6 +77,7 @@ public virtual ScriptableObject GetMetadataObject(GraphDataReadOnly graph) hdMetadata.migrateFromOldCrossPipelineSG = m_MigrateFromOldCrossPipelineSG; hdMetadata.hdSubTargetVersion = systemData.version; hdMetadata.hasVertexModificationInMotionVector = systemData.customVelocity || systemData.tessellation || graph.AnyVertexAnimationActive(); + hdMetadata.isVFXCompatible = graph.IsVFXCompatible(); return hdMetadata; } diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPBinder.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPBinder.cs index bd671d569c8..858bfed1f6b 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPBinder.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPBinder.cs @@ -23,6 +23,8 @@ class VFXHDRPBinder : VFXSRPBinder public override string SRPAssetTypeStr { get { return typeof(HDRenderPipelineAsset).Name; } } public override Type SRPOutputDataType { get { return typeof(VFXHDRPSubOutput); } } + public override bool IsShaderVFXCompatible(Shader shader) => shader.TryGetMetadataOfType(out var metadata) && metadata.isVFXCompatible; + public override void SetupMaterial(Material mat, bool hasMotionVector = false, bool hasShadowCasting = false, ShaderGraphVfxAsset shaderGraph = null) { try diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSubTarget.cs index 511c57c5348..520336e25eb 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSubTarget.cs @@ -62,6 +62,7 @@ public virtual ScriptableObject GetMetadataObject(GraphDataReadOnly graphData) urpMetadata.surfaceType = target.surfaceType; urpMetadata.alphaMode = target.alphaMode; urpMetadata.castShadows = target.castShadows; + urpMetadata.isVFXCompatible = graphData.IsVFXCompatible(); return urpMetadata; } diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 58c4b5cd34d..52880377cf9 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -99,9 +99,9 @@ internal enum RenderFace Both = 0 // = CullMode.Off -- render both faces } - sealed class UniversalTarget : Target, IHasMetadata, ILegacyTarget + sealed class UniversalTarget : Target, IHasMetadata, ILegacyTarget, IMaySupportVFX #if HAS_VFX_GRAPH - , IMaySupportVFX, IRequireVFXContext + , IRequireVFXContext #endif { public override int latestVersion => 1; @@ -770,17 +770,7 @@ public bool CanSupportVFX() return false; } - public bool SupportsVFX() - { -#if HAS_VFX_GRAPH - if (!CanSupportVFX()) - return false; - - return m_SupportVFX; -#else - return false; -#endif - } + public bool SupportsVFX() => CanSupportVFX() && m_SupportVFX; [Serializable] class UniversalTargetLegacySerialization diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalMetadata.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalMetadata.cs index 122fbcad605..aea948c2ed7 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalMetadata.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalMetadata.cs @@ -24,6 +24,9 @@ sealed class UniversalMetadata : ScriptableObject [SerializeField] bool m_CastShadows; + [SerializeField] + bool m_IsVFXCompatible; + public ShaderUtils.ShaderID shaderID { get => m_ShaderID; @@ -52,5 +55,11 @@ public bool castShadows get => m_CastShadows; set => m_CastShadows = value; } + + public bool isVFXCompatible + { + get => m_IsVFXCompatible; + set => m_IsVFXCompatible = value; + } } } diff --git a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXURPBinder.cs b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXURPBinder.cs index 38e96f39882..52bb6c8097c 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXURPBinder.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXURPBinder.cs @@ -18,6 +18,11 @@ class VFXURPBinder : VFXSRPBinder public override string SRPAssetTypeStr { get { return "UniversalRenderPipelineAsset"; } } public override Type SRPOutputDataType { get { return null; } } // null by now but use VFXURPSubOutput when there is a need to store URP specific data + public override bool IsShaderVFXCompatible(Shader shader) + { + return shader.TryGetMetadataOfType(out var metadata) && metadata.isVFXCompatible; + } + public override void SetupMaterial(Material material, bool hasMotionVector = false, bool hasShadowCasting = false, ShaderGraphVfxAsset shaderGraph = null) { ShaderUtils.UpdateMaterial(material, ShaderUtils.MaterialUpdateType.ModifiedShader, shaderGraph); diff --git a/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs b/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs index e8cd1c7ae44..2ae7b61d848 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs @@ -547,8 +547,8 @@ public void SortActiveTargets() } // TODO: Need a better way to handle this -#if VFX_GRAPH_10_0_0_OR_NEWER public bool hasVFXCompatibleTarget => activeTargets.Any(o => o.SupportsVFX()); +#if VFX_GRAPH_10_0_0_OR_NEWER public bool hasVFXTarget { get diff --git a/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphDataReadOnly.cs b/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphDataReadOnly.cs index 2b76e67bf08..6e2b5e08339 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphDataReadOnly.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphDataReadOnly.cs @@ -22,5 +22,7 @@ public bool AnyVertexAnimationActive() { return AnyConnectedControl(); } + + public bool IsVFXCompatible() => m_Graph.hasVFXCompatibleTarget; } } diff --git a/Packages/com.unity.shadergraph/Editor/Data/Interfaces/IMaySupportVFX.cs b/Packages/com.unity.shadergraph/Editor/Data/Interfaces/IMaySupportVFX.cs index 88f727d085f..f4cab92d57e 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Interfaces/IMaySupportVFX.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Interfaces/IMaySupportVFX.cs @@ -7,16 +7,7 @@ public interface IMaySupportVFX } static class MaySupportVFXExtensions { - public static bool SupportsVFX(this Target target) - { - var vfxTarget = target as IMaySupportVFX; - return vfxTarget != null && vfxTarget.SupportsVFX(); - } - - public static bool CanSupportVFX(this Target target) - { - var vfxTarget = target as IMaySupportVFX; - return vfxTarget != null && vfxTarget.CanSupportVFX(); - } + public static bool SupportsVFX(this Target target) => target is IMaySupportVFX vfxTarget && vfxTarget.SupportsVFX(); + public static bool CanSupportVFX(this Target target) => target is IMaySupportVFX vfxTarget && vfxTarget.CanSupportVFX(); } } diff --git a/Packages/com.unity.visualeffectgraph/Editor/Core/VFXSRPBinder.cs b/Packages/com.unity.visualeffectgraph/Editor/Core/VFXSRPBinder.cs index 263641b13ab..d7852f67bd2 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Core/VFXSRPBinder.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Core/VFXSRPBinder.cs @@ -31,6 +31,7 @@ public struct ShaderGraphBinder abstract public string SRPAssetTypeStr { get; } abstract public Type SRPOutputDataType { get; } + public abstract bool IsShaderVFXCompatible(Shader shader); public virtual void SetupMaterial(Material mat, bool hasMotionVector = false, bool hasShadowCasting = false, ShaderGraphVfxAsset shaderGraph = null) { } public virtual bool TryGetQueueOffset(ShaderGraphVfxAsset shaderGraph, VFXMaterialSerializedSettings materialSettings, out int queueOffset) diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs index d09756f8690..40f21eef0fd 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs @@ -4,10 +4,12 @@ using System.Collections.ObjectModel; using System.Linq; using System.Reflection; + using UnityEditor.VFX.UI; using UnityEngine; using UnityEngine.VFX; using UnityEngine.Profiling; +using UnityEditor.ShaderGraph.Internal; using UnityObject = UnityEngine.Object; @@ -196,56 +198,111 @@ static void CheckCompilationVersion() serializedVFXManager.ApplyModifiedProperties(); AssetDatabase.StartAssetEditing(); - foreach (var guid in allVisualEffectAssets) + try { - string path = AssetDatabase.GUIDToAssetPath(guid); + foreach (var guid in AssetDatabase.FindAssets("t:VisualEffectAsset")) + { + var path = AssetDatabase.GUIDToAssetPath(guid); - AssetDatabase.ImportAsset(path); + AssetDatabase.ImportAsset(path); + } + + VFXAssetManager.ImportAllVFXShaders(); + } + finally + { + AssetDatabase.StopAssetEditing(); } - AssetDatabase.StopAssetEditing(); } } } class VFXAssetManager : EditorWindow { - public static List GetAllVisualEffectObjects() + public static Dictionary GetAllVisualEffectObjects() { - var vfxObjects = new List(); + var allVisualEffectObjects = new Dictionary(); var vfxObjectsGuid = AssetDatabase.FindAssets("t:VisualEffectObject"); foreach (var guid in vfxObjectsGuid) { - string assetPath = AssetDatabase.GUIDToAssetPath(guid); + var assetPath = AssetDatabase.GUIDToAssetPath(guid); var vfxObj = AssetDatabase.LoadAssetAtPath(assetPath); if (vfxObj != null) { - vfxObjects.Add(vfxObj); + allVisualEffectObjects[vfxObj] = assetPath; } } - return vfxObjects; + + return allVisualEffectObjects; } - public static void Build(bool forceDirty = false) + public static Dictionary GetAllShaderGraph() { - var vfxObjects = GetAllVisualEffectObjects(); - - foreach (var vfxObj in vfxObjects) + var allShaderGraphObjects = new Dictionary(); + var shaderGraphGuids = AssetDatabase.FindAssets("t:Shader"); + foreach (var guid in shaderGraphGuids) { - if (VFXViewPreference.advancedLogs) - Debug.Log(string.Format("Recompile VFX asset: {0} ({1})", vfxObj, AssetDatabase.GetAssetPath(vfxObj))); + var assetPath = AssetDatabase.GUIDToAssetPath(guid); + var shaderGraph = AssetDatabase.LoadAssetAtPath(assetPath); + if (shaderGraph != null) + { + allShaderGraphObjects[shaderGraph] = assetPath; + } + } + + return allShaderGraphObjects; + } - var resource = vfxObj.GetResource(); - if (resource != null) + // Import VFX shader graph assets + // Because some shader compatible with VFX can be there before the Visual Effect package is installed + // We must re-import them to generate the ShaderGraphVfxAsset + public static void ImportAllVFXShaders() + { + var currentSrpBinder = VFXLibrary.currentSRPBinder; + if (currentSrpBinder != null) + { + foreach (var (shader, path) in GetAllShaderGraph()) { - VFXGraph graph = resource.GetOrCreateGraph(); - AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); - if (forceDirty) - EditorUtility.SetDirty(resource); + var assets = AssetDatabase.LoadAllAssetsAtPath(path); + if (assets.OfType().Any()) + { + continue; + } + + if (shader != null && currentSrpBinder.IsShaderVFXCompatible(shader)) + { + AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); + } } } + } + + public static void Build(bool forceDirty = false) + { + AssetDatabase.StartAssetEditing(); + try + { + foreach (var vfxObj in GetAllVisualEffectObjects()) + { + if (VFXViewPreference.advancedLogs) + Debug.Log($"Recompile VFX asset: {vfxObj.Key} ({vfxObj.Value})"); - VFXExpression.ClearCache(); - EditorUtility.UnloadUnusedAssetsImmediate(); - GC.Collect(); + var resource = VisualEffectResource.GetResourceAtPath(vfxObj.Value); + if (resource != null) + { + AssetDatabase.ImportAsset(vfxObj.Value); + if (forceDirty) + EditorUtility.SetDirty(resource); + } + } + + VFXExpression.ClearCache(); + + ImportAllVFXShaders(); + } + finally + { + AssetDatabase.StopAssetEditing(); + } } [MenuItem("Edit/VFX/Rebuild And Save All VFX Graphs", priority = 320)] From 9bba61a3afb966407c067b8c93fe837828e5e55a Mon Sep 17 00:00:00 2001 From: Pieterjan Bartels Date: Tue, 10 Oct 2023 15:48:39 +0000 Subject: [PATCH 3/6] [Port] [2023.1] UUM-47230: allow changing number of lights in path tracing light list This is a backport based on https://github.cds.internal.unity3d.com/unity/unity/pull/35672 for branch 2023.1/staging. This PR is in response to this bug-report: https://jira.unity3d.com/browse/UUM-47230 The artefacts reported are caused by a limit on the maximum number of lights in local neighborhoods in the path tracer. This PR allows users to change this limit through [the shader config mechanism](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@17.0/manual/HDRP-Config-Package.html). --- .../Runtime/ShaderConfig.cs | 28 ++++++++++++++++++- .../Runtime/ShaderConfig.cs.hlsl | 1 + .../Documentation~/HDRP-Config-Package.md | 2 ++ .../Ray-Tracing-Path-Tracing.md | 8 ++++++ .../Runtime/Lighting/LightLoop/LightLoop.cs | 2 +- .../PathTracing/Shaders/PathTracingLight.hlsl | 2 +- .../local.gtf.references/package.json | 14 ++++++++++ .../local.gtf.references/package.json.meta | 7 +++++ .../local.utf.references/package.json | 16 +++++++++++ .../local.utf.references/package.json.meta | 7 +++++ 10 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 Tests/SRPTests/Packages/local.gtf.references/package.json create mode 100644 Tests/SRPTests/Packages/local.gtf.references/package.json.meta create mode 100644 Tests/SRPTests/Packages/local.utf.references/package.json create mode 100644 Tests/SRPTests/Packages/local.utf.references/package.json.meta diff --git a/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs b/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs index 9948cc99edd..7cca2f0c265 100644 --- a/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs +++ b/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs @@ -15,6 +15,15 @@ internal enum FPTLMaxLightSizes Ultra = 255 } + internal enum PathTracingLightListSizes + { + Low = 8, + Medium = 16, + High = 32, + Ultra = 64 + } + + /// /// Project-wide shader configuration options. /// @@ -53,7 +62,18 @@ public enum ShaderOptions /// Lower count will mean some memory savings. /// Note: For any rendering bigger than 4k (in native) it is recommended to use Low count per tile, to avoid possible artifacts. /// - FPTLMaxLightCount = FPTLMaxLightSizes.High + FPTLMaxLightCount = FPTLMaxLightSizes.High, + + /// + /// The upper limit for the maximum amount of elements per cell in the light cluster. The maximum can be set in the project settings. This value caps the maximum. + /// + LightClusterMaxCellElementCount = 24, + + /// + /// Maximum number of lights used in the path tracer light list. This number can be one of the prespecified possibilities in PathTracingLightListSizes, or can be chosen manually. + /// Lower count will mean some memory savings. + /// + PathTracingMaxLightCount = PathTracingLightListSizes.Medium }; // Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl @@ -94,6 +114,12 @@ public class ShaderConfig /// Indicates the maximum number of lights available for Fine Prunning Tile Lighting. /// public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount; + /// Indicates the cap on the maximum number of elements per cell in the light cluster. + /// + public const int LightClusterMaxCellElementCount = (int)ShaderOptions.LightClusterMaxCellElementCount; + /// Indicates the maximum number of lights in the path tracing light list. + /// + public static int PathTracingMaxLightCount = (int)ShaderOptions.PathTracingMaxLightCount; } /// diff --git a/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl b/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl index adae23cd603..1dea1fe82a3 100644 --- a/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl +++ b/Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl @@ -16,6 +16,7 @@ #define SHADEROPTIONS_BARN_DOOR (0) #define SHADEROPTIONS_GLOBAL_MIP_BIAS (1) #define SHADEROPTIONS_FPTLMAX_LIGHT_COUNT (63) +#define SHADEROPTIONS_PATH_TRACING_MAX_LIGHT_COUNT (16) // // UnityEngine.Rendering.HighDefinition.InternalLightCullingDefs: static fields diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md index d3eca1c1745..f19b7083099 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md @@ -7,6 +7,8 @@ For example, you can use it to: * Disable Area Light. * Disable Pre-exposition. * Enable [camera-relative rendering](Camera-Relative-Rendering.md). +* Increase the size of the tile and cluster light list for rasterization. +* Increase the size of [the Path Tracing light list](Ray-Tracing-Path-Tracing.md). ## Using the HDRP Config package diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Path-Tracing.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Path-Tracing.md index 3f0d5185f59..17bbf6f5554 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Path-Tracing.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Path-Tracing.md @@ -163,6 +163,14 @@ If there is any noise that affects the exposure in the final converged frame, ad * **Limit Max** +## Path tracing and Light sources + +Due to the fundamentally different nature of Path Tracing, light sources are queried differently. To support this, the path tracer needs to build some additional data structures that contain light source information. These data structures limit the maximum number of lights that can be evaluated in local neighborhoods. In the current implementation, there are two such data structures. + +The first one is the [Ray Tracing Light Cluster](Ray-Tracing-Light-Cluster.md). It is used to resolve the lights around a specific point. The maximum number of lights per cell in this cluster can be increased if necessary. + +The second one is the Path Tracing light list, an internal data structure used to capture all light sources relevant to a specific path segment. If too many light sources are close to each other, they might not all fit in the light list. This might result in artifacts. To remove these artifacts, you can change the `PathTracingMaxLightCount` setting through the [HDRP Config mechanism](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/HDRP-Config-Package.html). + ## Limitations This section contains information on the limitations of HDRP's path tracing implementation. Mainly, this is a list of features that HDRP supports in its rasterized render pipeline, but not in its path-traced render pipeline. diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index deab2080765..93504fa9e3c 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -269,7 +269,7 @@ public partial class HDRenderPipeline internal const int k_MaxDecalsOnScreen = 2048; internal const int k_MaxPlanarReflectionsOnScreen = 16; internal const int k_MaxCubeReflectionsOnScreen = 64; - internal const int k_MaxLightsPerClusterCell = 24; + internal const int k_MaxLightsPerClusterCell = ShaderConfig.LightClusterMaxCellElementCount; internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f; #if UNITY_SWITCH diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl index dcbdef7f858..f3f72d1bf72 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl @@ -24,7 +24,7 @@ // How many lights (at most) do we support at one given shading point // FIXME: hardcoded limits are evil, this LightList should instead be put together in C# -#define MAX_LOCAL_LIGHT_COUNT 16 +#define MAX_LOCAL_LIGHT_COUNT SHADEROPTIONS_PATH_TRACING_MAX_LIGHT_COUNT #define MAX_DISTANT_LIGHT_COUNT 4 #define DELTA_PDF 1000000.0 diff --git a/Tests/SRPTests/Packages/local.gtf.references/package.json b/Tests/SRPTests/Packages/local.gtf.references/package.json new file mode 100644 index 00000000000..3404dcdd4f4 --- /dev/null +++ b/Tests/SRPTests/Packages/local.gtf.references/package.json @@ -0,0 +1,14 @@ +{ + "displayName": "Local Graphics Test Framework references", + "name": "local.gtf.references", + "version": "1.0.0", + "unity": "2019.1", + "description": "This is a dummy package that contains references to other packages needed for tests in the repository.", + "keywords": [ + "test" + ], + "category": "Libraries", + "dependencies": { + "com.unity.testframework.graphics": "7.15.0-exp.1" + } +} diff --git a/Tests/SRPTests/Packages/local.gtf.references/package.json.meta b/Tests/SRPTests/Packages/local.gtf.references/package.json.meta new file mode 100644 index 00000000000..051399e566e --- /dev/null +++ b/Tests/SRPTests/Packages/local.gtf.references/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5af65b1ef04f1244881103972bcbec61 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/SRPTests/Packages/local.utf.references/package.json b/Tests/SRPTests/Packages/local.utf.references/package.json new file mode 100644 index 00000000000..7ee54e884f1 --- /dev/null +++ b/Tests/SRPTests/Packages/local.utf.references/package.json @@ -0,0 +1,16 @@ +{ + "displayName": "Local Unity Test Framework references", + "name": "local.utf.references", + "version": "1.0.0", + "unity": "2019.1", + "description": "This is a dummy package that contains references to other packages needed for tests in the repository.", + "keywords": [ + "test" + ], + "category": "Libraries", + "dependencies": { + "com.unity.test-framework": "1.3.3", + "com.unity.test-framework.build": "0.0.1-preview.14", + "com.unity.test-framework.utp-reporter": "1.1.0-preview" + } +} diff --git a/Tests/SRPTests/Packages/local.utf.references/package.json.meta b/Tests/SRPTests/Packages/local.utf.references/package.json.meta new file mode 100644 index 00000000000..5523ff4f081 --- /dev/null +++ b/Tests/SRPTests/Packages/local.utf.references/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 04c5a0f14abccc943b76bd3b5096712d +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 837944f21c41583c5a90f02b2106547cf843bb1a Mon Sep 17 00:00:00 2001 From: Tim Cannell Date: Thu, 12 Oct 2023 09:36:28 +0000 Subject: [PATCH 4/6] [content automatically redacted] touching PlatformDependent folder --- .../com.unity.render-pipelines.high-definition/package.json | 4 ++-- Packages/com.unity.render-pipelines.universal/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/package.json b/Packages/com.unity.render-pipelines.high-definition/package.json index bdeb4242028..8cf81a24c04 100644 --- a/Packages/com.unity.render-pipelines.high-definition/package.json +++ b/Packages/com.unity.render-pipelines.high-definition/package.json @@ -7,7 +7,7 @@ "dependencies": { "com.unity.mathematics": "1.2.4", "com.unity.collections": "1.4.0", - "com.unity.burst": "1.8.4", + "com.unity.burst": "1.8.9", "com.unity.modules.video": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.imageconversion": "1.0.0", @@ -66,4 +66,4 @@ "path": "Samples~/WaterSamples" } ] -} \ No newline at end of file +} diff --git a/Packages/com.unity.render-pipelines.universal/package.json b/Packages/com.unity.render-pipelines.universal/package.json index e4260add7fd..d9bed449f42 100644 --- a/Packages/com.unity.render-pipelines.universal/package.json +++ b/Packages/com.unity.render-pipelines.universal/package.json @@ -6,7 +6,7 @@ "displayName": "Universal RP", "dependencies": { "com.unity.mathematics": "1.2.1", - "com.unity.burst": "1.8.4", + "com.unity.burst": "1.8.9", "com.unity.render-pipelines.core": "15.0.7", "com.unity.shadergraph": "15.0.7" }, @@ -25,4 +25,4 @@ "path": "Samples~/URPPackageSamples" } ] -} \ No newline at end of file +} From 0469d41050b371828359c50808d2325b0b9bb7fa Mon Sep 17 00:00:00 2001 From: Kleber Garcia Date: Fri, 13 Oct 2023 00:23:08 +0000 Subject: [PATCH 5/6] [Backport 2023.1][Jira # UUM-37206] Fix temporal upscaling flag to skip temporal upscalers and TAA Adding new checkbox to allow materials to be excluded from temporal anti aliasing. For now, this checkbox is only exposed to transparent materials since they are the only ones that can fit a stencil bit for such operation. The materials that go through this path will generate a special mask (stencil or a bit mask in DLSS) that just performs spatial upscaling. This checkbox is ideal for surfaces that contain texture scrolling that has to be neat and does not have velocity information. Comparison (left is flag off, right is flag on, notice the scrolling is more clear and less blury than the one in the right): ![bluryTextureScroll](https://media.github.cds.internal.unity3d.com/user/3327/files/e1f0a283-e471-4f91-a015-f874da0915db) ![image](https://media.github.cds.internal.unity3d.com/user/3327/files/76046247-c229-4e9d-abda-dba342fdfc23) --- .../Documentation~/master-stack-eye.md | 1 + .../Documentation~/master-stack-fabric.md | 1 + .../Documentation~/master-stack-hair.md | 1 + .../Documentation~/master-stack-stacklit.md | 1 + .../Documentation~/master-stack-unlit.md | 1 + .../surface-options/exclude-from-taau.md | 9 +++ .../ShaderGraph/HDSubShaderUtilities.cs | 21 +++++-- .../ShaderGraph/SurfaceOptionPropertyBlock.cs | 1 + .../ShaderGraph/TargetData/SystemData.cs | 8 +++ .../Material/UIBlocks/SurfaceOptionUIBlock.cs | 7 +++ .../Water/ShaderGraph/WaterSubTarget.cs | 4 +- .../Outputs/VFXAbstractDistortionOutput.cs | 2 +- .../Outputs/VFXAbstractParticleHDRPOutput.cs | 2 +- .../Outputs/VFXVolumetricFogOutput.cs | 2 +- .../Editor/VFXGraph/VFXHDRPSubOutput.cs | 10 ++-- .../Runtime/Material/AxF/AxFAPI.cs | 3 +- .../Material/LayeredLit/LayeredLitAPI.cs | 4 +- .../Runtime/Material/Lit/BaseLitAPI.cs | 55 ++++++++++++++++--- .../Runtime/Material/Lit/LitAPI.cs | 3 +- .../Runtime/Material/ShaderGraphAPI.cs | 3 +- .../Runtime/Material/Unlit/UnlitAPI.cs | 3 +- .../HDRenderPipeline.PostProcess.cs | 10 ++-- .../Runtime/RenderPipeline/HDStencilUsage.cs | 2 +- .../RenderPipeline/HDStringConstants.cs | 2 + .../VFXAbstractParticleURPLitOutput.cs | 2 +- .../Context-OutputSharedSettings.md | 22 ++++---- .../VFXAbstractParticleOutput.cs | 4 +- .../VFXAbstractRenderedOutput.cs | 6 +- .../Editor/Models/Contexts/VFXSRPSubOutput.cs | 2 +- .../VFXShaderGraphParticleOutput.cs | 2 +- 30 files changed, 142 insertions(+), 52 deletions(-) create mode 100644 Packages/com.unity.render-pipelines.high-definition/Documentation~/snippets/shader-properties/surface-options/exclude-from-taau.md diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-eye.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-eye.md index 5731bef0716..5aee0724982 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-eye.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-eye.md @@ -138,6 +138,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add [!include[](snippets/shader-properties/surface-options/alpha-clipping.md)] [!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)] [!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)] +[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)] [!include[](snippets/shader-properties/surface-options/double-sided-mode.md)] [!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)] [!include[](snippets/shader-properties/surface-options/receive-decals.md)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-fabric.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-fabric.md index 9dc2fee092f..9770f228521 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-fabric.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-fabric.md @@ -135,6 +135,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add [!include[](snippets/shader-properties/surface-options/alpha-clipping.md)] [!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)] [!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)] +[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)] [!include[](snippets/shader-properties/surface-options/double-sided-mode.md)] [!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)] [!include[](snippets/shader-properties/surface-options/receive-decals.md)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-hair.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-hair.md index 030953864b7..e05ee6adea4 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-hair.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-hair.md @@ -238,6 +238,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add [!include[](snippets/shader-properties/surface-options/alpha-clipping.md)] [!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)] [!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)] +[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)] [!include[](snippets/shader-properties/surface-options/double-sided-mode.md)] [!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)] [!include[](snippets/shader-properties/surface-options/receive-decals.md)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-stacklit.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-stacklit.md index e4a4077c705..01b69b5056b 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-stacklit.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-stacklit.md @@ -151,6 +151,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add [!include[](snippets/shader-properties/surface-options/alpha-clipping.md)] [!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)] [!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)] +[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)] [!include[](snippets/shader-properties/surface-options/double-sided-mode.md)] [!include[](snippets/shader-properties/surface-options/fragment-normal-space.md)] [!include[](snippets/shader-properties/surface-options/receive-decals.md)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-unlit.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-unlit.md index ac261d6706c..c080f96f810 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-unlit.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/master-stack-unlit.md @@ -119,6 +119,7 @@ Depending on the [Graph Settings](#graph-settings) you use, Shader Graph can add [!include[](snippets/shader-properties/surface-options/alpha-clipping.md)] [!include[](snippets/shader-properties/surface-options/use-shadow-threshold.md)] [!include[](snippets/shader-properties/surface-options/alpha-to-mask.md)] +[!include[](snippets/shader-properties/surface-options/exclude-from-taau.md)] [!include[](snippets/shader-properties/surface-options/double-sided.md)] [!include[](snippets/shader-properties/surface-options/ss-depth-offset.md)] [!include[](snippets/shader-properties/surface-options/conservative-depth-offset.md)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/snippets/shader-properties/surface-options/exclude-from-taau.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/snippets/shader-properties/surface-options/exclude-from-taau.md new file mode 100644 index 00000000000..d368aa22130 --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/snippets/shader-properties/surface-options/exclude-from-taau.md @@ -0,0 +1,9 @@ + +- **Exclude from Temporal Upscaling and Anti Aliasing** + + +Indicates whether the render pipeline excludes this surface from any temporal upscalers (TU) and temporal anti-aliasing (AA). This is useful when the surface looks blurry when TAA or any Temporal Upscaler is enabled and especially useful for animated textures (such as video player in a surface). +This setting only works for Transparent surfaces due to the fact that there are no more stencil bits open. + + + diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubShaderUtilities.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubShaderUtilities.cs index 321dd410069..80520d3512d 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubShaderUtilities.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubShaderUtilities.cs @@ -119,11 +119,24 @@ public static void AddStencilShaderProperties(PropertyCollector collector, Syste collector.AddToggleProperty(kEnableBlendModePreserveSpecularLighting, false, HLSLDeclaration.UnityPerMaterial); } + bool excludeFromTUAndAA = systemData?.excludeFromTUAndAA ?? false; + collector.AddToggleProperty(kExcludeFromTUAndAA, excludeFromTUAndAA); + // Configure render state - BaseLitAPI.ComputeStencilProperties(receivesLighting, forwardOnly, ssrStencil, splitLighting, out int stencilRef, out int stencilWriteMask, - out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer, - out int stencilRefMV, out int stencilWriteMaskMV - ); + BaseLitAPI.ComputeStencilProperties( + receivesLighting, + forwardOnly, + ssrStencil, + splitLighting, + excludeFromTUAndAA, + out int stencilRef, + out int stencilWriteMask, + out int stencilRefDepth, + out int stencilWriteMaskDepth, + out int stencilRefGBuffer, + out int stencilWriteMaskGBuffer, + out int stencilRefMV, + out int stencilWriteMaskMV); // All these properties values will be patched with the material keyword update collector.AddIntProperty("_StencilRef", stencilRef); diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs index 4cced457955..0db4ecc3fe4 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs @@ -128,6 +128,7 @@ protected override void CreatePropertyGUI() } AddProperty(customVelocityText, () => systemData.customVelocity, (newValue) => systemData.customVelocity = newValue); + AddProperty(excludeFromTUAndAAText, () => systemData.excludeFromTUAndAA, (newValue) => systemData.excludeFromTUAndAA = newValue); AddProperty(tessellationEnableText, () => systemData.tessellation, (newValue) => systemData.tessellation = newValue); if (systemData.tessellation) diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs index 49d585bc2d8..29515619e31 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs @@ -90,6 +90,14 @@ public bool alphaTest set => m_AlphaTest = value; } + [SerializeField] + bool m_ExcludeFromTUAndAA = false; + public bool excludeFromTUAndAA + { + get => m_ExcludeFromTUAndAA; + set => m_ExcludeFromTUAndAA = value; + } + [SerializeField, Obsolete("Keep for migration")] internal bool m_TransparentDepthPrepass; diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs index 50167de4928..627481cf58a 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs @@ -135,6 +135,8 @@ internal static class Styles public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Controls the strength of the Specular AA reduction. Higher values give a more blurry result and less aliasing."); public static GUIContent specularAAThresholdText = new GUIContent("Threshold", "Controls the effect of Specular AA reduction. A values of 0 does not apply reduction, higher values allow higher reduction."); + public static GUIContent excludeFromTUAndAAText = new GUIContent("Exclude From Temporal Upscalers and Anti Aliasing", "When enabled, the current material wont be temporaly sampled during TAA and will have reduced ghosting on upscalers."); + // SSR public static GUIContent receivesSSRText = new GUIContent("Receive SSR", "When enabled, this Material can receive screen space reflections."); public static GUIContent receivesSSRTransparentText = new GUIContent("Receive SSR Transparent", "When enabled, this Material can receive screen space reflections. This will force a transparent depth prepass on the object if HDRP supports it."); @@ -182,6 +184,7 @@ enum DisplacementModeLitTessellation { None = DisplacementMode.None, Tessellatio MaterialProperty specularAAThreshold = null; const string kSpecularAAThreshold = "_SpecularAAThreshold"; MaterialProperty transmissionEnable = null; + MaterialProperty excludeFromTUAndAA = null; // Per pixel displacement params MaterialProperty ppdMinSamples = null; @@ -311,6 +314,7 @@ public override void LoadMaterialProperties() blendMode = FindProperty(kBlendMode); transmissionEnable = FindProperty(kTransmissionEnable); + excludeFromTUAndAA = FindProperty(kExcludeFromTUAndAA); if ((m_Features & Features.DoubleSidedNormalMode) != 0) { @@ -768,6 +772,9 @@ protected void DrawLitSurfaceOptions() materialEditor.ShaderProperty(receivesSSR, Styles.receivesSSRText); } + if (excludeFromTUAndAA != null && BaseLitAPI.CompatibleWithExcludeFromTUAndAA(surfaceTypeValue, renderQueue)) + materialEditor.ShaderProperty(excludeFromTUAndAA, Styles.excludeFromTUAndAAText); + if (enableGeometricSpecularAA != null) { materialEditor.ShaderProperty(enableGeometricSpecularAA, Styles.enableGeometricSpecularAAText); diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/Water/ShaderGraph/WaterSubTarget.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/Water/ShaderGraph/WaterSubTarget.cs index 28457802702..8a5fcde5cf9 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/Water/ShaderGraph/WaterSubTarget.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/Water/ShaderGraph/WaterSubTarget.cs @@ -420,7 +420,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera stencilRefWaterVar.displayName = "Stencil Water Ref GBuffer"; stencilRefWaterVar.hidden = true; stencilRefWaterVar.floatType = FloatType.Default; - stencilRefWaterVar.value = (int)StencilUsage.WaterSurface; + stencilRefWaterVar.value = (int)(StencilUsage.WaterSurface | StencilUsage.ExcludeFromTUAndAA); stencilRefWaterVar.overrideHLSLDeclaration = true; stencilRefWaterVar.hlslDeclarationOverride = HLSLDeclaration.Global; stencilRefWaterVar.generatePropertyBlock = false; @@ -431,7 +431,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera stencilWriteMaskWaterVar.displayName = "Stencil Water Write Mask GBuffer"; stencilWriteMaskWaterVar.hidden = true; stencilWriteMaskWaterVar.floatType = FloatType.Default; - stencilWriteMaskWaterVar.value = (int)StencilUsage.WaterSurface; + stencilWriteMaskWaterVar.value = (int)(StencilUsage.WaterSurface | StencilUsage.ExcludeFromTUAndAA); stencilWriteMaskWaterVar.overrideHLSLDeclaration = true; stencilWriteMaskWaterVar.hlslDeclarationOverride = HLSLDeclaration.Global; stencilWriteMaskWaterVar.generatePropertyBlock = false; diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractDistortionOutput.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractDistortionOutput.cs index 8a67834da89..22e9b33607d 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractDistortionOutput.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractDistortionOutput.cs @@ -41,7 +41,7 @@ protected override IEnumerable filteredOutSettings yield return "castShadows"; yield return "sort"; yield return "useAlphaClipping"; - yield return "excludeFromTAA"; + yield return "excludeFromTUAndAA"; } } diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPOutput.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPOutput.cs index 14a98a8e7b2..277bdc7b95c 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPOutput.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPOutput.cs @@ -249,7 +249,7 @@ protected override IEnumerable filteredOutSettings { yield return "onlyAmbientLighting"; yield return "preserveSpecularLighting"; - yield return "excludeFromTAA"; + yield return "excludeFromTUAndAA"; } } } diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXVolumetricFogOutput.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXVolumetricFogOutput.cs index b130f156567..bece7205d32 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXVolumetricFogOutput.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXVolumetricFogOutput.cs @@ -208,7 +208,7 @@ protected override IEnumerable filteredOutSettings yield return nameof(sortMode); yield return nameof(enableRayTracing); yield return nameof(revertSorting); - yield return nameof(excludeFromTAA); + yield return nameof(excludeFromTUAndAA); yield return nameof(computeCulling); yield return nameof(vfxSystemSortPriority); yield return nameof(sortingPriority); diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs index e6e55882de7..fbcd4c09e2a 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubOutput.cs @@ -30,7 +30,7 @@ public override bool supportsMotionVector && transparentRenderQueue != TransparentRenderQueue.AfterPostProcessing; } } - public override bool supportsExcludeFromTAA { get { return !owner.isBlendModeOpaque; } } + public override bool supportsExcludeFromTUAndAA { get { return !owner.isBlendModeOpaque; } } bool GeneratesWithShaderGraph() { @@ -199,12 +199,12 @@ private void GetStencilStateGBuffer(out int stencilWriteMask, out int stencilRef stencilRef |= hasSubsurfaceScattering ? (int)StencilUsage.SubsurfaceScattering : 0; } - private void GetStencilStateForward(out int stencilWriteMask, out int stencilRef, bool excludeFromTAA) + private void GetStencilStateForward(out int stencilWriteMask, out int stencilRef, bool excludeFromTUAndAA) { GetStencilStateCommon(out stencilWriteMask, out stencilRef); - stencilWriteMask |= excludeFromTAA ? (int)StencilUsage.ExcludeFromTAA : 0; - stencilRef |= excludeFromTAA ? (int)StencilUsage.ExcludeFromTAA : 0; + stencilWriteMask |= excludeFromTUAndAA ? (int)StencilUsage.ExcludeFromTUAndAA : 0; + stencilRef |= excludeFromTUAndAA ? (int)StencilUsage.ExcludeFromTUAndAA : 0; } public override IEnumerable> GetStencilStateOverridesStr() @@ -222,7 +222,7 @@ public override IEnumerable> GetStencilSta yield return CreateStencilStateOverrideStr("${VFXStencilGBuffer}", stencilWriteMaskGBuffer, stencilRefGBuffer); int stencilWriteMaskForward, stencilRefForward; - GetStencilStateForward(out stencilWriteMaskForward, out stencilRefForward, owner.hasExcludeFromTAA); + GetStencilStateForward(out stencilWriteMaskForward, out stencilRefForward, owner.hasExcludeFromTUAndAA); yield return CreateStencilStateOverrideStr("${VFXStencilForward}", stencilWriteMaskForward, stencilRefForward); } diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFAPI.cs index 3d4244532f1..719a30a33a0 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFAPI.cs @@ -159,7 +159,8 @@ public static void ValidateMaterial(Material material) CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.HasProperty(kEnableGeometricSpecularAA) && material.GetFloat(kEnableGeometricSpecularAA) > 0.0f); CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", material.HasProperty(kSpecularOcclusionMode) && material.GetFloat(kSpecularOcclusionMode) == 0.0f); - BaseLitAPI.SetupStencil(material, receivesLighting: true, receivesSSR: ssrEnabled, useSplitLighting: false); + bool excludeFromTUAndAA = BaseLitAPI.CompatibleWithExcludeFromTUAndAA(material) && material.GetInt(kExcludeFromTUAndAA) != 0; + BaseLitAPI.SetupStencil(material, receivesLighting: true, receivesSSR: ssrEnabled, useSplitLighting: false, excludeFromTUAndAA: excludeFromTUAndAA); // // Patch for raytracing for now: mirror int props as float explicitly // diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitAPI.cs index 5e86d2fd775..5474192e73e 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitAPI.cs @@ -112,7 +112,9 @@ internal static void ValidateMaterial(Material material) SetupLayersMappingKeywords(material); bool receiveSSR = material.GetSurfaceType() == SurfaceType.Opaque ? (material.HasProperty(kReceivesSSR) ? material.GetInt(kReceivesSSR) != 0 : false) : (material.HasProperty(kReceivesSSRTransparent) ? material.GetInt(kReceivesSSRTransparent) != 0 : false); - BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, materialId == MaterialId.LitSSS); + + bool excludeFromTUAndAA = BaseLitAPI.CompatibleWithExcludeFromTUAndAA(material) && material.GetInt(kExcludeFromTUAndAA) != 0; + BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, materialId == MaterialId.LitSSS, excludeFromTUAndAA: excludeFromTUAndAA); for (int i = 0; i < kMaxLayerCount; ++i) { diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs index 2d814a42f5f..6f35761e4c9 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs @@ -126,16 +126,36 @@ static public void SetupBaseLitKeywords(Material material) } } - static public void SetupStencil(Material material, bool receivesLighting, bool receivesSSR, bool useSplitLighting) + static public bool CompatibleWithExcludeFromTUAndAA(SurfaceType surfaceType, int renderQueue) + { + return surfaceType == SurfaceType.Transparent && HDRenderQueue.k_RenderQueue_Transparent.Contains(renderQueue); + } + + static public bool CompatibleWithExcludeFromTUAndAA(Material material) + { + return CompatibleWithExcludeFromTUAndAA(material.GetSurfaceType(), material.renderQueue) && material.HasProperty(kExcludeFromTUAndAA); + } + + static public void SetupStencil(Material material, bool receivesLighting, bool receivesSSR, bool useSplitLighting, bool excludeFromTUAndAA = false) { // To determine if the shader is forward only, we can't rely on the presence of GBuffer pass because that depends on the active subshader, which // depends on the active render pipeline, giving an inconsistent result. The properties of a shader are always the same so it's ok to check them bool forwardOnly = material.shader.FindPropertyIndex(kZTestGBuffer) == -1; - ComputeStencilProperties(receivesLighting, forwardOnly, receivesSSR, useSplitLighting, out int stencilRef, out int stencilWriteMask, - out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer, - out int stencilRefMV, out int stencilWriteMaskMV - ); + ComputeStencilProperties( + receivesLighting, + forwardOnly, + receivesSSR, + useSplitLighting, + excludeFromTUAndAA, + out int stencilRef, + out int stencilWriteMask, + out int stencilRefDepth, + out int stencilWriteMaskDepth, + out int stencilRefGBuffer, + out int stencilWriteMaskGBuffer, + out int stencilRefMV, + out int stencilWriteMaskMV); // As we tag both during motion vector pass and Gbuffer pass we need a separate state and we need to use the write mask if (material.HasProperty(kStencilRef)) @@ -165,9 +185,20 @@ static public void SetupStencil(Material material, bool receivesLighting, bool r } } - static public void ComputeStencilProperties(bool receivesLighting, bool forwardOnly, bool receivesSSR, bool useSplitLighting, out int stencilRef, out int stencilWriteMask, - out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer, - out int stencilRefMV, out int stencilWriteMaskMV) + static public void ComputeStencilProperties( + bool receivesLighting, + bool forwardOnly, + bool receivesSSR, + bool useSplitLighting, + bool excludeFromTUAndAA, + out int stencilRef, + out int stencilWriteMask, + out int stencilRefDepth, + out int stencilWriteMaskDepth, + out int stencilRefGBuffer, + out int stencilWriteMaskGBuffer, + out int stencilRefMV, + out int stencilWriteMaskMV) { // Stencil usage rules: // TraceReflectionRay need to be tagged during depth prepass @@ -221,6 +252,14 @@ static public void ComputeStencilProperties(bool receivesLighting, bool forwardO stencilRefMV |= (int)StencilUsage.IsUnlit; } + if (excludeFromTUAndAA) + { + stencilRefDepth |= (int)StencilUsage.ExcludeFromTUAndAA; + stencilRef |= (int)StencilUsage.ExcludeFromTUAndAA; + stencilWriteMask |= (int)StencilUsage.ExcludeFromTUAndAA; + stencilWriteMaskDepth |= (int)StencilUsage.ExcludeFromTUAndAA; + } + stencilWriteMaskDepth |= (int)StencilUsage.IsUnlit; stencilWriteMaskGBuffer |= (int)StencilUsage.IsUnlit; stencilWriteMaskMV |= (int)StencilUsage.IsUnlit; diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitAPI.cs index 703b52ab188..663417c3278 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitAPI.cs @@ -13,7 +13,8 @@ internal static void ValidateMaterial(Material material) BaseLitAPI.SetupBaseLitMaterialPass(material); bool receiveSSR = material.GetSurfaceType() == SurfaceType.Opaque ? (material.HasProperty(kReceivesSSR) ? material.GetInt(kReceivesSSR) != 0 : false) : (material.HasProperty(kReceivesSSRTransparent) ? material.GetInt(kReceivesSSRTransparent) != 0 : false); - BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, material.GetMaterialId() == MaterialId.LitSSS); + bool excludeFromTUAndAA = BaseLitAPI.CompatibleWithExcludeFromTUAndAA(material) && material.GetInt(kExcludeFromTUAndAA) != 0; + BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, material.GetMaterialId() == MaterialId.LitSSS, excludeFromTUAndAA: excludeFromTUAndAA); BaseLitAPI.SetupDisplacement(material); if (material.HasProperty(kNormalMapSpace)) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/ShaderGraphAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/ShaderGraphAPI.cs index d4876258230..6bd828dc595 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/ShaderGraphAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/ShaderGraphAPI.cs @@ -76,7 +76,8 @@ public static void ValidateLightingMaterial(Material material) } - BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, useSplitLighting); + bool excludeFromTUAndAA = BaseLitAPI.CompatibleWithExcludeFromTUAndAA(material) && material.GetInt(kExcludeFromTUAndAA) != 0; + BaseLitAPI.SetupStencil(material, receivesLighting: true, receiveSSR, useSplitLighting, excludeFromTUAndAA); } public static void ValidateDecalMaterial(Material material) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitAPI.cs index c124d0db713..a3d6445268b 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitAPI.cs @@ -19,7 +19,8 @@ internal static void ValidateMaterial(Material material) // All the bits exclusively related to lit are ignored inside the BaseLitGUI function. bool receivesLighting = (material.HasProperty(kShadowMatteFilter) && material.GetFloat(kShadowMatteFilter) != 0); - BaseLitAPI.SetupStencil(material, receivesLighting: receivesLighting, receivesSSR: false, useSplitLighting: false); + bool excludeFromTUAndAA = BaseLitAPI.CompatibleWithExcludeFromTUAndAA(material) && material.GetInt(kExcludeFromTUAndAA) != 0; + BaseLitAPI.SetupStencil(material, receivesLighting: receivesLighting, receivesSSR: false, useSplitLighting: false, excludeFromTUAndAA: excludeFromTUAndAA); } } } diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index b88e5b02ab4..af0970553e3 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -717,8 +717,8 @@ TextureHandle DoDLSSColorMaskPass(RenderGraph renderGraph, HDCamera hdCamera, Te (DLSSColorMaskPassData data, RenderGraphContext ctx) => { Rect targetViewport = new Rect(0.0f, 0.0f, data.destWidth, data.destHeight); - data.colorMaskMaterial.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.ExcludeFromTAA); - data.colorMaskMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.ExcludeFromTAA); + data.colorMaskMaterial.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.ExcludeFromTUAndAA); + data.colorMaskMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.ExcludeFromTUAndAA); ctx.cmd.SetViewport(targetViewport); ctx.cmd.DrawProcedural(Matrix4x4.identity, data.colorMaskMaterial, 0, MeshTopology.Triangles, 3, 1, null); }); @@ -1658,7 +1658,7 @@ void PrepareTAAPassData(RenderGraph renderGraph, RenderGraphBuilder builder, Tem const float offset = postDofMin - TAABaseBlendFactorMin * scale; float taaBaseBlendFactor = postDoF ? camera.taaBaseBlendFactor * scale + offset : camera.taaBaseBlendFactor; - passData.taaParameters1 = new Vector4(camera.camera.cameraType == CameraType.SceneView ? 0.2f : 1.0f - taaBaseBlendFactor, taaSampleWeights[0], (int)StencilUsage.ExcludeFromTAA, historyContrastLerp); + passData.taaParameters1 = new Vector4(camera.camera.cameraType == CameraType.SceneView ? 0.2f : 1.0f - taaBaseBlendFactor, taaSampleWeights[0], (int)StencilUsage.ExcludeFromTUAndAA, historyContrastLerp); passData.taaFilterWeights = taaSampleWeights; @@ -1833,8 +1833,8 @@ TextureHandle DoTemporalAntialiasing(RenderGraph renderGraph, HDCamera hdCamera, } var mpb = ctx.renderGraphPool.GetTempMaterialPropertyBlock(); - mpb.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.ExcludeFromTAA); - mpb.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.ExcludeFromTAA); + mpb.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.ExcludeFromTUAndAA); + mpb.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.ExcludeFromTUAndAA); mpb.SetTexture(HDShaderIDs._CameraMotionVectorsTexture, data.motionVecTexture); mpb.SetTexture(HDShaderIDs._InputTexture, source); mpb.SetTexture(HDShaderIDs._InputHistoryTexture, data.prevHistory); diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStencilUsage.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStencilUsage.cs index cbc269dc153..828b9880bf6 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStencilUsage.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStencilUsage.cs @@ -24,7 +24,7 @@ internal enum StencilUsage // --- Following bits are used exclusively for what happens after opaque --- WaterExclusion = (1 << 0), // Prevents water surface from being rendered. - ExcludeFromTAA = (1 << 1), // Disable Temporal Antialiasing for certain objects + ExcludeFromTUAndAA = (1 << 1), // Disable Temporal Upscaling and Antialiasing for certain objects DistortionVectors = (1 << 2), // Distortion pass - reset after distortion pass, shared with SMAA SMAA = (1 << 2), // Subpixel Morphological Antialiasing // Reserved TraceReflectionRay = (1 << 3) for transparent SSR or RTR diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index e76af300819..31b4c3ae9ed 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -1295,6 +1295,8 @@ public static class HDMaterialProperties public const string kAffectSmoothness = "_AffectSmoothness"; /// Enable affect Emission (decal only. public const string kAffectEmission = "_AffectEmission"; + /// Exclude from temporal upsamplers and anti aliasing. + public const string kExcludeFromTUAndAA = "_ExcludeFromTUAndAA"; // Internal properties diff --git a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXAbstractParticleURPLitOutput.cs b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXAbstractParticleURPLitOutput.cs index d560743ca12..408114483bb 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXAbstractParticleURPLitOutput.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/VFXAbstractParticleURPLitOutput.cs @@ -426,7 +426,7 @@ protected override IEnumerable filteredOutSettings else if ((colorMode & ColorMode.Emissive) != 0) yield return nameof(useEmissive); - yield return nameof(excludeFromTAA); + yield return nameof(excludeFromTUAndAA); } } diff --git a/Packages/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md b/Packages/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md index 588a8ebf7f4..08e161df5a7 100644 --- a/Packages/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md +++ b/Packages/com.unity.visualeffectgraph/Documentation~/Context-OutputSharedSettings.md @@ -8,17 +8,17 @@ All outputs share these settings and property ports. The only exception is the S ## Render State Settings -| **Setting** | **Type** | **Description** | -| --------------------------- | -------- | ------------------------------------------------------------ | -| **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. | -| **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. | -| **Cull Mode** | Enum | **(Inspector)** Specifies the cull mode to use with the system. The options are:
• **Default**: Use the default cull mode for the system.
• **Front**: Culls front faces of particles in the system.
• **Back**: Culls back faces of particles in the system.
• **Off**: Culls no faces. This mode makes the output render both front and back faces. | -| **Z Write Mode** | Enum | **(Inspector)** Specifies the depth writing mode to use with the system. The options are:
• **Default**: Uses the default depth write mode for the system. This is typically **On** for opaque and **Off** for transparent.
• **On**: Enables depth writing for the system.
• **Off**: Disables depth writing for the system. | -| **Z Test Mode** | Enum | **(Inspector)** Specifies the depth test mode to use with the system. The options are:
• **Default**: Use the default depth testing mode for the system. This is typically **On**.
• **On**: Enables depth testing for the system.
• **Off**: Disables depth testing for the system. This means the output renders regardless of whether the pixels are occluded by closer geometry. | +| **Setting** | **Type** | **Description** | +| ------------------------------------------------- | -------- | ------------------------------------------------------------ | +| **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. | +| **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 TU And AA** **[HDRP]** | Bool | **(Inspector)** Indicates whether the render pipeline excludes particles from temporal upscalers (TU) and temporal anti-aliasing (AA). 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. | +| **Cull Mode** | Enum | **(Inspector)** Specifies the cull mode to use with the system. The options are:
• **Default**: Use the default cull mode for the system.
• **Front**: Culls front faces of particles in the system.
• **Back**: Culls back faces of particles in the system.
• **Off**: Culls no faces. This mode makes the output render both front and back faces. | +| **Z Write Mode** | Enum | **(Inspector)** Specifies the depth writing mode to use with the system. The options are:
• **Default**: Uses the default depth write mode for the system. This is typically **On** for opaque and **Off** for transparent.
• **On**: Enables depth writing for the system.
• **Off**: Disables depth writing for the system. | +| **Z Test Mode** | Enum | **(Inspector)** Specifies the depth test mode to use with the system. The options are:
• **Default**: Use the default depth testing mode for the system. This is typically **On**.
• **On**: Enables depth testing for the system.
• **Off**: Disables depth testing for the system. This means the output renders regardless of whether the pixels are occluded by closer geometry. | ## Particle Options Settings diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs index 970460e3a78..8df0bacc405 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractParticleOutput.cs @@ -598,8 +598,8 @@ protected override IEnumerable filteredOutSettings { yield return "flipbookLayout"; } - if (!subOutput.supportsExcludeFromTAA) - yield return "excludeFromTAA"; + if (!subOutput.supportsExcludeFromTUAndAA) + yield return "excludeFromTUAndAA"; if (!HasSorting()) { yield return "sortMode"; diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs index eb7bbbda08b..8ea9c0a4011 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs @@ -61,8 +61,8 @@ public enum ZTestMode [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("When enabled, particles write to the velocity buffer, allowing them to be blurred with the Motion Blur post processing effect.")] protected bool generateMotionVector = false; - [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("When enabled, particles will not be affected by temporal anti-aliasing.")] - protected bool excludeFromTAA = false; + [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), FormerlySerializedAs("excludeFromTAA"), SerializeField, Tooltip("When enabled, particles will not be affected by temporal upscaling and anti-aliasing.")] + protected bool excludeFromTUAndAA = false; public virtual bool isBlendModeOpaque { get { return blendMode == BlendMode.Opaque; } } @@ -88,7 +88,7 @@ public virtual bool hasMotionVector public virtual bool implementsMotionVector { get { return false; } } - public virtual bool hasExcludeFromTAA => subOutput.supportsExcludeFromTAA && excludeFromTAA; + public virtual bool hasExcludeFromTUAndAA => subOutput.supportsExcludeFromTUAndAA && excludeFromTUAndAA; protected VFXAbstractRenderedOutput(VFXDataType dataType) : base(VFXContextType.Output, dataType, VFXDataType.None) { } diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs index 389ea4d2ece..20a382de08c 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs @@ -24,7 +24,7 @@ public void Init(VFXAbstractRenderedOutput owner) // Caps public virtual bool supportsExposure { get { return false; } } public virtual bool supportsMotionVector { get { return false; } } - public virtual bool supportsExcludeFromTAA { get { return false; } } + public virtual bool supportsExcludeFromTUAndAA { get { return false; } } public virtual bool supportsSortingPriority { get { return true; } } // Sealed override as SRP suboutputs cannot have dependencies diff --git a/Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs b/Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs index 1ea3a60d07f..4b0f16ff1c1 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs @@ -467,7 +467,7 @@ static IEnumerable FilterOutBuiltinSettings() yield return "cullMode"; yield return "zWriteMode"; yield return "zTestMode"; - yield return "excludeFromTAA"; + yield return "excludeFromTUAndAA"; yield return "preserveSpecularLighting"; yield return "doubleSided"; yield return "onlyAmbientLighting"; From c4ca3c5e4f10468d64965e1a220697d82854c8d1 Mon Sep 17 00:00:00 2001 From: Reach Platform Support Date: Fri, 13 Oct 2023 00:23:09 +0000 Subject: [PATCH 6/6] [Port] [2023.1] Fixed layered lit displacement. Fixed Layered Lit Displacement --- .../Runtime/Material/Lit/BaseLitAPI.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs index 6f35761e4c9..52dde496af6 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/BaseLitAPI.cs @@ -54,23 +54,6 @@ static public void SetupBaseLitKeywords(Material material) bool enableDisplacement = material.HasProperty(kDisplacementMode) && (GetFilteredDisplacementMode(material) != DisplacementMode.None); - // Displacement mapping requires a height map. - if (enableDisplacement) - { - int layerCount = material.HasProperty(kLayerCount) ? material.GetInt(kLayerCount) : 1; - - // If the layerCount is 1, then it means that the property we're fetching is not from a layered material - // thus it doesn't have a postfix - string[] postfixes = (layerCount > 1) ? new[] { "0", "1", "2", "3" } : new[] { "" }; - - for (int i = 0; i < layerCount; i++) - { - string kHeightMapN = string.Format("{0}{1}", kHeightMap, postfixes[i]); - - enableDisplacement = enableDisplacement && material.HasProperty(kHeightMapN) && (material.GetTexture(kHeightMapN) != null); - } - } - if (enableDisplacement) { var displacementMode = GetFilteredDisplacementMode(material);