From 2b5fe2b706685e73a372657abf9b56d4fad1a98a Mon Sep 17 00:00:00 2001 From: Robin Bradley Date: Mon, 18 May 2026 18:16:06 +0000 Subject: [PATCH 01/63] [content automatically redacted] touching PlatformDependent folder --- .../Targets/UniversalDecalSubTarget.cs | 1 + .../Targets/UniversalLitSubTarget.cs | 1 + .../ShaderGraph/Targets/UniversalTarget.cs | 6 +++++ .../Targets/UniversalTerrainLitSubTarget.cs | 1 + .../Targets/UniversalUnlitSubTarget.cs | 1 + .../Runtime/DeferredLights.cs | 1 + .../ShaderLibrary/GBufferOutputFormat.hlsl | 25 +++++++++++++++++++ .../GBufferOutputFormat.hlsl.meta | 7 ++++++ .../Shaders/BakedLit.shader | 1 + .../Shaders/ComplexLit.shader | 1 + .../Shaders/Lit.shader | 1 + .../Shaders/Nature/SpeedTree7.shader | 1 + .../Shaders/Nature/SpeedTree7Billboard.shader | 1 + .../Shaders/Nature/SpeedTree8.shader | 2 +- .../Shaders/Particles/ParticlesLit.shader | 1 + .../Particles/ParticlesSimpleLit.shader | 1 + .../Shaders/SimpleLit.shader | 1 + .../Shaders/Terrain/TerrainLit.shader | 1 + .../Shaders/Terrain/TerrainLitAdd.shader | 1 + .../Shaders/Terrain/TerrainLitBase.shader | 1 + .../Shaders/Terrain/WavingGrass.shader | 1 + .../Terrain/WavingGrassBillboard.shader | 1 + .../Shaders/Unlit.shader | 1 + 23 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl create mode 100644 Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl.meta diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs index b73a8719002..4864d96e608 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs @@ -1121,6 +1121,7 @@ static class DecalIncludes // Post-graph { DecalPostgraph }, + { CoreIncludes.GBufferOutputFormat }, }; public static IncludeCollection ScenePicking = new IncludeCollection diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs index 7e705a473ac..089265acf82 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs @@ -941,6 +941,7 @@ static class LitIncludes { CoreIncludes.CorePostgraph }, { kGBuffer, IncludeLocation.Postgraph }, { kPBRGBufferPass, IncludeLocation.Postgraph }, + { CoreIncludes.GBufferOutputFormat }, }; public static readonly IncludeCollection Meta = new IncludeCollection 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 f96bfb28f30..71ae728ccc3 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 @@ -1776,6 +1776,7 @@ static class CoreIncludes const string kFog = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"; const string kRenderingLayers = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"; const string kProbeVolumes = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"; + const string kGbufferOutputFormat = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl"; public static readonly IncludeCollection CorePregraph = new IncludeCollection { @@ -1916,6 +1917,11 @@ static class CoreIncludes { { kLODCrossFade, IncludeLocation.Pregraph } }; + + public static readonly IncludeCollection GBufferOutputFormat = new IncludeCollection + { + { kGbufferOutputFormat, IncludeLocation.Postgraph, true } + }; } #endregion diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTerrainLitSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTerrainLitSubTarget.cs index b385663ea79..a303f02bce8 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTerrainLitSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTerrainLitSubTarget.cs @@ -1633,6 +1633,7 @@ static class TerrainCoreIncludes { TerrainCoreIncludes.CorePostgraph }, { TerrainCoreIncludes.kGBuffer, IncludeLocation.Postgraph }, { TerrainCoreIncludes.kPBRGBufferPass, IncludeLocation.Postgraph }, + { CoreIncludes.GBufferOutputFormat }, }; public static readonly IncludeCollection Meta = new IncludeCollection diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs index 465d38f7f90..9dfa5a538a9 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs @@ -586,6 +586,7 @@ static class UnlitIncludes // Post-graph { CoreIncludes.CorePostgraph }, { kUnlitGBufferPass, IncludeLocation.Postgraph }, + { CoreIncludes.GBufferOutputFormat }, }; public static IncludeCollection LightingIncludes = new IncludeCollection diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs b/Packages/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs index 8479225aa06..7e8f5af84f4 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs @@ -156,6 +156,7 @@ internal enum ClusterDeferredPasses internal int GBufferInputAttachmentCount { get { return 4 + (UseShadowMask ? 1 : 0); } } + // Keep these formats in sync with the formats in GBufferOutputFormat.hlsl internal GraphicsFormat GetGBufferFormat(int index) { if (index == GBufferAlbedoIndex) // sRGB albedo, materialFlags diff --git a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl new file mode 100644 index 00000000000..50a38ec224a --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl @@ -0,0 +1,25 @@ +// This file contains functionality for letting the Unity Shader Compiler know what render target formats could be used +// The functionality provided here is intended to be used during in the material GBuffer pass. +#ifndef UNIVERSAL_GBUFFEROUTPUTFORMAT_INCLUDED +#define UNIVERSAL_GBUFFEROUTPUTFORMAT_INCLUDED + +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferCommon.hlsl" + +// Keep these formats in sync with the formats returned in DeferredLights.GetGBufferFormat +#pragma rendertarget_format_hint MRT0 R8G8B8A8_SRGB +#pragma rendertarget_format_hint MRT1 R8G8B8A8_SRGB +#pragma rendertarget_format_hint MRT2 R8G8B8A8_SRGB +#pragma rendertarget_format_hint MRT3 R8G8B8A8_SRGB,B10G11R11_UFloatPack32 +#pragma rendertarget_format_hint MRT4 R32_SFloat // Assume GBUFFER_FEATURE_DEPTH is always enabled at the moment. +#if defined(GBUFFER_FEATURE_RENDERING_LAYERS) +#pragma rendertarget_format_hint MRT5 R8_UInt, R16_UInt, R32_UInt +#if defined(GBUFFER_FEATURE_SHADOWMASK) +#pragma rendertarget_format_hint MRT6 B8G8R8A8_UNorm, R8G8B8A8_UNorm +#endif +#else // GBUFFER_FEATURE_RENDERING_LAYERS +#if defined(GBUFFER_FEATURE_SHADOWMASK) +#pragma rendertarget_format_hint MRT5 B8G8R8A8_UNorm, R8G8B8A8_UNorm +#endif +#endif + +#endif // UNIVERSAL_GBUFFEROUTPUTFORMAT_INCLUDED diff --git a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl.meta b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl.meta new file mode 100644 index 00000000000..a7178b5a276 --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 87322610c9b88a64e8bce40c056d8116 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/BakedLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/BakedLit.shader index 89312d9872a..8d85c39e692 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/BakedLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/BakedLit.shader @@ -156,6 +156,7 @@ Shader "Universal Render Pipeline/Baked Lit" // Lighting include is needed because of GI #include "Packages/com.unity.render-pipelines.universal/Shaders/BakedLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/BakedLitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader index 0af6f466e9e..4662bd572b8 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader @@ -323,6 +323,7 @@ Shader "Universal Render Pipeline/Complex Lit" // Includes #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader index c20112e0240..223ac738297 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader @@ -321,6 +321,7 @@ Shader "Universal Render Pipeline/Lit" // Includes #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader index 22527c1a269..6e1fddc57e4 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader @@ -173,6 +173,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7" #include "SpeedTree7Input.hlsl" #include "SpeedTree7Passes.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader index bf07ebea661..f3b42d851f4 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader @@ -117,6 +117,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7 Billboard" #include "SpeedTree7BillboardInput.hlsl" #include "SpeedTree7BillboardPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader index f728bc82a0e..c7c842bb8b3 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader @@ -170,7 +170,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" #include "SpeedTree8Input.hlsl" #include "SpeedTree8Passes.hlsl" - + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader index 71303ef12e9..59a40b06c55 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader @@ -238,6 +238,7 @@ Shader "Universal Render Pipeline/Particles/Lit" // Includes #include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitGbufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader index 6fac3fdacbe..eb2ddef1c40 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader @@ -245,6 +245,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit" // Includes #include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl" #include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader index 0a76394a268..622cc282052 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader @@ -278,6 +278,7 @@ Shader "Universal Render Pipeline/Simple Lit" // Includes #include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader index b914b8ccc35..e08dcbfe11e 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader @@ -203,6 +203,7 @@ Shader "Universal Render Pipeline/Terrain/Lit" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitAdd.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitAdd.shader index 80232b438d8..0716b198c16 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitAdd.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitAdd.shader @@ -170,6 +170,7 @@ Shader "Hidden/Universal Render Pipeline/Terrain/Lit (Add Pass)" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader index 1cefc8c4e6d..712d787fe64 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader @@ -164,6 +164,7 @@ Shader "Hidden/Universal Render Pipeline/Terrain/Lit (Base Pass)" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader index 8c8160709ff..4ea0a5477bf 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader @@ -124,6 +124,7 @@ Shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader index 2225d078fb1..08aaf6d48e0 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader @@ -108,6 +108,7 @@ Shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Unlit.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Unlit.shader index 387802f5754..d46ef332d62 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Unlit.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Unlit.shader @@ -139,6 +139,7 @@ Shader "Universal Render Pipeline/Unlit" // Includes #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitGBufferPass.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferOutputFormat.hlsl" ENDHLSL } From 93f40c7e4e0bc54eebb7d61759e04f30f43f24e0 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Mon, 18 May 2026 18:16:07 +0000 Subject: [PATCH 02/63] [Port] [6000.5] Fix SupportedOnRenderPipeline/SupportedOnRenderer to not leave types null on bad input (UUM-140584) --- .../Runtime/SupportedOnRenderer.cs | 4 +- .../SupportedOnRendererAttributeTests.cs | 39 +++++++++++++++++++ .../SupportedOnRendererAttributeTests.cs.meta | 2 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs create mode 100644 Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs.meta diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/SupportedOnRenderer.cs b/Packages/com.unity.render-pipelines.universal/Runtime/SupportedOnRenderer.cs index 4144a51a5f7..7e567b48328 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/SupportedOnRenderer.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/SupportedOnRenderer.cs @@ -32,6 +32,7 @@ public SupportedOnRendererAttribute(params Type[] renderers) if (renderers == null) { Debug.LogError($"The {nameof(SupportedOnRendererAttribute)} parameters cannot be null."); + rendererTypes = Array.Empty(); return; } @@ -40,7 +41,8 @@ public SupportedOnRendererAttribute(params Type[] renderers) var r = renderers[i]; if (r == null || !typeof(ScriptableRendererData).IsAssignableFrom(r)) { - Debug.LogError($"The {nameof(SupportedOnRendererAttribute)} Attribute targets an invalid {nameof(ScriptableRendererData)}. One of the types cannot be assigned from {nameof(ScriptableRendererData)}"); + Debug.LogError($"The {nameof(SupportedOnRendererAttribute)} Attribute targets an invalid {nameof(ScriptableRendererData)}. One of the types cannot be assigned from {nameof(ScriptableRendererData)}."); + rendererTypes = Array.Empty(); return; } } diff --git a/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs b/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs new file mode 100644 index 00000000000..dee29ae69bf --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Text.RegularExpressions; +using NUnit.Framework; +using UnityEngine.TestTools; + +namespace UnityEngine.Rendering.Universal.Tests +{ + [TestFixture] + sealed class SupportedOnRendererAttributeTests + { + class CustomRenderer { } + + static readonly Regex k_InvalidTypeMessage = new($@"{nameof(SupportedOnRendererAttribute)} Attribute targets an invalid {nameof(ScriptableRendererData)}"); + static readonly Regex k_NullParametersMessage = new($@"{nameof(SupportedOnRendererAttribute)} parameters cannot be null"); + + [Test] + public void NonScriptableRendererDataType_LogsErrorAndProducesEmptyTypeArray() + { + LogAssert.Expect(LogType.Error, k_InvalidTypeMessage); + + var attr = new SupportedOnRendererAttribute(typeof(CustomRenderer)); + + Assert.That(attr.rendererTypes, Is.Not.Null); + Assert.That(attr.rendererTypes, Is.Empty); + } + + [Test] + public void NullType_LogsErrorAndProducesEmptyTypeArray() + { + LogAssert.Expect(LogType.Error, k_NullParametersMessage); + + var attr = new SupportedOnRendererAttribute((Type[])null); + + Assert.That(attr.rendererTypes, Is.Not.Null); + Assert.That(attr.rendererTypes, Is.Empty); + } + + } +} diff --git a/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs.meta b/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs.meta new file mode 100644 index 00000000000..7f2f11283c6 --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/Tests/Editor/SupportedOnRendererAttributeTests.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3fc1d215954974240928b390996c4362 \ No newline at end of file From 9eb7152eedf2d7fcf91ec755ba29429e4a18192c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nanho=20Lee=20=EF=BC=88=EC=9D=B4=EB=82=9C=ED=98=B8?= =?UTF-8?q?=EF=BC=89?= Date: Mon, 18 May 2026 18:16:08 +0000 Subject: [PATCH 03/63] [Port][6000.5] Stable Light Index Tracking using dataIndex in HDRP --- .../Light/HDGpuLightsBuilder.LightLoop.cs | 31 ++++++++-------- .../Light/HDShadowRequestUpdateJob.cs | 18 +++++----- .../Runtime/Lighting/Shadow/HDShadowAtlas.cs | 35 ++++++++++++++++--- .../Lighting/Shadow/HDShadowManager.cs | 22 +++++++----- .../HDRenderPipeline.LightLoop.cs | 2 +- 5 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs index a73f865a75d..05aa145ab0f 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs @@ -605,6 +605,7 @@ internal unsafe void UpdateShadowRequestsAndCalculateShadowIndices( ref HDShadowRequest shadowRequest = ref requestStorageUnsafe.ElementAt(shadowRequestHandle.storageIndexForRequestIndex); int additionalLightDataIndex = directionalUpdateInfo.additionalLightDataIndex; int lightIndex = directionalUpdateInfo.lightIndex; + int dataIndex = visibleLights.visibleLightEntityDataIndices[lightIndex]; Vector2 viewportSize = directionalUpdateInfo.viewportSize; VisibleLight* visibleLightPtr = visibleLightsArrayPtr + lightIndex; ref VisibleLight visibleLight = ref UnsafeUtility.AsRef(visibleLightPtr); @@ -624,7 +625,7 @@ internal unsafe void UpdateShadowRequestsAndCalculateShadowIndices( SetDirectionalRequestSettings(ref shadowRequest, shadowRequestHandle, visibleLight, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, shadowRequest.cullingSplit.deviceProjectionMatrix, viewportSize, - lightIndex, directionalShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, dataIndex, directionalShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); shadowRequest.shouldUseCachedShadowData = false; shadowRequest.shouldRenderCachedComponent = true; @@ -645,7 +646,6 @@ internal unsafe void UpdateShadowRequestsAndCalculateShadowIndices( shadowRequest.cullingSplit.deviceProjectionYFlip = _ProjMatrix; } - int dataIndex = visibleLights.visibleLightEntityDataIndices[lightIndex]; HDAdditionalLightData additionalLightData = lightEntities.hdAdditionalLightData[dataIndex]; if (needToUpdateCachedContent && hdCamera.camera.cameraType != CameraType.Reflection) { @@ -674,7 +674,7 @@ internal unsafe void UpdateShadowRequestsAndCalculateShadowIndices( SetDirectionalRequestSettings(ref shadowRequest, shadowRequestHandle, visibleLight, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, shadowRequest.cullingSplit.deviceProjectionMatrix, viewportSize, - lightIndex, directionalShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, directionalShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } @@ -791,7 +791,7 @@ internal static unsafe void UpdateCachedSpotShadowRequestsAndResolutionRequests( SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); hasUpdatedRequestData = true; shadowRequest.shouldUseCachedShadowData = false; @@ -817,7 +817,7 @@ internal static unsafe void UpdateCachedSpotShadowRequestsAndResolutionRequests( SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } } @@ -858,7 +858,7 @@ internal static unsafe void UpdateDynamicSpotShadowRequestsAndResolutionRequests SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, shadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } } @@ -963,7 +963,7 @@ internal static Vector3 GetPositionFromVisibleLight(in VisibleLight visibleLight [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetDirectionalRequestSettings(ref HDShadowRequest shadowRequest, HDShadowRequestHandle shadowRequestHandle, in VisibleLight visibleLight, Vector3 cameraPos, - Matrix4x4 invViewProjection, in Matrix4x4 projection, in Matrix4x4 devProjMatrix, Vector2 viewportSize, int lightIndex, HDShadowFilteringQuality filteringQuality, + Matrix4x4 invViewProjection, in Matrix4x4 projection, in Matrix4x4 devProjMatrix, Vector2 viewportSize, int lightIndex, int dataIndex, HDShadowFilteringQuality filteringQuality, in HDAdditionalLightDataUpdateInfo additionalLightData, int shaderConfigCameraRelativeRendering, NativeList frustumPlanesStorage) { MakeViewAndViewProjectionCameraRelative(ref shadowRequest, ref invViewProjection, shaderConfigCameraRelativeRendering, cameraPos); @@ -977,7 +977,7 @@ internal static void SetDirectionalRequestSettings(ref HDShadowRequest shadowReq float baseBias = GetBaseBias(filteringQuality == HDShadowFilteringQuality.High, 0.0f); SetCommonShadowRequestSettings(ref shadowRequest, shadowRequestHandle, cameraPos, invViewProjection, projection, - viewportSize, lightIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, + viewportSize, lightIndex, dataIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, ShadowMapType.CascadedDirectional, zBufferParam, softnessAndRangeScale.x, position, baseBias, true, false); @@ -1009,7 +1009,7 @@ internal static void SetDirectionalRequestSettings(ref HDShadowRequest shadowReq [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetAreaRequestSettings(ref HDShadowRequest shadowRequest, HDShadowRequestHandle shadowRequestHandle, in VisibleLight visibleLight, float forwardOffset, - Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, + Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, int dataIndex, HDAreaShadowFilteringQuality areaFilteringQuality, in HDAdditionalLightDataUpdateInfo additionalLightData, int shaderConfigCameraRelativeRendering, NativeList frustumPlanesStorage) @@ -1024,7 +1024,7 @@ internal static void SetAreaRequestSettings(ref HDShadowRequest shadowRequest, float baseBias = GetBaseBias(areaFilteringQuality == HDAreaShadowFilteringQuality.High, softness); SetCommonShadowRequestSettings(ref shadowRequest, shadowRequestHandle, cameraPos, invViewProjection, projection, - viewportSize, lightIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, + viewportSize, lightIndex, dataIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, ShadowMapType.AreaLightAtlas, zBufferParam, softness, position, baseBias, false, true); @@ -1040,7 +1040,7 @@ internal static void SetAreaRequestSettings(ref HDShadowRequest shadowRequest, [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetSpotRequestSettings(ref HDShadowRequest shadowRequest, HDShadowRequestHandle shadowRequestHandle, in VisibleLight visibleLight, float forwardOffset, - Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, + Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, int dataIndex, HDShadowFilteringQuality filteringQuality, in HDAdditionalLightDataUpdateInfo additionalLightData, int shaderConfigCameraRelativeRendering, NativeList frustumPlanesStorage) @@ -1065,7 +1065,7 @@ internal static void SetSpotRequestSettings(ref HDShadowRequest shadowRequest, float baseBias = GetBaseBias(filteringQuality == HDShadowFilteringQuality.High, softness); SetCommonShadowRequestSettings(ref shadowRequest, shadowRequestHandle, cameraPos, invViewProjection, projection, - viewportSize, lightIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, + viewportSize, lightIndex, dataIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, ShadowMapType.PunctualAtlas, zBufferParam, softness, position, baseBias, hasOrthoMatrix, true); } @@ -1073,7 +1073,7 @@ internal static void SetSpotRequestSettings(ref HDShadowRequest shadowRequest, [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetPointRequestSettings(ref HDShadowRequest shadowRequest, HDShadowRequestHandle shadowRequestHandle, in VisibleLight visibleLight, - Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, + Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, int dataIndex, HDShadowFilteringQuality filteringQuality, in HDAdditionalLightDataUpdateInfo additionalLightData, int shaderConfigCameraRelativeRendering, NativeList frustumPlanesStorage) @@ -1087,14 +1087,14 @@ internal static void SetPointRequestSettings(ref HDShadowRequest shadowRequest, float baseBias = GetBaseBias(filteringQuality == HDShadowFilteringQuality.High, softness); SetCommonShadowRequestSettings(ref shadowRequest, shadowRequestHandle, cameraPos, invViewProjection, projection, - viewportSize, lightIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, + viewportSize, lightIndex, dataIndex, additionalLightData, shaderConfigCameraRelativeRendering, frustumPlanesStorage, ShadowMapType.PunctualAtlas, zBufferParam, softness, position, baseBias, false, true); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetCommonShadowRequestSettings(ref HDShadowRequest shadowRequest, - HDShadowRequestHandle shadowRequestHandle, Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, + HDShadowRequestHandle shadowRequestHandle, Vector3 cameraPos, Matrix4x4 invViewProjection, Matrix4x4 projection, Vector2 viewportSize, int lightIndex, int dataIndex, in HDAdditionalLightDataUpdateInfo additionalLightData, int shaderConfigCameraRelativeRendering, NativeList frustumPlanesStorage, ShadowMapType shadowMapType, float4 zBufferParam, float softness, Vector3 position, float baseBias, bool hasOrthoMatrix, bool zClip) { @@ -1107,6 +1107,7 @@ internal static void SetCommonShadowRequestSettings(ref HDShadowRequest shadowRe shadowRequest.shadowToWorld = invViewProjection.transpose; shadowRequest.zClip = zClip; shadowRequest.lightIndex = lightIndex; + shadowRequest.dataIndex = dataIndex; // We don't allow shadow resize for directional cascade shadow shadowRequest.shadowMapType = shadowMapType; diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDShadowRequestUpdateJob.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDShadowRequestUpdateJob.cs index b0321d3ea32..4650b79af5d 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDShadowRequestUpdateJob.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDShadowRequestUpdateJob.cs @@ -323,7 +323,7 @@ public void UpdateCachedPointShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetPointRequestSettings(ref shadowRequest, shadowRequestHandle, in pointUpdateInfo.visibleLight, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); hasUpdatedRequestData = true; shadowRequest.shouldUseCachedShadowData = false; @@ -344,7 +344,7 @@ public void UpdateCachedPointShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetPointRequestSettings(ref shadowRequest, shadowRequestHandle, in pointUpdateInfo.visibleLight, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } } @@ -370,7 +370,7 @@ public void UpdateDynamicPointShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetPointRequestSettings(ref shadowRequest, shadowRequestHandle, in pointUpdateInfo.visibleLight, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } @@ -407,7 +407,7 @@ public void UpdateCachedSpotShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); hasUpdatedRequestData = true; shadowRequest.shouldUseCachedShadowData = false; @@ -428,7 +428,7 @@ public void UpdateCachedSpotShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } } @@ -454,7 +454,7 @@ public void UpdateDynamicSpotShadowRequestsAndResolutionRequests() HDGpuLightsBuilder.SetSpotRequestSettings(ref shadowRequest, shadowRequestHandle, spotUpdateInfo.visibleLight, 0f, worldSpaceCameraPos, shadowRequest.cullingSplit.invViewProjection, shadowRequest.cullingSplit.projection, viewportSize, - lightIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); + lightIndex, additionalLightDataIndex, punctualShadowFilteringQuality, updateInfo, shaderConfigCameraRelativeRendering, frustumPlanesStorage); } } @@ -487,7 +487,7 @@ public void UpdateCachedAreaShadowRequestsAndResolutionRequests(NativeList visibleLightEntityDataIndices; } private void SetCommonRenderPassData(RenderShadowMapsCommonPassData passData, in IUnsafeRenderGraphBuilder builder, RenderGraph renderGraph, in ShaderVariablesGlobal globalCBData) @@ -427,7 +428,10 @@ private static void ResetDepthState(CommandBuffer cmd) } public static Vector4[] frustumPlanesScratchpad = new Vector4[HDShadowRequest.frustumPlanesCount]; - internal unsafe TextureHandle RenderShadowMaps(RenderGraph renderGraph, ScriptableRenderContext renderContext, CullingResults cullResults, in ShaderVariablesGlobal globalCBData, FrameSettings frameSettings, string shadowPassName) + internal unsafe TextureHandle RenderShadowMaps( + RenderGraph renderGraph, ScriptableRenderContext renderContext, + CullingResults cullResults, NativeArray visibleLightEntityDataIndices, + in ShaderVariablesGlobal globalCBData, FrameSettings frameSettings, string shadowPassName) { TextureHandle atlasTexture; @@ -440,6 +444,7 @@ internal unsafe TextureHandle RenderShadowMaps(RenderGraph renderGraph, Scriptab passData.shadowDrawSettings = new ShadowDrawingSettings(cullResults, 0); passData.shadowDrawSettings.useRenderingLayerMaskTest = frameSettings.IsEnabled(FrameSettingsField.LightLayers); passData.renderContext = renderContext; + passData.visibleLightEntityDataIndices = visibleLightEntityDataIndices; builder.SetRenderFunc( static (RenderShadowMapsPassData data, UnsafeGraphContext ctx) => @@ -458,9 +463,26 @@ internal unsafe TextureHandle RenderShadowMaps(RenderGraph renderGraph, Scriptab Vector4[] planesScratchpad = frustumPlanesScratchpad; + var cullResults = data.shadowDrawSettings.cullingResults; + var visibleLightCount = cullResults.visibleLights.Length; + // Build mapping from stable dataIndex to current light index. + // Allocated per-pass (not shared) to remain RenderGraph-compliant and avoid + // implicit dependencies if the execution model changes. + var dataIndexToCurrentLightIndex = new NativeHashMap(visibleLightCount, Allocator.Temp); + + for (int i = 0; i < visibleLightCount; ++i) + { + int dataIndex = data.visibleLightEntityDataIndices[i]; + if (dataIndex >= 0) + dataIndexToCurrentLightIndex[dataIndex] = i; + } + foreach (var shadowRequestHandle in data.shadowRequests) { ref var shadowRequest = ref requestStorageUnsafe.ElementAt(shadowRequestHandle.storageIndexForShadowRequest); + if (!dataIndexToCurrentLightIndex.TryGetValue(shadowRequest.dataIndex, out int currentCorrectIndex)) + continue; + var commonState = CommonPerShadowRequestUpdate(natCmd, data, shadowRequest, shadowRequestHandle, ref planesScratchpad, ref frustumPlanesStorageUnsafe); if (commonState.shouldSkipRequest) continue; @@ -478,7 +500,7 @@ internal unsafe TextureHandle RenderShadowMaps(RenderGraph renderGraph, Scriptab if (!commonState.mixedInDynamicAtlas) CoreUtils.DrawFullScreen(natCmd, data.clearMaterial, null, 0); - data.shadowDrawSettings.lightIndex = shadowRequest.lightIndex; + data.shadowDrawSettings.lightIndex = currentCorrectIndex; data.shadowDrawSettings.splitIndex = shadowRequest.cullingSplit.splitIndex; //TODO(ddebaets) as the shadowDrawSettings are modified in this loop, we generate this RL very last minute @@ -487,6 +509,8 @@ internal unsafe TextureHandle RenderShadowMaps(RenderGraph renderGraph, Scriptab natCmd.DrawRendererList(rl); } + dataIndexToCurrentLightIndex.Dispose(); + ResetDepthState(natCmd); }); @@ -735,14 +759,17 @@ internal TextureHandle BlurShadows(RenderGraph renderGraph) return m_ShadowMapOutput; } } - internal TextureHandle RenderShadows(RenderGraph renderGraph, ScriptableRenderContext renderContext, CullingResults cullResults, in ShaderVariablesGlobal globalCB, FrameSettings frameSettings, string shadowPassName) + internal TextureHandle RenderShadows( + RenderGraph renderGraph, ScriptableRenderContext renderContext, + CullingResults cullResults, NativeArray visibleLightEntityDataIndices, + in ShaderVariablesGlobal globalCB, FrameSettings frameSettings, string shadowPassName) { if (m_ShadowRequests.Length == 0) { return renderGraph.defaultResources.defaultShadowTexture; } - RenderShadowMaps(renderGraph, renderContext, cullResults, globalCB, frameSettings, shadowPassName); + RenderShadowMaps(renderGraph, renderContext, cullResults, visibleLightEntityDataIndices, globalCB, frameSettings, shadowPassName); if (m_BlurAlgorithm == BlurAlgorithm.EVSM) { diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs index 35d3b5b30ad..676be384596 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs @@ -195,6 +195,7 @@ internal struct HDShadowRequest // TODO: Remove these field once scriptable culling is here (currently required by ScriptableRenderContext.DrawShadows) public int lightIndex; + public int dataIndex; // end public float normalBias; @@ -298,6 +299,7 @@ public void InitDefault() zClip = default; shadowMapType = ShadowMapType.PunctualAtlas; lightIndex = default; + dataIndex = HDLightRenderDatabase.InvalidDataIndex; normalBias = default; worldTexelSize = default; slopeBias = default; @@ -1226,7 +1228,7 @@ public int GetShadowRequestCount() { return m_ShadowRequestCount; } - + internal void GetUnmanageDataForComputeCullingSplitsJob(ref HDShadowManagerDataForComputeCullingSplitsJob shadowManagerData) { shadowManagerData.requestCount = GetShadowRequestCount(); @@ -1373,7 +1375,11 @@ internal static ShadowResult ReadShadowResult(in ShadowResult shadowResult, IUns return result; } - internal void RenderShadows(RenderGraph renderGraph, ScriptableRenderContext renderContext, in ShaderVariablesGlobal globalCB, HDCamera hdCamera, CullingResults cullResults, ref ShadowResult result) + internal void RenderShadows( + RenderGraph renderGraph, ScriptableRenderContext renderContext, + in ShaderVariablesGlobal globalCB, HDCamera hdCamera, + CullingResults cullResults, NativeArray visibleLightEntityIndices, + ref ShadowResult result) { InvalidateAtlasOutputs(); @@ -1382,15 +1388,15 @@ internal void RenderShadows(RenderGraph renderGraph, ScriptableRenderContext ren (hdCamera.frameSettings.IsEnabled(FrameSettingsField.OpaqueObjects) || hdCamera.frameSettings.IsEnabled(FrameSettingsField.TransparentObjects))) { // Punctual - result.cachedPunctualShadowResult = cachedShadowManager.punctualShadowAtlas.RenderShadows(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Cached Punctual Lights Shadow Maps"); + result.cachedPunctualShadowResult = cachedShadowManager.punctualShadowAtlas.RenderShadows(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Cached Punctual Lights Shadow Maps"); BlitCachedShadows(renderGraph, ShadowMapType.PunctualAtlas); - result.punctualShadowResult = m_Atlas.RenderShadows(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Punctual Lights Shadow Maps"); + result.punctualShadowResult = m_Atlas.RenderShadows(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Punctual Lights Shadow Maps"); if (ShaderConfig.s_AreaLights == 1) { - cachedShadowManager.areaShadowAtlas.RenderShadowMaps(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Cached Area Lights Shadow Maps"); + cachedShadowManager.areaShadowAtlas.RenderShadowMaps(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Cached Area Lights Shadow Maps"); BlitCachedShadows(renderGraph, ShadowMapType.AreaLightAtlas); - m_AreaLightShadowAtlas.RenderShadowMaps(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Area Light Shadow Maps"); + m_AreaLightShadowAtlas.RenderShadowMaps(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Area Light Shadow Maps"); result.areaShadowResult = m_AreaLightShadowAtlas.BlurShadows(renderGraph); result.cachedAreaShadowResult = cachedShadowManager.areaShadowAtlas.BlurShadows(renderGraph); } @@ -1401,11 +1407,11 @@ internal void RenderShadows(RenderGraph renderGraph, ScriptableRenderContext ren if (cachedShadowManager.directionalLightAtlas.HasShadowRequests()) { cachedShadowManager.UpdateDirectionalCacheTexture(renderGraph); - cachedShadowManager.directionalLightAtlas.RenderShadows(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Cached Directional Lights Shadow Maps"); + cachedShadowManager.directionalLightAtlas.RenderShadows(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Cached Directional Lights Shadow Maps"); } BlitCachedShadows(renderGraph, ShadowMapType.CascadedDirectional); } - result.directionalShadowResult = m_CascadeAtlas.RenderShadows(renderGraph, renderContext, cullResults, globalCB, hdCamera.frameSettings, "Render Directional Light Shadow Maps"); + result.directionalShadowResult = m_CascadeAtlas.RenderShadows(renderGraph, renderContext, cullResults, visibleLightEntityIndices, globalCB, hdCamera.frameSettings, "Render Directional Light Shadow Maps"); } // TODO RENDERGRAPH diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index 4909219fe7f..a1a3cd58a97 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -721,7 +721,7 @@ void PushGlobalCameraParams(RenderGraph renderGraph, HDCamera hdCamera) internal ShadowResult RenderShadows(RenderGraph renderGraph, ScriptableRenderContext renderContext, HDCamera hdCamera, CullingResults cullResults, ref ShadowResult result) { - m_ShadowManager.RenderShadows(m_RenderGraph, renderContext, m_ShaderVariablesGlobalCB, hdCamera, cullResults, ref result); + m_ShadowManager.RenderShadows(m_RenderGraph, renderContext, m_ShaderVariablesGlobalCB, hdCamera, cullResults, m_ProcessedLightsBuilder.visibleLightEntityDataIndices, ref result); // Need to restore global camera parameters. PushGlobalCameraParams(renderGraph, hdCamera); return result; From 59d4f227530e8f50e715ace6326daf9d9311fabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sumin=20Cho=20=EF=BC=88=EC=A1=B0=EC=88=98=EB=AF=BC?= =?UTF-8?q?=EF=BC=89?= Date: Tue, 19 May 2026 15:31:06 +0000 Subject: [PATCH 04/63] Add performance warning message on Switch2 for DepthOfField --- .../PostProcessing/DepthOfFieldEditor.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/PostProcessing/DepthOfFieldEditor.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/PostProcessing/DepthOfFieldEditor.cs index 3165410858a..436ca8434ef 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/PostProcessing/DepthOfFieldEditor.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/PostProcessing/DepthOfFieldEditor.cs @@ -180,6 +180,24 @@ void DrawFocusSettings(int mode) void DrawQualitySettings() { + if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget()) + { + DepthOfField dof = HDEditorUtils.GetVolumeComponentDefaultState(); + + bool useDefaultQuality = !overrideState; + int effectiveQuality = useDefaultQuality + ? dof?.quality.value ?? (int)ScalableSettingLevelParameter.Level.Low + : value; + + if (effectiveQuality > (int)ScalableSettingLevelParameter.Level.Low && + effectiveQuality != k_CustomQuality) + { + string tierName = ((ScalableSettingLevelParameter.Level)effectiveQuality).ToString(); + + HDEditorUtils.ShowFeatureOptimisationWarning(tierName); + } + } + using (new QualityScope(this)) { PropertyField(m_NearSampleCount, Styles.k_NearSampleCount); From 7ce7fffc64b2ecf8859562be2ac2650d467005c9 Mon Sep 17 00:00:00 2001 From: Pablo Bayarri Romar Date: Tue, 19 May 2026 15:31:07 +0000 Subject: [PATCH 05/63] Use VFS-aware file reads in ShaderGraph importers to support long paths (UUM-120311) --- .../Editor/Importers/ShaderGraphImporter.cs | 2 +- .../Editor/Importers/ShaderGraphImporterEditor.cs | 2 +- .../Editor/Importers/ShaderSubGraphImporter.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs index 3dc53284f7b..bec99e1e327 100644 --- a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs +++ b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs @@ -516,7 +516,7 @@ internal static string GetShaderText(string path, out List configuredTextures, AssetCollection assetCollection, out GraphData graph) { - var textGraph = File.ReadAllText(path, Encoding.UTF8); + var textGraph = FileUtilities.ReadAllTextUTF8(path); graph = new GraphData { messageManager = new MessageManager(), diff --git a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporterEditor.cs b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporterEditor.cs index f383ea34bbc..3931d8a18f5 100644 --- a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporterEditor.cs +++ b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporterEditor.cs @@ -30,7 +30,7 @@ public override void OnInspectorGUI() serializedObject.Update(); GraphData GetGraphData(AssetImporter importer) { - var textGraph = File.ReadAllText(importer.assetPath, Encoding.UTF8); + var textGraph = FileUtilities.ReadAllTextUTF8(importer.assetPath); var graphObject = CreateInstance(); graphObject.hideFlags = HideFlags.HideAndDontSave; bool isSubGraph; diff --git a/Packages/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs b/Packages/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs index bc4907b071a..daccda2e4a7 100644 --- a/Packages/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs +++ b/Packages/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs @@ -78,7 +78,7 @@ public override void OnImportAsset(AssetImportContext ctx) var subGraphPath = ctx.assetPath; var subGraphGuid = AssetDatabase.AssetPathToGUID(subGraphPath); graphAsset.assetGuid = subGraphGuid; - var textGraph = File.ReadAllText(subGraphPath, Encoding.UTF8); + var textGraph = FileUtilities.ReadAllTextUTF8(subGraphPath); var messageManager = new MessageManager(); var graphData = new GraphData { From 5b2084d974886b4762715f26af0994224369e6e0 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Tue, 19 May 2026 15:31:07 +0000 Subject: [PATCH 06/63] [Port] [6000.5] Lighting/uum 141983 apv clear on incompatible layout --- .../Editor/Lighting/ProbeVolume/ProbeGIBaking.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs b/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs index 1ce93cfc1bd..48e0430d820 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs @@ -1717,8 +1717,11 @@ Vector3Int GetCellPositionFromVoxel(Vector3Int voxelToLookup, int cellSizeInBric continue; // 3. - // Overwrite lighting data with trilinear sampled data from the brick with highest subdiv level - float brickSize = ProbeReferenceVolume.instance.BrickSize(largestBrick.subdivisionLevel - 1); + // Overwrite lighting data with trilinear sampled data from the brick with highest subdiv level. + // Use minBrickSize from m_ProfileInfo (live bake settings), not ProbeReferenceVolume.instance, + // because that runtime state is restored to the previous bake's snapshot at the end of + // ApplySubdivisionResults and would be stale here. UUM-141983. + float brickSize = ProbeVolumeUtil.BrickSize(minBrickSize, largestBrick.subdivisionLevel - 1); float3 uvw = math.clamp((pos - (Vector3)largestBrick.position * minBrickSize) / brickSize, 0, 3); var probe = Vector3Int.FloorToInt(uvw); From 78526540eb0dca84c5b6a69ca943f5a02897be7a Mon Sep 17 00:00:00 2001 From: Evergreen Date: Tue, 19 May 2026 15:31:08 +0000 Subject: [PATCH 07/63] [Port] [6000.5] [HDRP] Fix directional shadow truncation caused by spurious _ZClip property --- .../Runtime/Material/Lit/Lit.shader | 1 - 1 file changed, 1 deletion(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 6149ddef158..421c0244a11 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -144,7 +144,6 @@ Shader "HDRP/Lit" [Enum(UnityEngine.Rendering.HighDefinition.OpaqueCullMode)] _OpaqueCullMode("_OpaqueCullMode", Int) = 2 // Back culling by default [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal [HideInInspector] _ZTestGBuffer("_ZTestGBuffer", Int) = 4 - [HideInInspector] _ZClip("_ZClip", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("Transparent ZTest", Int) = 4 // Less equal [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 From a98654c79a2063b60fdfc22631d8c6a9c5c22b2f Mon Sep 17 00:00:00 2001 From: Evergreen Date: Thu, 21 May 2026 00:08:06 +0000 Subject: [PATCH 08/63] [Port] [6000.5] [URP] Hide renderer feature sub-assets in project browser --- .../Editor/ScriptableRendererDataEditor.cs | 19 +- .../Runtime/ScriptableRendererData.cs | 26 +++ .../ScriptableRendererDataEditorTests.cs | 179 ++++++++++++++++++ .../ScriptableRendererDataEditorTests.cs.meta | 2 + 4 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs create mode 100644 Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs.meta diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ScriptableRendererDataEditor.cs b/Packages/com.unity.render-pipelines.universal/Editor/ScriptableRendererDataEditor.cs index 4261385ed00..8d25eac1858 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ScriptableRendererDataEditor.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ScriptableRendererDataEditor.cs @@ -51,13 +51,21 @@ static Styles() private void OnEnable() { - m_RendererFeatures = serializedObject.FindProperty(nameof(ScriptableRendererData.m_RendererFeatures)); - m_RendererFeaturesMap = serializedObject.FindProperty(nameof(ScriptableRendererData.m_RendererFeatureMap)); + InitializeIfNeeded(); var editorObj = new SerializedObject(this); m_FalseBool = editorObj.FindProperty(nameof(falseBool)); UpdateEditorList(); } + void InitializeIfNeeded() + { + if (m_RendererFeatures == null) + m_RendererFeatures = serializedObject.FindProperty(nameof(ScriptableRendererData.m_RendererFeatures)); + + if (m_RendererFeaturesMap == null) + m_RendererFeaturesMap = serializedObject.FindProperty(nameof(ScriptableRendererData.m_RendererFeatureMap)); + } + private void OnDisable() { ClearEditorsList(); @@ -261,10 +269,13 @@ private void OnContextClick(Object rendererFeatureObject, Vector2 position, int internal void AddComponent(Type type) { + InitializeIfNeeded(); + serializedObject.Update(); ScriptableObject component = CreateInstance(type); component.name = $"{type.Name}"; + component.hideFlags |= HideFlags.HideInHierarchy; Undo.RegisterCreatedObjectUndo(component, "Add Renderer Feature"); // Store this new effect as a sub-asset so we can reference it safely afterwards @@ -297,6 +308,8 @@ internal void AddComponent(Type type) private void RemoveComponent(int id) { + InitializeIfNeeded(); + SerializedProperty property = m_RendererFeatures.GetArrayElementAtIndex(id); Object component = property.objectReferenceValue; property.objectReferenceValue = null; @@ -365,8 +378,6 @@ private void ClearEditorsList() private void ForceSave() { EditorUtility.SetDirty(target); - AssetDatabase.SaveAssetIfDirty(target); - AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); } } diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/ScriptableRendererData.cs b/Packages/com.unity.render-pipelines.universal/Runtime/ScriptableRendererData.cs index c1fd1233f9a..8a8762a59b3 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/ScriptableRendererData.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/ScriptableRendererData.cs @@ -78,9 +78,35 @@ protected virtual void OnValidate() // when ScriptableRendererFeatures haven't been compiled before this check). if (!EditorApplication.isCompiling && m_RendererFeatures.Contains(null)) ValidateRendererFeatures(); + + MigrateRendererFeatureHideFlags(); #endif } +#if UNITY_EDITOR + /// + /// Migrates renderer features to use HideInHierarchy flag so they don't appear in the project browser. + /// + void MigrateRendererFeatureHideFlags() + { + if (AssetDatabase.IsAssetImportWorkerProcess()) + return; + bool dirty = false; + foreach (var feature in m_RendererFeatures) + { + if (feature != null && (feature.hideFlags & HideFlags.HideInHierarchy) == 0) + { + feature.hideFlags |= HideFlags.HideInHierarchy; + EditorUtility.SetDirty(feature); + dirty = true; + } + } + + if (dirty) + EditorUtility.SetDirty(this); + } +#endif + /// /// This function is called when the object becomes enabled and active. /// diff --git a/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs b/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs new file mode 100644 index 00000000000..11d3ccaf64a --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs @@ -0,0 +1,179 @@ +using NUnit.Framework; +using UnityEditor; +using UnityEditor.Rendering.Universal; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.Rendering.Universal; + +class ScriptableRendererDataEditorTests +{ + const string k_TempAssetPath = "Assets/ScriptableRendererDataEditorTests"; + + UniversalRendererData m_RendererData; + string m_AssetPath; + Editor m_Editor; + + [SetUp] + public void Setup() + { + m_RendererData = ScriptableObject.CreateInstance(); + CoreUtils.EnsureFolderTreeInAssetFilePath($"{k_TempAssetPath}/test.asset"); + m_AssetPath = $"{k_TempAssetPath}/RendererData_{System.Guid.NewGuid():N}.asset"; + AssetDatabase.CreateAsset(m_RendererData, m_AssetPath); + AssetDatabase.SaveAssets(); + + // Clear undo stack to ensure clean state + Undo.ClearAll(); + } + + [TearDown] + public void TearDown() + { + // Ensure editor is destroyed before clearing undo or deleting assets + if (m_Editor != null) + { + Object.DestroyImmediate(m_Editor); + m_Editor = null; + } + + Undo.ClearAll(); + + if (m_RendererData != null) + { + AssetDatabase.DeleteAsset(m_AssetPath); + m_RendererData = null; + } + + if (AssetDatabase.IsValidFolder(k_TempAssetPath)) + AssetDatabase.DeleteAsset(k_TempAssetPath); + } + + ScriptableRendererDataEditor CreateEditor() + { + m_Editor = Editor.CreateEditor(m_RendererData); + return (ScriptableRendererDataEditor)m_Editor; + } + + [Test] + public void AddComponent_AddsRendererFeature() + { + var editor = CreateEditor(); + + Assert.AreEqual(0, m_RendererData.rendererFeatures.Count, "Renderer should start with no features"); + + editor.AddComponent(typeof(RenderObjects)); + + Assert.AreEqual(1, m_RendererData.rendererFeatures.Count, "Renderer should have one feature after adding"); + Assert.IsInstanceOf(m_RendererData.rendererFeatures[0], "Added feature should be RenderObjects"); + } + + [Test] + public void AddComponent_SetsHideFlags() + { + var editor = CreateEditor(); + + editor.AddComponent(typeof(RenderObjects)); + + var feature = m_RendererData.rendererFeatures[0]; + Assert.IsTrue((feature.hideFlags & HideFlags.HideInHierarchy) != 0, + "Added feature should have HideInHierarchy flag set"); + } + + [Test] + public void AddComponent_StoresFeatureInSameAsset() + { + var editor = CreateEditor(); + + // Verify target is persistent (required for sub-asset creation) + Assert.IsTrue(EditorUtility.IsPersistent(m_RendererData), "RendererData should be persistent"); + + editor.AddComponent(typeof(RenderObjects)); + AssetDatabase.SaveAssets(); + AssetDatabase.ImportAsset(m_AssetPath); + + // Reload the asset to get fresh references + m_RendererData = AssetDatabase.LoadAssetAtPath(m_AssetPath); + var feature = m_RendererData.rendererFeatures[0]; + + // Feature should be stored at the same asset path as the renderer data + string featurePath = AssetDatabase.GetAssetPath(feature); + Assert.AreEqual(m_AssetPath, featurePath, "Feature asset path should match renderer data path"); + + // Feature should not be the main asset (it's embedded in the renderer data) + Assert.IsFalse(AssetDatabase.IsMainAsset(feature), "Feature should not be the main asset"); + } + + [Test] + public void AddComponent_CanBeUndone() + { + var editor = CreateEditor(); + + Assert.AreEqual(0, m_RendererData.rendererFeatures.Count); + + editor.AddComponent(typeof(RenderObjects)); + Assert.AreEqual(1, m_RendererData.rendererFeatures.Count); + + Undo.PerformUndo(); + + // Reload asset to get fresh state + m_RendererData = AssetDatabase.LoadAssetAtPath(m_AssetPath); + Assert.AreEqual(0, m_RendererData.rendererFeatures.Count, "Feature count should be 0 after undo"); + } + + [Test] + public void AddComponent_CanBeRedone() + { + var editor = CreateEditor(); + + editor.AddComponent(typeof(RenderObjects)); + Assert.AreEqual(1, m_RendererData.rendererFeatures.Count); + + Undo.PerformUndo(); + m_RendererData = AssetDatabase.LoadAssetAtPath(m_AssetPath); + Assert.AreEqual(0, m_RendererData.rendererFeatures.Count); + + Undo.PerformRedo(); + m_RendererData = AssetDatabase.LoadAssetAtPath(m_AssetPath); + Assert.AreEqual(1, m_RendererData.rendererFeatures.Count, "Feature count should be 1 after redo"); + } + + [Test] + public void AddMultipleComponents_MaintainsOrder() + { + var editor = CreateEditor(); + + editor.AddComponent(typeof(RenderObjects)); + editor.AddComponent(typeof(FullScreenPassRendererFeature)); + + Assert.AreEqual(2, m_RendererData.rendererFeatures.Count); + Assert.IsInstanceOf(m_RendererData.rendererFeatures[0]); + Assert.IsInstanceOf(m_RendererData.rendererFeatures[1]); + } + + [Test] + public void NewFeatures_HaveHideInHierarchyFlag() + { + var editor = CreateEditor(); + + editor.AddComponent(typeof(RenderObjects)); + editor.AddComponent(typeof(FullScreenPassRendererFeature)); + + foreach (var feature in m_RendererData.rendererFeatures) + { + Assert.IsTrue((feature.hideFlags & HideFlags.HideInHierarchy) != 0, + $"Feature {feature.name} should have HideInHierarchy flag"); + } + } + + [Test] + public void RendererFeatureMapCount_MatchesFeatureCount() + { + var editor = CreateEditor(); + + editor.AddComponent(typeof(RenderObjects)); + editor.AddComponent(typeof(FullScreenPassRendererFeature)); + + Assert.AreEqual(m_RendererData.m_RendererFeatures.Count, m_RendererData.m_RendererFeatureMap.Count, + "Feature map count should match features count"); + } +} diff --git a/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs.meta b/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs.meta new file mode 100644 index 00000000000..4136ee561ba --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal/Tests/Editor/ScriptableRendererDataEditorTests.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cc9a0e128afcfe74d965b5c34ce187a2 \ No newline at end of file From 73032a48709c8c7eeaa4c79c4b77d53a708b83a9 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Thu, 21 May 2026 12:58:11 +0000 Subject: [PATCH 09/63] [Port] [6000.5] [UUM-142398] Fix preview generation for graphs using predefined keywords --- .../com.unity.shadergraph/Editor/Data/Graphs/ShaderKeyword.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Packages/com.unity.shadergraph/Editor/Data/Graphs/ShaderKeyword.cs b/Packages/com.unity.shadergraph/Editor/Data/Graphs/ShaderKeyword.cs index 2bc1f332194..c67fe55c569 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Graphs/ShaderKeyword.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Graphs/ShaderKeyword.cs @@ -208,6 +208,9 @@ public void AppendKeywordDeclarationStrings(ShaderStringBuilder builder) public string GetKeywordPreviewDeclarationString() { + if (keywordDefinition == KeywordDefinition.Predefined) + return string.Empty; + if (this.IsDynamic) { switch(keywordType) From 73f3c4ba8dac81be37edc5ee1a9ae95c9284d772 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Thu, 21 May 2026 12:58:11 +0000 Subject: [PATCH 10/63] [Port] [6000.5] Remove unused LiveGI urtshader that is producing a warning on vulkan --- .../PathTracing/Shaders/LiveGI.urtshader | 175 ------------------ .../PathTracing/Shaders/LiveGI.urtshader.meta | 10 - 2 files changed, 185 deletions(-) delete mode 100644 Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader delete mode 100644 Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader.meta diff --git a/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader b/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader deleted file mode 100644 index 368968dc8a0..00000000000 --- a/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader +++ /dev/null @@ -1,175 +0,0 @@ -#pragma only_renderers d3d11 vulkan metal glcore - -#define UNIFIED_RT_GROUP_SIZE_X 16 -#define UNIFIED_RT_GROUP_SIZE_Y 8 - -RWTexture2D g_Radiance; // Path tracer output -RWTexture2D g_MotionVectors; -RWTexture2D g_NormalsDepth; -RWTexture2D g_DebugOutput; - -// Input -float4x4 g_CameraToWorldMatrix; -float4 g_CameraFrustum; -float4x4 g_CameraViewProjection; -float4x4 g_PreviousViewProjection; - -uint g_SampleCount; -uint g_FrameIndex; -int g_EnableSubPixelJittering; -uint g_EnableDebug; - -#define READ_EXPOSURE_FROM_TEXTURE -#include "PathTracing.hlsl" - -UnifiedRT::Ray GeneratePinholeRay(float2 frameCoord, float2 pixelJitter, uint2 launchDim) -{ - float2 ndcCoords01 = (frameCoord + pixelJitter) / float2(launchDim); - float3 viewDirection = float3( - lerp(g_CameraFrustum.x, g_CameraFrustum.y, ndcCoords01.x), - lerp(g_CameraFrustum.z, g_CameraFrustum.w, ndcCoords01.y), - -1.0); - - viewDirection = normalize(viewDirection); - - // Rotate the ray from view space to world space. - float3 rayDirection = mul((float3x3) g_CameraToWorldMatrix, viewDirection); - - UnifiedRT::Ray ray; - ray.origin = GetColumn(g_CameraToWorldMatrix, 3).xyz; // last column - ray.direction = rayDirection; - ray.tMin = 0; - ray.tMax = K_T_MAX; - - return ray; -} - -UnifiedRT::Ray GeneratePrimaryRay(float2 frameCoord, float2 pixelJitter, uint2 launchDim) -{ - return GeneratePinholeRay(frameCoord, pixelJitter, launchDim); -} - -void ComputeMotionVectorAndDepth(inout PixelState pixel, float2 pixelJitter, float3 worldSpacePos) -{ - float2 frameCoord = pixel.coord + pixelJitter; - float4 projCoords = mul(g_PreviousViewProjection, float4(worldSpacePos, 1.0)); - projCoords.xyz = projCoords.xyz / projCoords.w; - projCoords.xy = (projCoords.xy * 0.5 + 0.5) * float2(pixel.launchDim); - pixel.motionVector = frameCoord - projCoords.xy; - - float4 ndc = mul(g_CameraViewProjection, float4(worldSpacePos, 1.0)); - pixel.depth = ndc.z / ndc.w; -} - -void ComputeMotionVectorAndDepth(inout PixelState pixel, float2 pixelJitter, PTHitGeom hitGeom, UnifiedRT::Ray ray, bool hit) -{ - float3 lastWorldPosition; - if (!hit) - { - float t = 10000 / dot(ray.direction, GetColumn(g_CameraToWorldMatrix, 2).xyz); - lastWorldPosition = ray.origin + t * ray.direction; - } - else - { - lastWorldPosition = hitGeom.lastWorldPosition; - pixel.normal = hitGeom.worldFaceNormal; - } - - ComputeMotionVectorAndDepth(pixel, pixelJitter, lastWorldPosition); -} - - -void TraceNewPath(UnifiedRT::DispatchInfo dispatchInfo, uint sampleIndex, inout PathTracingSampler rngState, inout PixelState pixel) -{ - UnifiedRT::RayTracingAccelStruct accelStruct = UNIFIED_RT_GET_ACCEL_STRUCT(g_SceneAccelStruct); - - float2 pixelJitter = g_EnableSubPixelJittering ? rngState.GetSample2D(RAND_DIM_AA) - 0.5 : 0.0; - - PathIterator pathIter; - InitPathIterator(pathIter, GeneratePrimaryRay(pixel.coord, pixelJitter, pixel.launchDim)); - - int transparencyBounce = 0; - for (int bounceIndex = 0; bounceIndex <= g_BounceCount && transparencyBounce < MAX_TRANSMISSION_BOUNCES; bounceIndex++) - { - uint traceResult = TraceBounceRayAndAddRadiance(pathIter, bounceIndex, RayMask(bounceIndex == 0), ShadowRayMask(), dispatchInfo, accelStruct, g_AccelStructInstanceList, rngState); - pixel.bounces++; - - if (bounceIndex == 0 && sampleIndex == 0) - ComputeMotionVectorAndDepth(pixel, pixelJitter, pathIter.hitGeo, pathIter.ray, pathIter.hitResult.IsValid()); - - if (traceResult == TRACE_MISS) - { - break; - } - if (traceResult == TRACE_TRANSMISSION) - { - bounceIndex--; - transparencyBounce++; - pathIter.ray.origin = pathIter.hitGeo.NextTransmissionRayOrigin(); - pathIter.throughput *= pathIter.material.transmission; - rngState.NextBounce(); - continue; - } - - if (!Scatter(pathIter, rngState)) - break; - - rngState.NextBounce(); - - } - - pixel.radiance += pathIter.radianceSample; -} - -PixelState SamplePixel(UnifiedRT::DispatchInfo dispatchInfo) -{ - uint2 launchIndex = dispatchInfo.dispatchThreadID.xy; - uint2 launchDim = dispatchInfo.dispatchDimensionsInThreads.xy; - - PixelState pixel = (PixelState) 0; - // flip the image (due to the pinhole camera) - pixel.launchIndex = uint2(launchIndex.x, launchDim.y - launchIndex.y - 1); - pixel.coord = pixel.launchIndex + float2(0.5, 0.5); - pixel.launchDim = launchDim; - - PathTracingSampler rngState; - rngState.Init(pixel.launchIndex, g_FrameIndex * g_SampleCount); - - for (uint sampleIndex = 0; sampleIndex < g_SampleCount; sampleIndex++) - { - TraceNewPath(dispatchInfo, sampleIndex, rngState, pixel); - rngState.NextPath(); - } - - pixel.radiance = pixel.radiance / g_SampleCount; - return pixel; -} - -float4 GetHeatmapColor(int rays) -{ - if (rays <= 2) - return float4(0, 1, 0, 0); - - if (rays <= 3) - return float4(0, 0, 1, 0); - - return float4(1, 0, 0, 0); -} - -void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo) -{ - float exposureMultiplier = GetCurrentExposureMultiplier(); - - PixelState pixel = SamplePixel(dispatchInfo); - g_Radiance[pixel.launchIndex] = float4(pixel.radiance, 0) * exposureMultiplier; - g_MotionVectors[pixel.launchIndex] = float4(pixel.motionVector.x, pixel.motionVector.y, 0, 0); - g_NormalsDepth[pixel.launchIndex] = float4(pixel.normal, pixel.depth); - if (g_EnableDebug) - { - float4 heat = GetHeatmapColor(pixel.bounces); - - g_Radiance[pixel.launchIndex] = heat;// * exposureMultiplier; - g_DebugOutput[pixel.launchIndex] = heat; - } - -} diff --git a/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader.meta b/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader.meta deleted file mode 100644 index 2019a8e29b6..00000000000 --- a/Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/LiveGI.urtshader.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: ceb7a31b84722d144bbeff1c8cd88769 -ScriptedImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 2 - userData: - assetBundleName: - assetBundleVariant: - script: {fileID: 11500000, guid: 42d537a8a4089e448a99fc57a06d74a9, type: 3} From 27566d90f8febffa753febaae994673d44e7d257 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Fri, 22 May 2026 14:01:08 +0000 Subject: [PATCH 11/63] [Port] [6000.5] [VFX] Avoid access of SystemInfo during compilation --- .../Expressions/VFXExpressionDecodeDepth.cs | 26 +++++++++++++++++++ .../VFXExpressionDecodeDepth.cs.meta | 2 ++ .../Collision/CollisionDepth.cs | 11 +++----- .../Implementations/Position/PositionDepth.cs | 4 +-- .../Implementations/PositionDepth.cs | 6 +---- .../Shaders/VFXCommon.hlsl | 9 +++++++ 6 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs create mode 100644 Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs.meta diff --git a/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs b/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs new file mode 100644 index 00000000000..4b8a8191e5e --- /dev/null +++ b/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs @@ -0,0 +1,26 @@ +using System; +using UnityEngine; +using UnityEngine.VFX; + +namespace UnityEditor.VFX +{ + class VFXExpressionDecodeDepth : VFXExpression + { + public VFXExpressionDecodeDepth() : this(VFXValue.Default) + { + } + + public VFXExpressionDecodeDepth(VFXExpression depth) + : base(Flags.InvalidOnCPU, new VFXExpression[] { depth }) + { + } + + public sealed override VFXExpressionOperation operation { get { return VFXExpressionOperation.None; } } + public sealed override VFXValueType valueType { get { return VFXValueType.Float; } } + + public sealed override string GetCodeString(string[] parents) + { + return string.Format("DecodeDepth({0})", parents[0]); + } + } +} diff --git a/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs.meta b/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs.meta new file mode 100644 index 00000000000..f5c43c83add --- /dev/null +++ b/Packages/com.unity.visualeffectgraph/Editor/Expressions/VFXExpressionDecodeDepth.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 4a1a658b4b2aab742951cc9c4db81618 \ No newline at end of file diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Collision/CollisionDepth.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Collision/CollisionDepth.cs index 43c04251366..3a60feae92b 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Collision/CollisionDepth.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Collision/CollisionDepth.cs @@ -116,9 +116,7 @@ protected sealed override string collisionDetection { float2 uv = projPos.xy * 0.5f + 0.5f; float depth = LOAD_TEXTURE2D_X(Camera_depthBuffer.t, uv*Camera_scaledPixelDimensions).r; - #if UNITY_REVERSED_Z - depth = 1.0f - depth; // reversed z - #endif + depth = DecodeDepth(depth); const float n = Camera_nearPlane; const float f = Camera_farPlane; @@ -154,11 +152,8 @@ protected sealed override string collisionDetection float depth10 = LOAD_TEXTURE2D_X(Camera_depthBuffer.t, depthPos10).r; float depth01 = LOAD_TEXTURE2D_X(Camera_depthBuffer.t, depthPos01).r; - - #if UNITY_REVERSED_Z - depth10 = 1.0f - depth10; - depth01 = 1.0f - depth01; - #endif + depth10 = DecodeDepth(depth10); + depth01 = DecodeDepth(depth01); float4 vPos10 = mul(ClipToView,float4(projPos10,depth10 * 2.0f - 1.0f,1.0f)); float4 vPos01 = mul(ClipToView,float4(projPos01,depth01 * 2.0f - 1.0f,1.0f)); diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Position/PositionDepth.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Position/PositionDepth.cs index 288b93e59ea..d02b9d8643c 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Position/PositionDepth.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Position/PositionDepth.cs @@ -186,9 +186,7 @@ public override string source source += @" float2 projpos = uvs * 2.0f - 1.0f; float depth = LOAD_TEXTURE2D_X(Camera_depthBuffer.t, uvs*Camera_scaledPixelDimensions).r; -#if UNITY_REVERSED_Z -depth = 1.0f - depth; // reversed z -#endif"; +depth = DecodeDepth(depth);"; if (cullMode == CullMode.FarPlane) source += @" diff --git a/Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/PositionDepth.cs b/Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/PositionDepth.cs index 4b574854397..cba040cc419 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/PositionDepth.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/PositionDepth.cs @@ -196,11 +196,7 @@ protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpressi // Get depth VFXExpression depth = new VFXExpressionExtractComponent(new VFXExpressionLoadCameraBuffer(Camera_depthBuffer, uvs), 0); - - if (SystemInfo.usesReversedZBuffer) - { - depth = VFXOperatorUtility.OneExpression[depth.valueType] - depth; - } + depth = new VFXExpressionDecodeDepth(depth); VFXExpression isAlive = VFXValue.Constant(true); diff --git a/Packages/com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl b/Packages/com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl index 228be967851..f146cde7fc0 100644 --- a/Packages/com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl +++ b/Packages/com.unity.visualeffectgraph/Shaders/VFXCommon.hlsl @@ -226,6 +226,15 @@ float4 LoadTexture(VFXSampler3D s, int4 pixelCoords) return s.t.Load(pixelCoords); } +float DecodeDepth(float depth) +{ +#if UNITY_REVERSED_Z + return 1.0f - depth; +#else + return depth; +#endif +} + float SampleSDF(VFXSampler3D s, float3 coords, float level = 0.0f) { return SampleTexture(s, coords, level).x; From 2373176716ecaef319c9ac505d8946d831bed909 Mon Sep 17 00:00:00 2001 From: Evergreen Date: Fri, 22 May 2026 14:01:08 +0000 Subject: [PATCH 12/63] [Port] [6000.5] [SRP] Fix importing samples with dependencies from the all samples tab in packman --- .../SampleDependencyImporter.cs | 492 ++++++++++++------ 1 file changed, 337 insertions(+), 155 deletions(-) diff --git a/Packages/com.unity.render-pipelines.core/Editor/SampleDependencyImportSystem/SampleDependencyImporter.cs b/Packages/com.unity.render-pipelines.core/Editor/SampleDependencyImportSystem/SampleDependencyImporter.cs index 6ae1a448d9c..4b065a63afc 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/SampleDependencyImportSystem/SampleDependencyImporter.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/SampleDependencyImportSystem/SampleDependencyImporter.cs @@ -1,6 +1,8 @@ +using System; using System.Collections.Generic; using System.IO; using UnityEditor; +using UnityEditor.PackageManager; using UnityEditor.PackageManager.UI; using UnityEngine; using UnityEngine.UIElements; @@ -60,12 +62,10 @@ VisualElement IPackageManagerExtension.CreateExtensionUI() injectingElement = new VisualElement(); injectingElement.style.display = DisplayStyle.None; - // This callback is called once the element is added to the UI, at this point we should have access to rest of the elements. injectingElement.RegisterCallback((callback) => { - //Force clear the cached elements to fetch those from the newly openned window + // Clear cached elements when panel is attached _panelRoot = null; samplesButton = null; - RefreshSampleButtons(); }); @@ -73,108 +73,299 @@ VisualElement IPackageManagerExtension.CreateExtensionUI() } Button samplesButton; + Button m_InjectedDetailsButton; + bool m_IsOnAllSamplesTab; + const string samplesButtonName = "samplesButton"; - const string sampleContainerClassName = "sampleContainer"; - const string importButtonClassName = "actionButton"; + const string samplesListContainerClassName = "sampleContainer"; + const string importButtonClassName = "actionButtonsContainer"; const string injectedButtonClassName = "importWithDependenciesButton"; internal void RefreshSampleButtons() { - if (injectingElement == null || m_PackageInfo == null || m_SampleList == null || panelRoot == null) - return; - - // Call refresh of samples and button injection when switching to the "Samples" tab. - if (samplesButton == null) + if (m_IsOnAllSamplesTab) + { + RefreshSampleButtonInDetailsView(); + } + else + { + RefreshSampleButtonInListView(); + } + } + + internal void RefreshSampleButtonInListView() + { + if (injectingElement == null || m_PackageInfo == null || m_SampleList == null || panelRoot == null) + return; + + // Hook up to the "Samples" tab button click event + if (samplesButton == null) + { + samplesButton = panelRoot.Q