From c38c4d5b82fd69c2b5a91df8838e07c116497f2b Mon Sep 17 00:00:00 2001 From: Anis Date: Thu, 16 Jul 2020 16:35:23 +0200 Subject: [PATCH 1/3] - Fixed the multiplier of the environement lights being overriden with a wrong value for ray tracing (1260311). - Fixed the first ray tracing frame not having the light cluster being set up properly (1260311). --- .../CHANGELOG.md | 2 ++ .../RenderPipeline/HDRenderPipelineUI.Skin.cs | 1 + .../RenderPipeline/HDRenderPipelineUI.cs | 5 ++++ .../SerializedGlobalLightLoopSettings.cs | 2 ++ .../LightLoop/GlobalLightLoopSettings.cs | 3 +++ .../Runtime/Lighting/LightLoop/LightLoop.cs | 1 + .../Raytracing/HDRaytracingLightCluster.cs | 24 +++++++++---------- .../RenderPipeline/Raytracing/LightCluster.cs | 6 ----- .../Deferred/RaytracingDeferred.compute | 4 ++-- .../Shaders/RaytracingLightLoop.hlsl | 1 - 10 files changed, 27 insertions(+), 22 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index f65a221d12d..37240774111 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -731,6 +731,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed path-traced subsurface scattering mixing with diffuse and specular BRDFs (1250601). - Fixed custom pass re-ordering issues. - Improved robustness of normal mapping when scale is 0, and mapping is extreme (normals in or below the tangent plane). +- Fixed the multiplier of the environement lights being overriden with a wrong value for ray tracing (1260311). ### Changed - Improve MIP selection for decals on Transparents @@ -892,6 +893,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue with quality setting foldouts not opening when clicking on them (1253088). - Shutter speed can now be changed by dragging the mouse over the UI label (case 1245007). - Remove the 'Point Cube Size' for cookie, use the Cubemap size directly. +- Fixed the first ray tracing frame not having the light cluster being set up properly (1260311). ## [7.1.1] - 2019-09-05 diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs index fbe26589dc7..4591cd5cf67 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs @@ -170,6 +170,7 @@ public class GeneralSection public static readonly GUIContent maxAreaContent = EditorGUIUtility.TrTextContent("Maximum Area on Screen", "Sets the maximum number of area Lights HDRP can handle on screen at once."); public static readonly GUIContent maxEnvContent = EditorGUIUtility.TrTextContent("Maximum Reflection Probes on Screen", "Sets the maximum number of Planar and Reflection Probes HDRP can handle on screen at once."); public static readonly GUIContent maxDecalContent = EditorGUIUtility.TrTextContent("Maximum Clustered Decals on Screen", "Sets the maximum number of decals that can affect transparent GameObjects on screen."); + public static readonly GUIContent maxLightPerCellContent = EditorGUIUtility.TrTextContent("Maximum Lights per Cell (Ray Tracing)", "Sets the maximum number of lights HDRP can handle in each cell of the ray tracing light cluster."); public static readonly GUIContent resolutionContent = EditorGUIUtility.TrTextContent("Resolution", "Specifies the resolution of the shadow Atlas."); public static readonly GUIContent cachedShadowAtlasResolution = EditorGUIUtility.TrTextContent("Cached Shadow Atlas Resolution", "Specifies the resolution of the shadow Atlas that contains the cached shadow maps."); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs index b9c0361d084..3fee70ab462 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs @@ -473,6 +473,11 @@ static void Drawer_SectionLightLoop(SerializedHDRenderPipelineAsset serialized, EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen, Styles.maxAreaContent); if (EditorGUI.EndChangeCheck()) serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen.intValue = Mathf.Clamp(serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen.intValue, 1, HDRenderPipeline.k_MaxAreaLightsOnScreen); + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell, Styles.maxLightPerCellContent); + if (EditorGUI.EndChangeCheck()) + serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell.intValue = Mathf.Clamp(serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell.intValue, 1, HDRenderPipeline.k_MaxLightsPerClusterCell); } static void Drawer_SectionDynamicResolutionSettings(SerializedHDRenderPipelineAsset serialized, Editor owner) diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs index 28ac5734030..32694a101e0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs @@ -27,6 +27,7 @@ class SerializedGlobalLightLoopSettings public SerializedProperty maxEnvLightsOnScreen; public SerializedProperty maxDecalsOnScreen; public SerializedProperty maxPlanarReflectionOnScreen; + public SerializedProperty maxLightsPerClusterCell; public SerializedGlobalLightLoopSettings(SerializedProperty root) { @@ -56,6 +57,7 @@ public SerializedGlobalLightLoopSettings(SerializedProperty root) maxEnvLightsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxEnvLightsOnScreen); maxDecalsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxDecalsOnScreen); maxPlanarReflectionOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxPlanarReflectionOnScreen); + maxLightsPerClusterCell = root.Find((GlobalLightLoopSettings s) => s.maxLightsPerClusterCell); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs index a644fae0248..2324e7d6c3d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs @@ -134,6 +134,7 @@ public struct GlobalLightLoopSettings maxEnvLightsOnScreen = 64, maxDecalsOnScreen = 512, maxPlanarReflectionOnScreen = 16, + maxLightsPerClusterCell = 8, }; /// Cookie atlas resolution. @@ -181,5 +182,7 @@ public struct GlobalLightLoopSettings public int maxDecalsOnScreen; /// Maximum number of planar reflections at the same time on screen. public int maxPlanarReflectionOnScreen; + /// Maximum number of lights per ray tracing light cluster cell. + public int maxLightsPerClusterCell; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 6704448b584..a2274068dd9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -265,6 +265,7 @@ public partial class HDRenderPipeline internal const int k_MaxDecalsOnScreen = 2048; internal const int k_MaxLightsOnScreen = k_MaxDirectionalLightsOnScreen + k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen + k_MaxEnvLightsOnScreen; internal const int k_MaxEnvLightsOnScreen = 1024; + internal const int k_MaxLightsPerClusterCell = 24; internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f; #if UNITY_SWITCH diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs index 3f2bf953156..1a85efe29e7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs @@ -58,7 +58,11 @@ internal class HDRaytracingLightCluster public static readonly int _ClusterCenterPosition = Shader.PropertyToID("_ClusterCenterPosition"); public static readonly int _ClusterDimension = Shader.PropertyToID("_ClusterDimension"); - // Temporary variables + // Temporary variables + // This value is now fixed for every HDRP asset + int m_NumLightsPerCell = 0; + + // These values are overriden for every light cluster that is built Vector3 minClusterPos = new Vector3(0.0f, 0.0f, 0.0f); Vector3 maxClusterPos = new Vector3(0.0f, 0.0f, 0.0f); Vector3 clusterCellSize = new Vector3(0.0f, 0.0f, 0.0f); @@ -68,7 +72,6 @@ internal class HDRaytracingLightCluster int areaLightCount = 0; int envLightCount = 0; int totalLightCount = 0; - int numLightsPerCell = 0; Bounds bounds = new Bounds(); Vector3 minBounds = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 maxBounds = new Vector3(-float.MaxValue, -float.MaxValue, -float.MaxValue); @@ -98,6 +101,11 @@ public void Initialize(HDRenderPipeline renderPipeline) m_LightDataGPUArray = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData))); m_EnvLightDataGPUArray = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData))); + // Allocate the light cluster buffer at the right size + m_NumLightsPerCell = renderPipeline.asset.currentPlatformRenderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell; + int bufferSize = 64 * 64 * 32 * (renderPipeline.asset.currentPlatformRenderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell + 4); + ResizeClusterBuffer(bufferSize); + // Create the material required for debug m_DebugMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineRayTracingResources.lightClusterDebugS); } @@ -434,16 +442,6 @@ void BuildLightCluster(HDCamera hdCamera, CommandBuffer cmd) { using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingBuildCluster))) { - var lightClusterSettings = hdCamera.volumeStack.GetComponent(); - numLightsPerCell = lightClusterSettings.maxNumLightsPercell.value; - - // Make sure the Cluster buffer has the right size - int bufferSize = 64 * 64 * 32 * (numLightsPerCell + 4); - if (m_LightCluster.count != bufferSize) - { - ResizeClusterBuffer(bufferSize); - } - // Grab the kernel ComputeShader lightClusterCS = m_RenderPipelineRayTracingResources.lightClusterBuildCS; int lightClusterKernel = lightClusterCS.FindKernel(m_LightClusterKernelName); @@ -691,7 +689,7 @@ public int GetEnvLightCount() public int GetLightPerCellCount() { - return numLightsPerCell; + return m_NumLightsPerCell; } void InvalidateCluster() diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/LightCluster.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/LightCluster.cs index bd5c5bd63b6..81ec4d72ab2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/LightCluster.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/LightCluster.cs @@ -8,12 +8,6 @@ namespace UnityEngine.Rendering.HighDefinition [Serializable, VolumeComponentMenu("Ray Tracing/Light Cluster (Preview)")] public sealed class LightCluster : VolumeComponent { - /// - /// Controls the maximal number lights in a cell. - /// - [Tooltip("Controls the maximal number lights in a cell.")] - public ClampedIntParameter maxNumLightsPercell = new ClampedIntParameter(10, 0, 24); - /// /// Controls the range of the cluster around the camera. /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute index 9e77ffee38b..d493f5a3758 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute @@ -93,7 +93,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro // Evaluate the complete lighting LightLoopOutput lightLoopOutput; - LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput); + LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 1.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput); // Alias float3 diffuseLighting = lightLoopOutput.diffuseLighting; @@ -183,7 +183,7 @@ void RaytracingDiffuseDeferred(uint3 dispatchThreadId : SV_DispatchThreadID, uin // Evaluate lighting LightLoopOutput lightLoopOutput; - LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput); + LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, 0.0, 1.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput); // Alias float3 diffuseLighting = lightLoopOutput.diffuseLighting; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl index ee4571c145f..745d5075edc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl @@ -119,7 +119,6 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS #else EnvLightData envLightData = _EnvLightDatasRT[envLightIdx]; #endif - envLightData.multiplier = _EnvLightDatas[envLightIdx].multiplier; if (reflectionHierarchyWeight < 1.0) { From 5695a7d0e740d7ec05235dd5d6321767a82e6dc3 Mon Sep 17 00:00:00 2001 From: Lewis Jordan Date: Thu, 16 Jul 2020 15:51:21 +0100 Subject: [PATCH 2/3] Added docs. --- .../Documentation~/HDRP-Asset.md | 11 ++++++----- .../Documentation~/Ray-Tracing-Light-Cluster.md | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md index 312dcabc21f..0b8aac3b0e2 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md @@ -183,11 +183,12 @@ The PCF algorithm applies a fixed size blur. PCSS applies a different blur size Use these settings to enable or disable settings relating to lighting in HDRP. -| **Property** | **Description** | -| --------------------------------- | ------------------------------------------------------------ | -| **Maximum Directional On Screen** | The maximum number of Directional Lights HDRP can manage on screen at once. | -| **Maximum Punctual On Screen** | The maximum number of [Point and Spot Lights](Glossary.html#PunctualLight) HDRP can manage on screen at once. | -| **Maximum Area On Screen** | The maximum number of area Lights HDRP can manage on screen at once. | +| **Property** | **Description** | +| ----------------------------------------- | ------------------------------------------------------------ | +| **Maximum Directional On Screen** | The maximum number of Directional Lights HDRP can manage on screen at once. | +| **Maximum Punctual On Screen** | The maximum number of [Point and Spot Lights](Glossary.html#PunctualLight) HDRP can manage on screen at once. | +| **Maximum Area On Screen** | The maximum number of area Lights HDRP can manage on screen at once. | +| **Maximum Lights Per Cell (Ray Tracing)** | Sets the maximum number of Lights that an individual grid cell in a [Light Cluster](Ray-Tracing-Light-Cluster.md) can store. | ## Material diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md index dcccec16d01..4a777ff4623 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md @@ -16,8 +16,7 @@ For ray tracing, HDRP builds an axis-aligned grid which, in each cell, stores th ## Properties -| **Property** | **Description** | -| --------------------------- | ------------------------------------------------------------ | -| **Maximum Lights Per Cell** | Sets the maximum number of Lights that an individual cell can store. | -| **Camera Cluster Range** | Sets the range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. | +| **Property** | **Description** | +| ------------------------ | ------------------------------------------------------------ | +| **Camera Cluster Range** | Sets the range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. | From 520ab170326d5cfa8ede84af7eb347c958711013 Mon Sep 17 00:00:00 2001 From: Lewis Jordan Date: Thu, 16 Jul 2020 15:52:39 +0100 Subject: [PATCH 3/3] Update property format in doc entries --- .../Documentation~/HDRP-Asset.md | 2 +- .../Documentation~/Ray-Tracing-Light-Cluster.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md index 0b8aac3b0e2..4363782dd08 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md @@ -188,7 +188,7 @@ Use these settings to enable or disable settings relating to lighting in HDRP. | **Maximum Directional On Screen** | The maximum number of Directional Lights HDRP can manage on screen at once. | | **Maximum Punctual On Screen** | The maximum number of [Point and Spot Lights](Glossary.html#PunctualLight) HDRP can manage on screen at once. | | **Maximum Area On Screen** | The maximum number of area Lights HDRP can manage on screen at once. | -| **Maximum Lights Per Cell (Ray Tracing)** | Sets the maximum number of Lights that an individual grid cell in a [Light Cluster](Ray-Tracing-Light-Cluster.md) can store. | +| **Maximum Lights Per Cell (Ray Tracing)** | The maximum number of Lights that an individual grid cell in a [Light Cluster](Ray-Tracing-Light-Cluster.md) can store. | ## Material diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md index 4a777ff4623..8d66d99172f 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Light-Cluster.md @@ -18,5 +18,5 @@ For ray tracing, HDRP builds an axis-aligned grid which, in each cell, stores th | **Property** | **Description** | | ------------------------ | ------------------------------------------------------------ | -| **Camera Cluster Range** | Sets the range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. | +| **Camera Cluster Range** | The range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. |