From 4749d4ffaa4c39ccc5cc9881d013b68ea4873d62 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Thu, 16 Apr 2026 19:04:06 +0000 Subject: [PATCH 01/11] [6000.3] Fix MSAA CameraDepthTexture scaling issues by replacing UV sampling with screen-space texture loading and Shader truncation warning in CopyDepthPass --- .../Shaders/Utils/CopyDepthPass.hlsl | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl b/Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl index 2a3b3b606e0..6698a7f5712 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl @@ -17,21 +17,19 @@ #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED) #define DEPTH_TEXTURE_MS(name, samples) Texture2DMSArray name #define DEPTH_TEXTURE(name) TEXTURE2D_ARRAY_FLOAT(name) -#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, uv, unity_StereoEyeIndex, sampleIndex) -#define SAMPLE(uv) SAMPLE_TEXTURE2D_ARRAY(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv, unity_StereoEyeIndex).r +#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, coord, unity_StereoEyeIndex, sampleIndex) +#define LOAD(coord) LOAD_TEXTURE2D_ARRAY(_CameraDepthAttachment, coord, unity_StereoEyeIndex) #else #define DEPTH_TEXTURE_MS(name, samples) Texture2DMS name #define DEPTH_TEXTURE(name) TEXTURE2D_FLOAT(name) -#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, uv, sampleIndex) -#define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv) +#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, coord, sampleIndex) +#define LOAD(coord) LOAD_TEXTURE2D(_CameraDepthAttachment, coord) #endif #if MSAA_SAMPLES == 1 DEPTH_TEXTURE(_CameraDepthAttachment); - SAMPLER(sampler_CameraDepthAttachment); #else DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES); - float4 _CameraDepthAttachment_TexelSize; #endif #if UNITY_REVERSED_Z @@ -42,17 +40,17 @@ #define DEPTH_OP max #endif -float SampleDepth(float2 uv) +float SampleDepth(float2 pixelCoords) { + int2 coord = int2(pixelCoords); #if MSAA_SAMPLES == 1 - return SAMPLE(uv); + return LOAD(coord).r; #else - int2 coord = int2(uv * _CameraDepthAttachment_TexelSize.zw); float outDepth = DEPTH_DEFAULT_VALUE; UNITY_UNROLL for (int i = 0; i < MSAA_SAMPLES; ++i) - outDepth = DEPTH_OP(LOAD(coord, i), outDepth); + outDepth = DEPTH_OP(LOAD_MSAA(coord, i), outDepth); return outDepth; #endif } @@ -64,7 +62,7 @@ float frag(Varyings input) : SV_Target #endif { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - return SampleDepth(input.texcoord); + return SampleDepth(input.positionCS.xy); } #endif From 72ede0862ca7f0ebfadea508019d4749e6004a57 Mon Sep 17 00:00:00 2001 From: Tyler Fan Date: Sat, 18 Apr 2026 08:17:09 +0000 Subject: [PATCH 02/11] Backport/6000.3/adp fix rendertexture size --- .../Runtime/UniversalRenderPipeline.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index f27226c3a8a..18b81fc6859 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -2486,18 +2486,18 @@ static void ApplyAdaptivePerformance(UniversalCameraData cameraData) // TODO if (!cameraData.xr.enabled) { - cameraData.cameraTargetDescriptor.width = (int)(cameraData.camera.pixelWidth * cameraData.renderScale); - cameraData.cameraTargetDescriptor.height = (int)(cameraData.camera.pixelHeight * cameraData.renderScale); + cameraData.cameraTargetDescriptor.width = Mathf.Max(1, (int)(cameraData.pixelWidth * cameraData.renderScale)); + cameraData.cameraTargetDescriptor.height = Mathf.Max(1, (int)(cameraData.pixelHeight * cameraData.renderScale)); #if ENABLE_UPSCALER_FRAMEWORK if (cameraData.upscalingFilter == ImageUpscalingFilter.IUpscaler) { // An IUpscaler is active. It might want to change the pre-upscale resolution. Negotiate with it. IUpscaler activeUpscaler = upscaling.GetActiveUpscaler(); Debug.Assert(activeUpscaler != null); - Vector2Int res = new Vector2Int(cameraData.cameraTargetDescriptor.width, cameraData.scaledHeight); + Vector2Int res = new Vector2Int(cameraData.cameraTargetDescriptor.width, cameraData.cameraTargetDescriptor.height); activeUpscaler.NegotiatePreUpscaleResolution(ref res, new Vector2Int(cameraData.pixelWidth, cameraData.pixelHeight)); - cameraData.cameraTargetDescriptor.width = res.x; - cameraData.cameraTargetDescriptor.height = res.y; + cameraData.cameraTargetDescriptor.width = Mathf.Max(1, res.x); + cameraData.cameraTargetDescriptor.height = Mathf.Max(1, res.y); } #endif cameraData.scaledWidth = cameraData.cameraTargetDescriptor.width; From 0806cb351080f3f199029e0c1c9026ceae2f52e3 Mon Sep 17 00:00:00 2001 From: Reach Platform Support Date: Sat, 18 Apr 2026 08:17:10 +0000 Subject: [PATCH 03/11] [Port] [6000.3] Graphics/URP/UUM-134993 - Fix URP Sample - Blit Depth Copy Pass wrongly binding msaa depth with Vulkan --- .../RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.render-pipelines.universal/Samples~/URPPackageSamples/RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs b/Packages/com.unity.render-pipelines.universal/Samples~/URPPackageSamples/RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs index c8bf2fb8c51..f97e3478b17 100644 --- a/Packages/com.unity.render-pipelines.universal/Samples~/URPPackageSamples/RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Samples~/URPPackageSamples/RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs @@ -134,8 +134,9 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer builder.SetRenderFunc((PassData data, RasterGraphContext context) => { // Enable an MSAA shader keyword based on the source texture MSAA sample count + // when depth must be resolved manually in the copy shader RTHandle sourceTex = data.source; - int cameraSamples = sourceTex.rt.antiAliasing; + int cameraSamples = sourceTex.rt.bindTextureMS ? sourceTex.rt.antiAliasing : 1; context.cmd.SetKeyword(data.keyword_DepthMsaa2, cameraSamples == 2); context.cmd.SetKeyword(data.keyword_DepthMsaa4, cameraSamples == 4); context.cmd.SetKeyword(data.keyword_DepthMsaa8, cameraSamples == 8); From 093d420ce78da497f674594a8a0c8ca1bc2becb8 Mon Sep 17 00:00:00 2001 From: Reach Platform Support Date: Sat, 18 Apr 2026 08:17:10 +0000 Subject: [PATCH 04/11] [Port] [6000.3] Graphics/HDRP - [UUM-130925] - Fix null limit.xy values in _ColorPyramidUvScaleAndLimitCurrentFrame after color pyramid for distortion --- .../RenderPipeline/HDRenderPipeline.RenderGraph.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index 19ca4fb29ed..cb67df991e0 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -313,10 +313,11 @@ void RecordRenderGraph(RenderRequest renderRequest, GenerateColorPyramid(m_RenderGraph, hdCamera, colorBuffer, distortionColorPyramid, FullScreenDebugMode.PreRefractionColorPyramid, distortionRendererList); currentColorPyramid = distortionColorPyramid; - - // The color pyramid for distortion is not an history, so it need to be sampled appropriate RT handle scale. Thus we need to update it - var newScale = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, 0, 0); - m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScale; + // The color pyramid for distortion is not an history buffer, so it needs to be sampled using an appropriate RT handle scale. Thus we need to update the scale and the limit. + // It's relatively straightforward to update the scale because we store it in rtHandleScale but we miss the limit values. For now, we approximate them by setting them to the scale value. + // This is imperfect but resetting limit at (0, 0) gives worse results (UUM-130925). + var newScaleLimits = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y); + m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScaleLimits; PushGlobalCameraParams(m_RenderGraph, hdCamera); } From 0938741ccba32ead18fed588143ee455d277bbe3 Mon Sep 17 00:00:00 2001 From: Reach Platform Support Date: Tue, 21 Apr 2026 13:03:52 +0000 Subject: [PATCH 05/11] [Port] [6000.3] Suppress 'potentially uninitialized variable' warning in UnifiedRT TraceRay.hlsl --- .../Runtime/UnifiedRayTracing/TraceRay.hlsl | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl index b9bcd02df1a..efaad78efe8 100644 --- a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl +++ b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/TraceRay.hlsl @@ -151,6 +151,7 @@ struct HitContext namespace UnifiedRT { #pragma warning(disable : 3557) // prevent warning when the "while (rayQuery.Proceed())" loop is unrolled +#pragma warning(disable : 4000) // suppress FXC warnings about potentially uninitialized variables void TraceRay(DispatchInfo dispatchInfo, RayTracingAccelStruct accelStruct, uint instanceMask, Ray ray, uint rayFlags, inout UNIFIED_RT_PAYLOAD payload) { From d165de2d067aaf37e359473d3674ed268740e6ea Mon Sep 17 00:00:00 2001 From: Evergreen Date: Wed, 22 Apr 2026 05:47:07 +0000 Subject: [PATCH 06/11] [Port] [6000.3] [UUM-137604] UnifiedRT: Fixed RayTracingRenderPipelineResources needing to be public for Player build + doc improvements --- .../create-ray-tracing-context.md | 11 +- .../UnifiedRayTracing/release-resources.md | 26 +++++ .../unified-ray-tracing-api.md | 2 +- .../UnifiedRayTracing/workflow.md | 3 + .../UnifiedRayTracing/RayTracingContext.cs | 8 +- .../UnifiedRayTracing/RayTracingResources.cs | 104 ++++++++++++++++-- 6 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/release-resources.md diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md index 5c2dacbdf21..baa4d4f9d87 100644 --- a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md +++ b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md @@ -9,7 +9,7 @@ Follow these steps: ## Load the ray tracing resources The [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext) needs a few utility shaders that the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) object supplies. You can load these resources in several different ways. -If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.LoadFromRenderPipelineResources()). This always works in the Editor. +If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources.LoadFromRenderPipelineResources()). This always works in the Editor. ```C# var rtResources = new RayTracingResources(); bool result = rtResources.LoadFromRenderPipelineResources(); @@ -49,9 +49,12 @@ rtResources.LoadFromAssetBundle(asssetBundle); ## Create the context Once the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) are loaded, use them to create the [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext). ```C# -// Choose a backend -var backend = RayTracingContext.IsBackendSupported(RayTracingBackend.Hardware) ? RayTracingBackend.Hardware : RayTracingBackend.Compute; +var context = new RayTracingContext(rtResources); +``` + +By default, Unity checks if the device supports hardware ray tracing, and selects either hardware ray tracing or compute shaders. To manually select the backend, pass in a `RayTracingBackend`. For example: -// Create the context +```C# +var backend = RayTracingBackend.Compute; var context = new RayTracingContext(backend, rtResources); ``` diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/release-resources.md b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/release-resources.md new file mode 100644 index 00000000000..881045c15f9 --- /dev/null +++ b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/release-resources.md @@ -0,0 +1,26 @@ +# Release your ray tracing objects + +You must free up the memory your ray tracing objects use after you finish with them. + +Dispose of the following: + +- Scratch buffers. Use [`GraphicsBuffer.Dispose`](xref:UnityEngine.GraphicsBuffer.Dispose()) after you've executed the final command buffer. +- Ray tracing acceleration structures. Use [`IRayTracingAccelStruct.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingAccelStruct.Dispose()) after you've executed the final command buffer. +- Ray tracing context. Use [`RayTracingContext.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.Dispose()) after you dispose of all its acceleration structures. + +**Note**: Unity automatically disposes of [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) and [`IRayTracingShader`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingShader). + +For example: + +```C# +RayTracingContext rtContext = new RayTracingContext(rtResources); +IRayTracingShader rtShader = rtContext.LoadRayTracingShader("Assets/yourShader.urtshader"); +IRayTracingAccelStruct rtAccelStruct = rtContext.CreateAccelerationStructure(new AccelerationStructureOptions()); +GraphicsBuffer rtScratchBuffer = RayTracingHelper.CreateScratchBufferForBuild(rtAccelStruct); + +// ... create and dispatch your ray tracing command buffers ... + +rtScratchBuffer.Dispose(); +rtAccelStruct.Dispose(); +rtContext.Dispose(); +``` diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/unified-ray-tracing-api.md b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/unified-ray-tracing-api.md index 97d2b49c41a..41f71c4ee88 100644 --- a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/unified-ray-tracing-api.md +++ b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/unified-ray-tracing-api.md @@ -12,4 +12,4 @@ The `UnifiedRayTracing` API enables you to write ray tracing code that can execu |[Execute your ray tracing code](execute-shader.md)|How to execute your ray tracing shader.| |[Sample code](trace-camera-rays-full-sample.md)|Complete code example showcasing tracing rays from the scene's camera.| |[Unified ray tracing shader code reference](shader-code-reference.md)|API reference for the unified ray tracing shader code.| - +|[Release your ray tracing objects](release-resources.md)|Learn how to release your ray tracing resources.| diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/workflow.md b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/workflow.md index 2683113ba65..c6669a1147f 100644 --- a/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/workflow.md +++ b/Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/workflow.md @@ -5,6 +5,7 @@ To use the API to trace rays in Unity, follow these steps: 3. Create a shader. 4. Build your acceleration structure. 5. Execute your shader. +6. Dispose of your objects. ## Create the ray tracing context @@ -53,3 +54,5 @@ rtShader.Dispatch(cmd, traceScratchBuffer, threadCountX, threadCountY, threadCou For more information, refer to [Execute your ray tracing code](execute-shader.md). +## Dispose of your objects +For more information, refer to [Release your ray tracing objects](release-resources.md). \ No newline at end of file diff --git a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingContext.cs b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingContext.cs index 0c6ff3dcf0a..01e23667eaf 100644 --- a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingContext.cs +++ b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingContext.cs @@ -332,7 +332,9 @@ static public GraphicsBuffer CreateScratchBufferForTrace(IRayTracingShader shade /// Resizes a scratch buffer if its size doesn't fit the requirement of . /// /// - /// The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size. + /// Unity resizes the buffer by disposing of the `GraphicsBuffer` and instantiating a new one with the proper size. + /// **Important:** If you reference the current in a command buffer, you must + /// only call this method after you submit the command buffer. See or . /// /// The shader that will be passed to . /// Number of threads in the X dimension that will be passed to . @@ -362,7 +364,9 @@ static public void ResizeScratchBufferForTrace( /// Resizes a scratch buffer if its size doesn't fit the requirement of . /// /// - /// The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size. + /// Unity resizes the buffer by disposing of the `GraphicsBuffer` and instantiating a new one with the proper size. + /// **Important:** If you reference the current in a command buffer, you must + /// only call this method after you submit the command buffer. See or . /// /// The acceleration structure that will be passed to . /// The scratch buffer. diff --git a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingResources.cs b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingResources.cs index 3e9a8f92dea..ea9c7970584 100644 --- a/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingResources.cs +++ b/Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingResources.cs @@ -5,6 +5,12 @@ namespace UnityEngine.Rendering.UnifiedRayTracing { + /// + /// Resource class that handles the serialization of UnifiedRayTracing's utility shaders in projects using a Scriptable Render Pipeline. + /// + /// + /// This class is used internally by + /// [Scripting.APIUpdating.MovedFrom( autoUpdateAPI: true, sourceNamespace: "UnityEngine.Rendering.UnifiedRayTracing", @@ -13,10 +19,13 @@ namespace UnityEngine.Rendering.UnifiedRayTracing [Serializable] [SupportedOnRenderPipeline()] [Categorization.CategoryInfo(Name = "R: Unified Ray Tracing", Order = 1000), HideInInspector] - internal class RayTracingRenderPipelineResources : IRenderPipelineResources + public sealed class RayTracingRenderPipelineResources : IRenderPipelineResources { [SerializeField, HideInInspector] int m_Version = 1; + /// + /// The version number of the resources container. + /// public int version { get => m_Version; @@ -49,54 +58,84 @@ public int version [SerializeField, ResourcePath("Runtime/UnifiedRayTracing/Compute/RadeonRays/kernels/scatter.compute")] ComputeShader m_Scatter; + /// + /// Compute shader for geometry pool operations. + /// public ComputeShader GeometryPoolKernels { get => m_GeometryPoolKernels; set => this.SetValueAndNotify(ref m_GeometryPoolKernels, value, nameof(m_GeometryPoolKernels)); } + /// + /// Compute shader for buffer copy operations. + /// public ComputeShader CopyBuffer { get => m_CopyBuffer; set => this.SetValueAndNotify(ref m_CopyBuffer, value, nameof(m_CopyBuffer)); } + /// + /// Compute shader for copying vertex position data. + /// public ComputeShader CopyPositions { get => m_CopyPositions; set => this.SetValueAndNotify(ref m_CopyPositions, value, nameof(m_CopyPositions)); } + /// + /// Compute shader for radix sort operations. + /// public ComputeShader BitHistogram { get => m_BitHistogram; set => this.SetValueAndNotify(ref m_BitHistogram, value, nameof(m_BitHistogram)); } + /// + /// Compute shader for prefix sum operations. + /// public ComputeShader BlockReducePart { get => m_BlockReducePart; set => this.SetValueAndNotify(ref m_BlockReducePart, value, nameof(m_BlockReducePart)); } + /// + /// Compute shader for prefix sum operations. + /// public ComputeShader BlockScan { get => m_BlockScan; set => this.SetValueAndNotify(ref m_BlockScan, value, nameof(m_BlockScan)); } + /// + /// Compute shader for building a BVH. + /// public ComputeShader BuildHlbvh { get => m_BuildHlbvh; set => this.SetValueAndNotify(ref m_BuildHlbvh, value, nameof(m_BuildHlbvh)); } + /// + /// Compute shader for BVH restructuring. + /// + /// + /// Used to optimize the BVH structure after initial construction. + /// public ComputeShader RestructureBvh { get => m_RestructureBvh; set => this.SetValueAndNotify(ref m_RestructureBvh, value, nameof(m_RestructureBvh)); } + /// + /// Compute shader for radix sort operations. + /// public ComputeShader Scatter { get => m_Scatter; @@ -107,17 +146,62 @@ public ComputeShader Scatter /// /// Utility shaders needed by a to operate. /// + /// + /// This class holds compute shaders required for unified ray tracing operations, + /// including geometry pool management and BVH construction kernels. + /// public class RayTracingResources { - internal ComputeShader geometryPoolKernels { get; set; } - internal ComputeShader copyBuffer { get; set; } - internal ComputeShader copyPositions { get; set; } - internal ComputeShader bitHistogram { get; set; } - internal ComputeShader blockReducePart { get; set; } - internal ComputeShader blockScan { get; set; } - internal ComputeShader buildHlbvh { get; set; } - internal ComputeShader restructureBvh { get; set; } - internal ComputeShader scatter { get; set; } + /// + /// Compute shader for geometry pool operations. + /// + public ComputeShader geometryPoolKernels { get; set; } + + /// + /// Compute shader for buffer copy operations. + /// + public ComputeShader copyBuffer { get; set; } + + /// + /// Compute shader for copying vertex position data. + /// + public ComputeShader copyPositions { get; set; } + + /// + /// Compute shader for radix sort operations. + /// + public ComputeShader bitHistogram { get; set; } + + /// + /// Compute shader for radix sort operations. + /// + public ComputeShader scatter { get; set; } + + /// + /// Compute shader for prefix sum operations. + /// + public ComputeShader blockReducePart { get; set; } + + /// + /// Compute shader for prefix sum operations. + /// + public ComputeShader blockScan { get; set; } + + /// + /// Compute shader for building a BVH. + /// + public ComputeShader buildHlbvh { get; set; } + + /// + /// Compute shader for BVH restructuring. + /// + /// + /// Used to optimize the BVH structure after initial construction. + /// + public ComputeShader restructureBvh { get; set; } + + + #if UNITY_EDITOR /// From 72c308fbf954e30b212eccee7cf03c3531ce75cf Mon Sep 17 00:00:00 2001 From: Evergreen Date: Thu, 23 Apr 2026 17:55:10 +0000 Subject: [PATCH 07/11] [Port] [6000.3] [URP][Shader Graph] Add stereo instancing support to custom UITK shaders written in ShaderGraph --- .../Editor/ShaderGraph/Includes/UITKPass.hlsl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UITKPass.hlsl b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UITKPass.hlsl index 03f675a2799..918543b6372 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UITKPass.hlsl +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UITKPass.hlsl @@ -16,6 +16,9 @@ PackedVaryings uie_custom_vert(Attributes input) uieInput.circle = input.uv6; uieInput.textureId = input.uv7.x; + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, uieInput); + v2f uieOutput = uie_std_vert(uieInput); Varyings varyings = (Varyings)0; @@ -32,6 +35,9 @@ PackedVaryings uie_custom_vert(Attributes input) varyings.texCoord3 = float4(uieOutput.textCoreLoc.x, uieOutput.textCoreLoc.y, input.uv0.z, input.uv0.w); // Layout uv in z, w varyings.texCoord4 = uieOutput.circle; + UNITY_TRANSFER_INSTANCE_ID(input, varyings); + UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(uieOutput, varyings); + PackedVaryings packedOutput = PackVaryings(varyings); return packedOutput; } From cf82355b1ba06ecf5ff737c8781d1e97e6b8c47d Mon Sep 17 00:00:00 2001 From: Evergreen Date: Fri, 24 Apr 2026 08:07:06 +0000 Subject: [PATCH 08/11] [Port] [6000.3] HDRP: Rendering Debugger - "Freeze Camera For Culling" dropdown was only showing None as an option. --- .../Runtime/Debug/DebugDisplay.cs | 90 ++++++++++++++----- .../RenderPipeline/HDRenderPipeline.cs | 3 - 2 files changed, 67 insertions(+), 26 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index b891cd00db2..3b5d42f3dc6 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -272,12 +272,6 @@ public partial class DebugDisplaySettings : IDebugData static GUIContent[] s_RenderingMipmapDebugMaterialTextureSlotStrings = null; static int[] s_RenderingMipmapDebugMaterialTextureSlotValues = null; - static List s_CameraNames = new List() { new("None") }; - static GUIContent[] s_CameraNamesStrings = { new ("No Visible Camera") }; - static int[] s_CameraNamesValues = { 0 }; - - static bool needsRefreshingCameraFreezeList = true; - #if ENABLE_NVIDIA && ENABLE_NVIDIA_MODULE internal UnityEngine.NVIDIA.DebugView nvidiaDebugView { get; } = new UnityEngine.NVIDIA.DebugView(); #endif @@ -339,8 +333,64 @@ public partial class DebugData public bool countRays = false; /// Display Show Lens Flare Data Driven Only. public bool showLensFlareDataDrivenOnly = false; + + private static Camera[] GetAvailableDebuggableCameras() + { + using (ListPool.Get(out var tmp)) + { + +#if UNITY_EDITOR + if (UnityEditor.SceneView.lastActiveSceneView != null) + { + var sceneCamera = UnityEditor.SceneView.lastActiveSceneView.camera; + if (sceneCamera != null) + tmp.Add(sceneCamera); + } +#endif + + var cameraArray = new Camera[Camera.allCamerasCount]; + Camera.GetAllCameras(cameraArray); + + foreach (var camera in cameraArray) + { + if (camera == null) + continue; + + if (camera.cameraType != CameraType.Preview && camera.cameraType != CameraType.Reflection) + { + if (camera.TryGetComponent(out _)) + tmp.Add(camera); + } + } + + return tmp.ToArray(); + } + } + /// Index of the camera to freeze for visibility. - public int debugCameraToFreeze = 0; + public int debugCameraToFreeze + { + get + { + var cameras = GetAvailableDebuggableCameras(); + if (cameras == null || cameras.Length == 0 || selectedCameraToFreeze == null) + return -1; + + return Array.IndexOf(cameras, selectedCameraToFreeze); + } + set + { + var cameras = GetAvailableDebuggableCameras(); + if (value < 0 || value >= cameras.Length) + selectedCameraToFreeze = null; + else + selectedCameraToFreeze = cameras[value]; + } + } + + /// The camera to freeze for visibility. + public Camera selectedCameraToFreeze; + internal RTASDebugView rtasDebugView = RTASDebugView.Shadows; internal RTASDebugMode rtasDebugMode = RTASDebugMode.InstanceID; internal VolumetricCloudsDebug volumetricCloudDebug = VolumetricCloudsDebug.Lighting; @@ -680,7 +730,7 @@ public ColorPickerDebugMode GetDebugColorPickerMode() /// True if camera visibility is frozen public bool IsCameraFreezeEnabled() { - return data.debugCameraToFreeze != 0; + return data.selectedCameraToFreeze != null; } /// @@ -690,7 +740,7 @@ public bool IsCameraFreezeEnabled() /// True if a specific camera is frozen for visibility. public bool IsCameraFrozen(Camera camera) { - return IsCameraFreezeEnabled() && camera.name.Equals(s_CameraNamesStrings[data.debugCameraToFreeze].text); + return IsCameraFreezeEnabled() && camera == data.selectedCameraToFreeze; } /// @@ -1974,7 +2024,14 @@ void RegisterRenderingDebug() }); } - renderingSettings.children.Add(new DebugUI.EnumField { nameAndTooltip = RenderingStrings.FreezeCameraForCulling, getter = () => data.debugCameraToFreeze, setter = value => data.debugCameraToFreeze = value, enumNames = s_CameraNamesStrings, enumValues = s_CameraNamesValues, getIndex = () => data.debugCameraToFreezeEnumIndex, setIndex = value => data.debugCameraToFreezeEnumIndex = value }); + var freezeCameraForCullingSelector = new DebugUI.CameraSelector() + { + nameAndTooltip = RenderingStrings.FreezeCameraForCulling, + getter = () => data.selectedCameraToFreeze, + setter = value => data.selectedCameraToFreeze = value as Camera + }; + + renderingSettings.children.Add(freezeCameraForCullingSelector); renderingSettings.children.Add(new DebugUI.Container { @@ -2228,19 +2285,6 @@ internal void UpdateMaterials() } } - internal void UpdateCameraFreezeOptions() - { - if (needsRefreshingCameraFreezeList) - { - s_CameraNamesStrings = s_CameraNames.ToArray(); - s_CameraNamesValues = Enumerable.Range(0, s_CameraNames.Count()).ToArray(); - - UnregisterRenderingDebug(); - RegisterRenderingDebug(); - needsRefreshingCameraFreezeList = false; - } - } - internal bool DebugHideSky(HDCamera hdCamera) { return (IsMatcapViewEnabled(hdCamera) || diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 4c93dd30542..d6b2db4d7e2 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2728,9 +2728,6 @@ AOVRequestData aovRequest } else { -#if DEVELOPMENT_BUILD || UNITY_EDITOR - m_DebugDisplaySettings.UpdateCameraFreezeOptions(); -#endif m_CurrentDebugDisplaySettings = m_DebugDisplaySettings; } From 2ea182c6dd7a49f5815b9a6e989188f6e0da5a48 Mon Sep 17 00:00:00 2001 From: Pema Malling Date: Fri, 24 Apr 2026 13:03:49 +0000 Subject: [PATCH 09/11] [6000.3] Fix color bleeding near edge of screen with HDRP SSGI --- .../RaytracingIndirectDiffuse.compute | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.compute b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.compute index db2839f382b..d6292090c79 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.compute +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.compute @@ -222,11 +222,8 @@ NeighborTapData GetNeighborTapDataSample_HR(uint2 groupThreadId, int2 offset) return GetNeighborTapDataSample_HR(OffsetToLDSAdress_HR(groupThreadId, offset)); } -NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 fulLResCoord, int2 offset) +NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 tapCoord) { - int2 tapCoord = (fulLResCoord / 2 + offset) * 2; - tapCoord = int2(clamp(tapCoord.x, 0, (int)_ScreenSize.x - 1), clamp(tapCoord.y, 0, (int)_ScreenSize.y - 1)); - NeighborTapData outVal; outVal.lighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, tapCoord / 2).xyz; outVal.linearDepth = Linear01Depth(LOAD_TEXTURE2D_X(_DepthTexture, tapCoord).x, _ZBufferParams); @@ -278,11 +275,15 @@ void IndirectDiffuseIntegrationUpscaleHalfRes(uint3 dispatchThreadId : SV_Dispat { for(int x = -HALF_RES_OUT_REGION_SIZE; x < HALF_RES_OUT_REGION_SIZE; ++x) { + int2 tapCoord = (targetCoord / 2 + int2(x,y)) * 2; + if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy)) + continue; + #ifndef WITHOUT_LDS // Grab the neighbor data NeighborTapData neighborData = GetNeighborTapDataSample_HR(groupThreadId, int2(x,y)); #else - NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(targetCoord, int2(x,y)); + NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(tapCoord); #endif // Evaluate the weight of this neighbor float weight = EvaluateNeighborWeight(neighborData, normalData.normalWS, linearDepth); @@ -416,6 +417,10 @@ void IndirectDiffuseIntegrationUpscaleFullRes(uint3 dispatchThreadId : SV_Dispat { for(int x = -FULL_RES_OUT_REGION_SIZE; x < FULL_RES_OUT_REGION_SIZE; ++x) { + int2 tapCoord = targetCoord + int2(x,y); + if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy)) + continue; + #ifndef WITHOUT_LDS // Grab the neighbor data NeighborTapData neighborData = GetNeighborTapDataSample_FR(groupThreadId, int2(x,y)); From 1c8465ed1fbd4130dc65481d148eec4a19c4ba74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez=20Mart=C3=ADnez?= Date: Mon, 27 Apr 2026 09:16:05 +0000 Subject: [PATCH 10/11] [Port] [6000.3] [Material Upgrader] Generic system for URP and HDRP Menu item --- .../MaterialUpgrader.Utils.cs | 8 +-- .../MaterialUpgraderEditMenus.cs | 52 +++++++++++++++++++ .../MaterialUpgraderEditMenus.cs.meta | 2 + .../MaterialUpgraderEditMenus.cs | 38 -------------- .../MaterialUpgraderEditMenus.cs.meta | 2 - .../Editor/Wizard/HDWizard.cs | 7 ++- 6 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs create mode 100644 Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta delete mode 100644 Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs delete mode 100644 Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta diff --git a/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgrader.Utils.cs b/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgrader.Utils.cs index 2673c9d8651..cca182bff51 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgrader.Utils.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgrader.Utils.cs @@ -12,6 +12,8 @@ namespace UnityEditor.Rendering /// public partial class MaterialUpgrader { + internal static string k_DialogKey = $"{nameof(UnityEditor)}.{nameof(Rendering)}.{nameof(MaterialUpgrader)}.ConfirmMaterialConversion"; + #region Internal API /// /// Represents an entry describing material properties @@ -344,15 +346,15 @@ static void PerformUpgrade(List materialUpgrades, List s_Empty = new List(); + + public static List GetCurrentSRPUpgraders() + { + if (!GraphicsSettings.isScriptableRenderPipelineEnabled) + return s_Empty; + + return MaterialUpgrader.FetchAllUpgradersForPipeline(GraphicsSettings.currentRenderPipelineAssetType); + } + + [MenuItem("Edit/Rendering/Materials/Convert All Built-In Materials to Current SRP", true)] + internal static bool UpgradeMaterialsProjectValidate() + { + return GraphicsSettings.isScriptableRenderPipelineEnabled; + } + + [MenuItem("Edit/Rendering/Materials/Convert All Built-In Materials to Current SRP", priority = CoreUtils.Priorities.editMenuPriority + 1)] + internal static void UpgradeMaterialsProject() + { + MaterialUpgrader.UpgradeProjectFolder(GetCurrentSRPUpgraders(), "Upgrade to SRP Material"); + } + + [MenuItem("Edit/Rendering/Materials/Convert Selected Built-In Materials to Current SRP", true)] + internal static bool UpgradeMaterialsSelectionValidate() + { + if (Selection.objects.Length == 0 || !GraphicsSettings.isScriptableRenderPipelineEnabled) + return false; + + foreach (var obj in Selection.objects) + { + if (obj is not Material) + return false; + } + + return true; + } + + [MenuItem("Edit/Rendering/Materials/Convert Selected Built-In Materials to Current SRP", priority = CoreUtils.Priorities.editMenuPriority + 2)] + internal static void UpgradeMaterialsSelection() + { + MaterialUpgrader.UpgradeSelection(GetCurrentSRPUpgraders(), "Upgrade to SRP Material"); + } + } +} diff --git a/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta b/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta new file mode 100644 index 00000000000..56a170e650f --- /dev/null +++ b/Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 81cce92cea62afc46ae47b09fa3c8c6e \ No newline at end of file diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs deleted file mode 100644 index 3181589f0e9..00000000000 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; - -namespace UnityEditor.Rendering.HighDefinition -{ - class MaterialUpgraderEditMenus - { - public static List GetHDUpgraders() - { - return MaterialUpgrader.FetchAllUpgradersForPipeline(typeof(HDRenderPipelineAsset)); - } - - [MenuItem("Edit/Rendering/Materials/Convert All Materials using HDRP upgraders", priority = CoreUtils.Priorities.editMenuPriority + 1)] - internal static void UpgradeMaterialsProject() - { - MaterialUpgrader.UpgradeProjectFolder(GetHDUpgraders(), "Upgrade to HDRP Material"); - } - - [MenuItem("Edit/Rendering/Materials/Convert Selected Materials using HDRP upgraders", true)] - static bool MaterialValidate(MenuCommand command) - { - foreach (var obj in Selection.objects) - { - if (obj is not Material) return false; - } - - return true; - } - - [MenuItem("Edit/Rendering/Materials/Convert Selected Materials using HDRP upgraders", priority = CoreUtils.Priorities.editMenuPriority + 2)] - internal static void UpgradeMaterialsSelection() - { - MaterialUpgrader.UpgradeSelection(GetHDUpgraders(), "Upgrade to HDRP Material"); - } - } -} diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta b/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta deleted file mode 100644 index f1574a46878..00000000000 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 989185d0be859c14a8c6c5e7e8f9f46b \ No newline at end of file diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.cs index 42d5097c458..8fe4e0cc228 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.cs @@ -391,6 +391,10 @@ private void UpdateWindowTitle() }); } + public static List GetHDUpgraders() + { + return MaterialUpgrader.FetchAllUpgradersForPipeline(typeof(HDRenderPipelineAsset)); + } private void CreateGUI() { UpdateWindowTitle(); @@ -431,8 +435,7 @@ private void CreateGUI() container.Add(CreateTitle(Style.migrationTitle)); - if (MaterialUpgrader.ProjectContainsNonAutomaticUpgradePath( - MaterialUpgraderEditMenus.GetHDUpgraders())) + if (MaterialUpgrader.ProjectContainsNonAutomaticUpgradePath(GetHDUpgraders())) { var nonBuiltinMaterialHelpBox = new HelpBox(Style.nonAutomaticUpgradeMaterials, HelpBoxMessageType.Warning); nonBuiltinMaterialHelpBox.AddToClassList("NonBuiltinMaterialWarning"); From a0bd01de35c6fc5c7bc8987fe9e0e0e808aa20e2 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 28 Apr 2026 09:34:07 +0000 Subject: [PATCH 11/11] [Port] [6000.3] [UUM-139229][URP 2D] Fix preview camera missing lighting and shadows --- .../Runtime/2D/Rendergraph/DrawLight2DPass.cs | 14 ++------ .../2D/Rendergraph/DrawRenderer2DPass.cs | 34 ++++++------------- .../2D/Rendergraph/Renderer2DRendergraph.cs | 19 +++++++++++ 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs index 20f8e548299..e9349c73ae1 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs @@ -180,20 +180,12 @@ internal void Render(RenderGraph graph, ContextContainer frameData, Renderer2DDa Universal2DResourceData universal2DResourceData = frameData.Get(); UniversalCameraData cameraData = frameData.Get(); - DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData); - var isDebugLightingActive = debugHandler?.IsLightingActive ?? true; - -#if UNITY_EDITOR - if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null) - isDebugLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting; - - if (cameraData.camera.cameraType == CameraType.Preview) - isDebugLightingActive = false; -#endif + // Check for lighting in scene/prefab/preview camera + var isLightingActive = Renderer2D.s_IsLightingActive; if (!layerBatch.lightStats.useLights || isVolumetric && !layerBatch.lightStats.useVolumetricLights || - !isDebugLightingActive) + !isLightingActive) return; // Render single RTs by for apis that don't support MRTs diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs index 67aec294994..bd3998ce3d9 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs @@ -39,7 +39,7 @@ private static void Execute(RasterGraphContext context, PassData passData) RendererLighting.SetLightShaderGlobals(cmd, passData.lightBlendStyles, passData.blendStyleIndices); #if UNITY_EDITOR - if (passData.isLitView) + if (passData.isLightingActive) #endif { if (passData.layerUseLights) @@ -87,7 +87,7 @@ class PassData internal bool activeDebugHandler; #if UNITY_EDITOR - internal bool isLitView; // Required for prefab view and preview camera + internal bool isLightingActive; // Required for prefab view and preview camera #endif } @@ -100,35 +100,23 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData CommonResourceData commonResourceData = frameData.Get(); var layerBatch = layerBatches[batchIndex]; - bool isLitView = true; -#if UNITY_EDITOR - // Early out for prefabs - if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null) - isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting; - - // Early out for preview camera - if (cameraData.cameraType == CameraType.Preview) - isLitView = false; - - DebugHandler debugHandler = GetActiveDebugHandler(cameraData); - if (debugHandler != null) - isLitView = debugHandler.IsLightingActive; -#endif + // Check for lighting in scene/prefab/preview camera + var isLightingActive = Renderer2D.s_IsLightingActive; // Preset global light textures for first batch if (batchIndex == 0) { using (var builder = graph.AddRasterRenderPass(k_SetLightBlendTexture, out var passData, m_SetLightBlendTextureProfilingSampler)) { - if (layerBatch.lightStats.useLights && isLitView) + if (layerBatch.lightStats.useLights && isLightingActive) { passData.lightTextures = universal2DResourceData.lightTextures[batchIndex]; for (var i = 0; i < passData.lightTextures.Length; i++) builder.UseTexture(passData.lightTextures[i]); } - SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLitView); + SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLightingActive); builder.AllowGlobalStateModification(true); @@ -147,7 +135,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData passData.isSceneLit = rendererData.lightCullResult.IsSceneLit(); passData.layerUseLights = layerBatch.lightStats.useLights; #if UNITY_EDITOR - passData.isLitView = isLitView; + passData.isLightingActive = isLightingActive; #endif var drawSettings = CreateDrawingSettings(k_ShaderTags, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent); @@ -172,7 +160,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData builder.UseRendererList(passData.rendererList); } - if (passData.layerUseLights && isLitView) + if (passData.layerUseLights && isLightingActive) { passData.lightTextures = universal2DResourceData.lightTextures[batchIndex]; for (var i = 0; i < passData.lightTextures.Length; i++) @@ -193,7 +181,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData // Post set global light textures for next renderer pass var nextBatch = batchIndex + 1; if (nextBatch < universal2DResourceData.lightTextures.Length) - SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLitView); + SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLightingActive); builder.SetRenderFunc((PassData data, RasterGraphContext context) => { @@ -202,9 +190,9 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData } } - void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLitView) + void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLightingActive) { - if (isLitView) + if (isLightingActive) { if (layerBatch.lightStats.useLights) { 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 1608e94aa0b..778f2e19a71 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 @@ -69,6 +69,7 @@ private struct ImportResourceSummary internal bool m_CreateColorTexture; internal bool m_CreateDepthTexture; bool ppcUpscaleRT = false; + static internal bool s_IsLightingActive; PostProcessPassRenderGraph m_PostProcessPassRenderGraph; ColorGradingLutPass m_ColorGradingLutPassRenderGraph; @@ -343,8 +344,10 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull void InitializeLayerBatches() { Universal2DResourceData resourceData = frameData.Get(); + UniversalCameraData cameraData = frameData.Get(); m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount); + s_IsLightingActive = IsSceneViewOrPreviewLightingActive(cameraData); // Initialize textures dependent on batch size if (resourceData.normalsTexture.Length != m_BatchCount) @@ -1074,5 +1077,21 @@ internal static bool supportsMRT } internal override bool supportsNativeRenderPassRendergraphCompiler => true; + + static internal bool IsSceneViewOrPreviewLightingActive(UniversalCameraData cameraData) + { + DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData); + var isLightingActive = debugHandler?.IsLightingActive ?? true; + +#if UNITY_EDITOR + if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null) + isLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting; + + if (cameraData.isPreviewCamera && cameraData.camera.name == "Preview Scene Camera") + isLightingActive = false; +#endif + + return isLightingActive; + } } }