From 2f25ece8b718872d7bac6c78162f99166e03f7c8 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Wed, 29 Jan 2025 02:59:07 +0000 Subject: [PATCH 01/22] SRP Core Docs: In-Loop Render Requests --- .../Documentation~/TableOfContents.md | 1 + .../Documentation~/in-loop-render-requests.md | 139 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md b/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md index 6adc3f35232..172b72b8a8c 100644 --- a/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md +++ b/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md @@ -12,6 +12,7 @@ * [Free Camera](Free-Camera.md) * [Camera Switcher](Camera-Switcher.md) * [Render Requests](User-Render-Requests.md) +* [Render from another camera inside a camera's rendering loop](in-loop-render-requests.md) * [Render Graph](render-graph-system.md) * [Benefits of the render graph system](render-graph-benefits.md) * [Render graph fundamentals](render-graph-fundamentals.md) diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md b/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md new file mode 100644 index 00000000000..409f3e1da7b --- /dev/null +++ b/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md @@ -0,0 +1,139 @@ +# Render from another camera inside a camera's rendering loop + +Render from cameras nested inside the render loop of other cameras. + +Attach the provided script to a GameObject with a Camera component to nest multiple cameras, that are rendering with [RenderPipeline.SubmitRenderRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.SubmitRenderRequest.html), inside the render loop of other cameras. + +**Note**: If your project uses the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP), the recommended best practice is to use [UniversalRenderPipeline.SingleCameraRequest](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/api/UnityEngine.Rendering.Universal.UniversalRenderPipeline.SingleCameraRequest.html) instead of [StandardRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.StandardRequest.html), to make sure you only render the camera provided to the `RenderRequest` API instead of the full stack of cameras. + +## Attach the script to nest + +Follow these steps: + +1. Create a new C# script. +2. Add the `using` statements shown below and the `RequireComponent` attribute with the `Camera` type. + + ```c# + using System.Collections.Generic; + using UnityEngine; + using UnityEngine.Rendering; + + [RequireComponent(typeof(Camera))] + public class InLoopRenderRequest : MonoBehaviour + { + + } + ``` + +3. Add a property with the type `Camera` to the `InLoopRenderRequest` class. +4. Add a property with the type `RenderTexture` for each callback the camera uses, as shown below: + + ```c# + [RequireComponent(typeof(Camera))] + public class InLoopRenderRequest : MonoBehaviour + { + public Camera renderRequestCamera; + + public RenderTexture onBeginCameraRendering; + public RenderTexture onBeginContextRendering; + public RenderTexture onEndCameraRendering; + public RenderTexture onEndContextRendering; + } + ``` + +## Full code example + +The following is an example of the finalized code which you attach to the secondary camera: + +```c# +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +[RequireComponent(typeof(Camera))] +public class InLoopRenderRequest : MonoBehaviour +{ + // Add a reference to the secondary camera that will render the textures + // It's recommended to disable the secondary camera. + public Camera renderRequestCamera; + + // Add references to the Render Textures that will contain the rendered image from the secondary camera. + public RenderTexture onBeginCameraRendering; + public RenderTexture onBeginContextRendering; + public RenderTexture onEndCameraRendering; + public RenderTexture onEndContextRendering; + + void OnEnable() + { + // Subscribe to the RenderPipelineManager callbacks + RenderPipelineManager.beginCameraRendering += OnBeginCameraRender; + RenderPipelineManager.beginContextRendering += OnBeginContextRendering; + RenderPipelineManager.endCameraRendering += OnEndCameraRender; + RenderPipelineManager.endContextRendering += OnEndContextRendering; + } + + public void OnDisable() + { + // Unsubscribe to the callbacks from RenderPipelineManager when we disable the component + RenderPipelineManager.beginCameraRendering -= OnBeginCameraRender; + RenderPipelineManager.beginContextRendering -= OnBeginContextRendering; + RenderPipelineManager.endCameraRendering -= OnEndCameraRender; + RenderPipelineManager.endContextRendering -= OnEndContextRendering; + } + + void SubmitStandardRenderRequest(RenderTexture rt, Camera cam) + { + RenderPipeline.StandardRequest request = new(); + + // Check that the Scriptable Render Pipeline (SRP) we're using supports the given render data. + if (RenderPipeline.SupportsRenderRequest(cam, request)) + { + // Set the request RenderTexture + request.destination = rt; + + // Render the camera output to the RenderTexture synchronously + // When this is complete, the RenderTexture in renderTextures[i] contains the scene rendered from the point of view of the secondary cameras + RenderPipeline.SubmitRenderRequest(cam, request); + } + } + + // StandardRequest and UniversalRenderPipeline.SingleCameraRequest also trigger RenderPipelineManager callbacks. + // Check that the callbacks are from the GameObject's Camera component to avoid a recursive rendering of the same camera. + private void OnBeginContextRendering(ScriptableRenderContext ctx, List cams) + { + if (cams.Contains(GetComponent())) + { + SubmitStandardRenderRequest(onBeginContextRendering, renderRequestCamera); + } + } + + private void OnEndContextRendering(ScriptableRenderContext ctx, List cams) + { + if (cams.Contains(GetComponent())) + { + SubmitStandardRenderRequest(onEndContextRendering, renderRequestCamera); + } + } + + private void OnBeginCameraRender(ScriptableRenderContext ctx, Camera cam) + { + if (cam == GetComponent()) + { + SubmitStandardRenderRequest(onBeginCameraRendering, renderRequestCamera); + } + } + + private void OnEndCameraRender(ScriptableRenderContext ctx, Camera cam) + { + if (cam == GetComponent()) + { + SubmitStandardRenderRequest(onEndCameraRendering, renderRequestCamera); + } + } +} +``` + +## Additional resources +- [Render Requests](User-Render-Requests.md) +- [Creating a custom render pipeline](srp-custom.md) + From 30fd3e1ba9b6bf82a1f128304bf08b6d9aeed386 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Wed, 29 Jan 2025 02:59:44 +0000 Subject: [PATCH 02/22] [6000.1][UUM-90792] Fix camera sorting layer not breaking batch for URP 2D --- .../LightBatchingDebugger.cs | 16 +++++--- .../Runtime/2D/Light2DManager.cs | 23 ++++++++++- .../Runtime/2D/Passes/Render2DLightingPass.cs | 31 ++++++--------- .../Runtime/2D/Passes/Utility/LayerUtility.cs | 38 ++++++++++++------- .../Runtime/2D/Renderer2D.cs | 3 ++ .../Rendergraph/CopyCameraSortingLayerPass.cs | 13 ++++--- .../2D/Rendergraph/DrawNormal2DPass.cs | 6 +-- .../2D/Rendergraph/GlobalPropertiesPass.cs | 7 +++- .../2D/Rendergraph/Renderer2DRendergraph.cs | 18 +++------ 9 files changed, 91 insertions(+), 64 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs index c0111c57645..67b44df185c 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs @@ -48,16 +48,20 @@ public static void ShowExample() private Vector3 cachedCamPos; ILight2DCullResult lightCullResult + { + get + { + return renderer2DData?.lightCullResult; + } + } + + Renderer2DData renderer2DData { get { // Game view main camera var renderer = Camera.main?.GetUniversalAdditionalCameraData().scriptableRenderer as Renderer2D; - var data = renderer?.GetRenderer2DData(); - if (data != null && data.lightCullResult.IsGameView()) - return data?.lightCullResult; - - return null; + return renderer?.GetRenderer2DData(); } } @@ -69,7 +73,7 @@ private bool PopulateData() batchList.Clear(); var layers = Light2DManager.GetCachedSortingLayer(); - var batches = LayerUtility.CalculateBatches(lightCullResult, out var batchCount); + var batches = LayerUtility.CalculateBatches(renderer2DData, out var batchCount); for (var i = 0; i < batchCount; i++) { diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs index 87e525cea2a..1fe354baf54 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace UnityEngine.Rendering.Universal { @@ -9,6 +8,20 @@ internal static class Light2DManager public static List lights { get; } = new List(); + internal static void Initialize() + { +#if UNITY_EDITOR + SortingLayer.onLayerChanged += OnSortingLayerChanged; +#endif + } + + internal static void Dispose() + { +#if UNITY_EDITOR + SortingLayer.onLayerChanged -= OnSortingLayerChanged; +#endif + } + // Called during OnEnable public static void RegisterLight(Light2D light) { @@ -108,5 +121,13 @@ public static SortingLayer[] GetCachedSortingLayer() return s_SortingLayers; } + +#if UNITY_EDITOR + internal static void OnSortingLayerChanged() + { + // Update sorting layers that were added or removed or changed order + s_SortingLayers = SortingLayer.layers; + } +#endif } } diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs index 05664a160a9..336c8278a57 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using UnityEngine.Profiling; -using UnityEngine.Experimental.Rendering; namespace UnityEngine.Rendering.Universal { @@ -167,7 +166,6 @@ private int DrawLayerBatches( CommandBuffer cmd, ScriptableRenderContext context, ref RenderingData renderingData, - ref FilteringSettings filterSettings, ref DrawingSettings normalsDrawSettings, ref DrawingSettings drawSettings, ref RenderTextureDescriptor desc) @@ -206,7 +204,7 @@ private int DrawLayerBatches( if (layerBatch.useNormals) { - filterSettings.sortingLayerRange = layerBatch.layerRange; + LayerUtility.GetFilterSettings(m_Renderer2DData, ref layerBatch, out var filterSettings); var depthTarget = m_NeedsDepth ? depthAttachmentHandle : null; this.RenderNormals(context, renderingData, normalsDrawSettings, filterSettings, depthTarget, normalsFirstClear); normalsFirstClear = false; @@ -284,23 +282,18 @@ private int DrawLayerBatches( copyStoreAction = resolveDuringBatch == i && resolveIsAfterCopy ? RenderBufferStoreAction.Resolve : RenderBufferStoreAction.StoreAndResolve; else copyStoreAction = RenderBufferStoreAction.Store; - // If our camera sorting layer texture bound is inside our batch we need to break up the DrawRenderers into two batches - if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound && m_Renderer2DData.useCameraSortingLayerTexture) - { - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, cameraSortingLayerBoundsIndex); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - CopyCameraSortingLayerRenderTexture(context, renderingData, copyStoreAction); - filterSettings.sortingLayerRange = new SortingLayerRange((short)(cameraSortingLayerBoundsIndex + 1), layerBatch.layerRange.upperBound); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - } - else - { - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, layerBatch.layerRange.upperBound); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - if (cameraSortingLayerBoundsIndex == layerBatch.layerRange.upperBound && m_Renderer2DData.useCameraSortingLayerTexture) + LayerUtility.GetFilterSettings(m_Renderer2DData, ref layerBatch, out var filterSettings); + + Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); + + if (m_Renderer2DData.useCameraSortingLayerTexture) + { + if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex <= layerBatch.layerRange.upperBound) + { CopyCameraSortingLayerRenderTexture(context, renderingData, copyStoreAction); + } } RendererLighting.DisableAllKeywords(CommandBufferHelpers.GetRasterCommandBuffer(cmd)); @@ -389,11 +382,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData ShadowRendering.CallOnBeforeRender(renderingData.cameraData.camera, m_Renderer2DData.lightCullResult); - var layerBatches = LayerUtility.CalculateBatches(m_Renderer2DData.lightCullResult, out var batchCount); + var layerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out var batchCount); var batchesDrawn = 0; for (var i = 0; i < batchCount; i += batchesDrawn) - batchesDrawn = DrawLayerBatches(layerBatches, batchCount, i, cmd, context, ref renderingData, ref filterSettings, ref normalsDrawSettings, ref combinedDrawSettings, ref desc); + batchesDrawn = DrawLayerBatches(layerBatches, batchCount, i, cmd, context, ref renderingData, ref normalsDrawSettings, ref combinedDrawSettings, ref desc); RendererLighting.DisableAllKeywords(CommandBufferHelpers.GetRasterCommandBuffer(cmd)); context.ExecuteCommandBuffer(cmd); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs index 42866e800dc..586b32a2d5e 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs @@ -103,13 +103,31 @@ private static bool CanBatchLightsInLayer(int layerIndex1, int layerIndex2, Sort return true; } - private static int FindUpperBoundInBatch(int startLayerIndex, SortingLayer[] sortingLayers, ILight2DCullResult lightCullResult) + private static bool CanBatchCameraSortingLayer(int startLayerIndex, SortingLayer[] sortingLayers, Renderer2DData rendererData) { + if (rendererData.useCameraSortingLayerTexture) + { + var cameraSortingLayerBoundsIndex = Render2DLightingPass.GetCameraSortingLayerBoundsIndex(rendererData); + return sortingLayers[startLayerIndex].value == cameraSortingLayerBoundsIndex; + } + + return false; + } + + private static int FindUpperBoundInBatch(int startLayerIndex, SortingLayer[] sortingLayers, Renderer2DData rendererData) + { + // break layer if camera sorting layer is active + if (CanBatchCameraSortingLayer(startLayerIndex, sortingLayers, rendererData)) + return startLayerIndex; + // start checking at the next layer for (var i = startLayerIndex + 1; i < sortingLayers.Length; i++) { - if (!CanBatchLightsInLayer(startLayerIndex, i, sortingLayers, lightCullResult)) + if (!CanBatchLightsInLayer(startLayerIndex, i, sortingLayers, rendererData.lightCullResult)) return i - 1; + + if (CanBatchCameraSortingLayer(i, sortingLayers, rendererData)) + return i; } return sortingLayers.Length - 1; } @@ -141,7 +159,7 @@ private static void InitializeBatchInfos(SortingLayer[] cachedSortingLayers) } } - public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, out int batchCount) + public static LayerBatch[] CalculateBatches(Renderer2DData rendererData, out int batchCount) { var cachedSortingLayers = Light2DManager.GetCachedSortingLayer(); InitializeBatchInfos(cachedSortingLayers); @@ -152,10 +170,10 @@ public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, { var layerToRender = cachedSortingLayers[i].id; ref var layerBatch = ref s_LayerBatches[batchCount++]; - var lightStats = lightCullResult.GetLightStatsByLayer(layerToRender, ref layerBatch); + var lightStats = rendererData.lightCullResult.GetLightStatsByLayer(layerToRender, ref layerBatch); // Find the highest layer that share the same set of lights and shadows as this layer. - var upperLayerInBatch = FindUpperBoundInBatch(i, cachedSortingLayers, lightCullResult); + var upperLayerInBatch = FindUpperBoundInBatch(i, cachedSortingLayers, rendererData); // Some renderers override their sorting layer value with short.MinValue or short.MaxValue. // When drawing the first sorting layer, we should include the range from short.MinValue to layerValue. @@ -195,19 +213,13 @@ public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, return s_LayerBatches; } - public static void GetFilterSettings(Renderer2DData rendererData, ref LayerBatch layerBatch, short cameraSortingLayerBoundsIndex, out FilteringSettings filterSettings) + public static void GetFilterSettings(Renderer2DData rendererData, ref LayerBatch layerBatch, out FilteringSettings filterSettings) { filterSettings = FilteringSettings.defaultValue; filterSettings.renderQueueRange = RenderQueueRange.all; filterSettings.layerMask = -1; filterSettings.renderingLayerMask = 0xFFFFFFFF; - - short upperBound = layerBatch.layerRange.upperBound; - - if (rendererData.useCameraSortingLayerTexture && cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound) - upperBound = cameraSortingLayerBoundsIndex; - - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, upperBound); + filterSettings.sortingLayerRange = layerBatch.layerRange; } static void SetupActiveBlendStyles() diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs index f69a8b0be85..37ea0047a97 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs @@ -112,6 +112,8 @@ public Renderer2D(Renderer2DData data) : base(data) LensFlareCommonSRP.mergeNeeded = 0; LensFlareCommonSRP.maxLensFlareWithOcclusionTemporalSample = 1; LensFlareCommonSRP.Initialize(); + + Light2DManager.Initialize(); } protected override void Dispose(bool disposing) @@ -127,6 +129,7 @@ protected override void Dispose(bool disposing) m_FinalBlitPass?.Dispose(); m_DrawOffscreenUIPass?.Dispose(); m_DrawOverlayUIPass?.Dispose(); + Light2DManager.Dispose(); CoreUtils.Destroy(m_BlitMaterial); CoreUtils.Destroy(m_BlitHDRMaterial); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs index 7b12a3b4a76..c6a2b9b8d9d 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs @@ -11,7 +11,7 @@ internal class CopyCameraSortingLayerPass : ScriptableRenderPass private static readonly ProfilingSampler m_ProfilingSampler = new ProfilingSampler(k_CopyCameraSortingLayerPass); private static readonly ProfilingSampler m_ExecuteProfilingSampler = new ProfilingSampler("Copy"); internal static readonly string k_CameraSortingLayerTexture = "_CameraSortingLayerTexture"; - private static readonly int k_CameraSortingLayerTextureId = Shader.PropertyToID(k_CameraSortingLayerTexture); + internal static readonly int k_CameraSortingLayerTextureId = Shader.PropertyToID(k_CameraSortingLayerTexture); static Material m_BlitMaterial; public CopyCameraSortingLayerPass(Material blitMaterial) @@ -57,18 +57,19 @@ class PassData internal TextureHandle source; } - public void Render(RenderGraph graph, in TextureHandle cameraColorAttachment, in TextureHandle destination) + public void Render(RenderGraph graph, ContextContainer frameData) { + UniversalResourceData commonResourceData = frameData.Get(); + Universal2DResourceData universal2DResourceData = frameData.Get(); + using (var builder = graph.AddRasterRenderPass(k_CopyCameraSortingLayerPass, out var passData, m_ProfilingSampler)) { - passData.source = cameraColorAttachment; + passData.source = commonResourceData.activeColorTexture; - builder.SetRenderAttachment(destination, 0); + builder.SetRenderAttachment(universal2DResourceData.cameraSortingLayerTexture, 0); builder.UseTexture(passData.source); builder.AllowPassCulling(false); - builder.SetGlobalTextureAfterPass(destination, k_CameraSortingLayerTextureId); - builder.SetRenderFunc((PassData data, RasterGraphContext context) => { Execute(context.cmd, data.source); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs index bd151105ed8..49a99b14a19 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs @@ -41,11 +41,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData using (var builder = graph.AddRasterRenderPass(k_NormalPass, out var passData, m_ProfilingSampler)) { - var filterSettings = FilteringSettings.defaultValue; - filterSettings.renderQueueRange = RenderQueueRange.all; - filterSettings.layerMask = -1; - filterSettings.renderingLayerMask = 0xFFFFFFFF; - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, layerBatch.layerRange.upperBound); + LayerUtility.GetFilterSettings(rendererData, ref layerBatch, out var filterSettings); var drawSettings = CreateDrawingSettings(k_NormalsRenderingPassName, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent); var sortSettings = drawSettings.sortingSettings; diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs index 2b8b6b2bb8c..fb1e2c41f3d 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs @@ -16,8 +16,10 @@ class PassData internal Vector2Int screenParams; } - internal static void Setup(RenderGraph graph, UniversalCameraData cameraData) + internal static void Setup(RenderGraph graph, ContextContainer frameData, Renderer2DData rendererData, UniversalCameraData cameraData) { + Universal2DResourceData universal2DResourceData = frameData.Get(); + using (var builder = graph.AddRasterRenderPass(k_SetGlobalProperties, out var passData, m_SetGlobalPropertiesProfilingSampler)) { // Set screenParams when pixel perfect camera is used with the reference resolution @@ -36,6 +38,9 @@ internal static void Setup(RenderGraph graph, UniversalCameraData cameraData) builder.SetGlobalTextureAfterPass(graph.defaultResources.whiteTexture, k_DefaultWhiteTextureID); #endif + if (rendererData.useCameraSortingLayerTexture) + builder.SetGlobalTextureAfterPass(universal2DResourceData.cameraSortingLayerTexture, CopyCameraSortingLayerPass.k_CameraSortingLayerTextureId); + builder.AllowPassCulling(false); builder.AllowGlobalStateModification(true); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs index a47e518bebb..d49e919ceee 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs @@ -144,7 +144,7 @@ void InitializeLayerBatches() { Universal2DResourceData resourceData = frameData.Get(); - m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData.lightCullResult, out m_BatchCount); + m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount); // Initialize textures dependent on batch size if (resourceData.normalsTexture.Length != m_BatchCount) @@ -529,7 +529,7 @@ private void OnMainRendering(RenderGraph renderGraph) var cameraSortingLayerBoundsIndex = Render2DLightingPass.GetCameraSortingLayerBoundsIndex(m_Renderer2DData); // Set Global Properties and Textures - GlobalPropertiesPass.Setup(renderGraph, cameraData); + GlobalPropertiesPass.Setup(renderGraph, frameData, m_Renderer2DData, cameraData); // Main render passes @@ -557,7 +557,7 @@ private void OnMainRendering(RenderGraph renderGraph) ref var layerBatch = ref m_LayerBatches[i]; - LayerUtility.GetFilterSettings(m_Renderer2DData, ref m_LayerBatches[i], cameraSortingLayerBoundsIndex, out var filterSettings); + LayerUtility.GetFilterSettings(m_Renderer2DData, ref m_LayerBatches[i], out var filterSettings); m_RendererPass.Render(renderGraph, frameData, m_Renderer2DData, ref m_LayerBatches, i, ref filterSettings); // Shadow Volumetric Pass @@ -569,17 +569,9 @@ private void OnMainRendering(RenderGraph renderGraph) // Camera Sorting Layer Pass if (m_Renderer2DData.useCameraSortingLayerTexture) { - // Split Render Pass if CameraSortingLayer is in the middle of a batch - if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound) + if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex <= layerBatch.layerRange.upperBound) { - m_CopyCameraSortingLayerPass.Render(renderGraph, commonResourceData.activeColorTexture, universal2DResourceData.cameraSortingLayerTexture); - - filterSettings.sortingLayerRange = new SortingLayerRange((short)(cameraSortingLayerBoundsIndex + 1), layerBatch.layerRange.upperBound); - m_RendererPass.Render(renderGraph, frameData, m_Renderer2DData, ref m_LayerBatches, i, ref filterSettings); - } - else if (cameraSortingLayerBoundsIndex == layerBatch.layerRange.upperBound) - { - m_CopyCameraSortingLayerPass.Render(renderGraph, commonResourceData.activeColorTexture, universal2DResourceData.cameraSortingLayerTexture); + m_CopyCameraSortingLayerPass.Render(renderGraph, frameData); } } } From 83987320422682cfc61fc78201da9ee6fae3ced3 Mon Sep 17 00:00:00 2001 From: Tristan Genevet Date: Wed, 29 Jan 2025 03:03:50 +0000 Subject: [PATCH 03/22] [UUM-92418] Help link color --- .../GraphView/Views/VFXHelpDropdownButton.cs | 16 ---------------- .../Editor/UIResources/uss/VFXToolbar.uss | 18 ------------------ .../UIResources/uxml/VFXHelpDropdownPanel.uxml | 8 ++++---- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs index 997f300714d..9e373e8569e 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs @@ -14,10 +14,6 @@ class VFXHelpDropdownButton : DropDownButtonBase const string k_AdditionalHelpers = "OutputEvent Helpers"; const string k_LearningSamples = "Learning Templates"; const string k_ManualUrl = @"https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@{0}/index.html"; - const string k_ForumUrl = @"https://forum.unity.com/forums/visual-effect-graph.428/"; - const string k_SpaceShipUrl = @"https://github.com/Unity-Technologies/SpaceshipDemo"; - const string k_SamplesUrl = @"https://github.com/Unity-Technologies/VisualEffectGraph-Samples"; - const string k_VfxGraphUrl = @"https://unity.com/visual-effect-graph"; string m_ManualUrlWithVersion; ListRequest m_PackageManagerRequest; @@ -40,18 +36,6 @@ public VFXHelpDropdownButton(VFXView vfxView) var installLearningButton = m_PopupContent.Q