diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2501_LightLayers.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2501_LightLayers.png index 26e2809aac5..71cfc926b98 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2501_LightLayers.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2501_LightLayers.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:960be740f330486d118d7db8d572b6c21ad02e4d384bf4939f7bbff614216a9d -size 111077 +oid sha256:963e7d128be200e4380e829455010a3aa95e62acbc15d51df8c5beb2a0fa4893 +size 111135 diff --git a/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs b/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs new file mode 100644 index 00000000000..594313c44f8 --- /dev/null +++ b/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs @@ -0,0 +1,163 @@ +using System; +using Unity.Collections.LowLevel.Unsafe; + +namespace UnityEngine.Rendering +{ + /// + /// A list that stores value on a provided memory buffer. + /// + /// Usually use this to have a list on stack allocated memory. + /// + /// The type of the data stored in the list. + public unsafe struct ListBuffer + where T: unmanaged + { + private T* m_BufferPtr; + private int m_Capacity; + private int* m_CountPtr; + + /// + /// The pointer to the memory storage. + /// + internal T* BufferPtr => m_BufferPtr; + + /// + /// The number of item in the list. + /// + public int Count => *m_CountPtr; + + /// + /// The maximum number of item stored in this list. + /// + public int Capacity => m_Capacity; + + /// + /// Instantiate a new list. + /// + /// The address in memory to store the data. + /// The address in memory to store the number of item of this list.. + /// The number of that can be stored in the buffer. + public ListBuffer(T* bufferPtr, int* countPtr, int capacity) + { + m_BufferPtr = bufferPtr; + m_Capacity = capacity; + m_CountPtr = countPtr; + } + + /// + /// Get an item from the list. + /// + /// The index of the item to get. + /// A reference to the item. + /// If the index is invalid. + public ref T this[in int index] + { + get + { + if (index < 0 || index >= Count) + throw new IndexOutOfRangeException( + $"Expected a value between 0 and {Count}, but received {index}."); + return ref m_BufferPtr[index]; + } + } + + /// + /// Get an item from the list. + /// + /// Safety: index must be inside the bounds of the list. + /// + /// The index of the item to get. + /// A reference to the item. + public unsafe ref T GetUnchecked(in int index) => ref m_BufferPtr[index]; + + /// + /// Try to add a value in the list. + /// + /// A reference to the value to add. + /// + /// true when the value was added, + /// false when the value was not added because the capacity was reached. + /// + public bool TryAdd(in T value) + { + if (Count >= m_Capacity) + return false; + + m_BufferPtr[Count] = value; + ++*m_CountPtr; + return true; + } + + /// + /// Copy the content of this list into another buffer in memory. + /// + /// Safety: + /// * The destination must have enough memory to receive the copied data. + /// + /// The destination buffer of the copy operation. + /// The index of the first element that will be copied in the destination buffer. + /// The number of item to copy. + public unsafe void CopyTo(T* dstBuffer, int startDstIndex, int copyCount) + { + UnsafeUtility.MemCpy( dstBuffer + startDstIndex, m_BufferPtr, + UnsafeUtility.SizeOf() * copyCount); + } + + /// + /// Try to copy the list into another list. + /// + /// The destination of the copy. + /// + /// * true when the copy was performed. + /// * false when the copy was aborted because the destination have a capacity too small. + /// + public bool TryCopyTo(ListBuffer other) + { + if (other.Count + Count >= other.m_Capacity) + return false; + + UnsafeUtility.MemCpy( other.m_BufferPtr + other.Count, m_BufferPtr, UnsafeUtility.SizeOf() * Count); + *other.m_CountPtr += Count; + return true; + } + + /// + /// Try to copy the data from a buffer in this list. + /// + /// The pointer of the source memory to copy. + /// The number of item to copy from the source buffer. + /// + /// * true when the copy was performed. + /// * false when the copy was aborted because the capacity of this list is too small. + /// + public bool TryCopyFrom(T* srcPtr, int count) + { + if (count + Count > m_Capacity) + return false; + + UnsafeUtility.MemCpy( m_BufferPtr + Count, srcPtr, UnsafeUtility.SizeOf() * count); + *m_CountPtr += count; + return true; + } + } + + /// + /// Extensions for . + /// + public static class ListBufferExtensions + { + /// + /// Perform a quick sort on a . + /// + /// The list to sort. + /// The type of the element in the list. + public static void QuickSort(this ListBuffer self) + where T : unmanaged, IComparable + { + unsafe + { + CoreUnsafeUtils.QuickSort(self.Count, self.BufferPtr); + } + } + } +} diff --git a/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs.meta b/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs.meta new file mode 100644 index 00000000000..1259d25752c --- /dev/null +++ b/com.unity.render-pipelines.core/Runtime/Common/ListBuffer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 188d5dc897b64646b3757571725337ce +timeCreated: 1591792904 \ No newline at end of file diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs index bceac713f0d..ca3bce10cc0 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs @@ -488,7 +488,7 @@ public RTHandle Alloc( bindTextureMS = bindTextureMS, useDynamicScale = m_HardwareDynamicResRequested && useDynamicScale, memorylessMode = memoryless, - name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples) + name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples) }; } @@ -744,7 +744,7 @@ string name useDynamicScale = m_HardwareDynamicResRequested && useDynamicScale, memorylessMode = memoryless, stencilFormat = stencilFormat, - name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples) + name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples) }; } else @@ -765,7 +765,7 @@ string name bindTextureMS = bindTextureMS, useDynamicScale = m_HardwareDynamicResRequested && useDynamicScale, memorylessMode = memoryless, - name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples) + name = CoreUtils.GetRenderTargetAutoName(width, height, slices, colorFormat, name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples) }; } diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index f29fc7bf234..5453c6d95a0 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -695,6 +695,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue where manipulating the color wheels in a volume component would reset the cursor every time. - Fixed an issue where static sky lighting would not be updated for a new scene until it's reloaded at least once. - Fixed culling for decals when used in prefabs and edited in context. +- Force to rebake probe with missing baked texture. (1253367) ### Changed - Improve MIP selection for decals on Transparents @@ -845,6 +846,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Changed the default exposure mode to "Automatic (Histogram)", along with "Limit Min" to -4 and "Limit Max" to 16. - Replaced the default scene system with the builtin Scene Template feature. - Changed extensions of shader CAS include files. +- Making the planar probe atlas's format match the color buffer's format. +- Removing the planarReflectionCacheCompressed setting from asset. ## [7.1.1] - 2019-09-05 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 ed8188a7586..2917c1df213 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Asset.md @@ -36,6 +36,7 @@ When you create an HDRP Asset, open it in the Inspector to edit its properties. | **Property** | **Description** | | --------------------------------------- | ------------------------------------------------------------ | +| **Color Buffer Format** | The format of the color buffer that HDRP will use for rendering, using R16G16B16A16 instead of R11G11B10 will double the memory usage but help you to avoid banding. R16G16B16A16 is also required for [Alpha-Output](Alpha-Output.md).| | **Lit Shader Mode** | Use the drop-down to choose which mode HDRP uses for the [Lit Shader](Lit-Shader.html).
• **Forward Only**: forces HDRP to only use forward rendering for Lit Shaders.
• **Deferred Only**: forces HDRP to use deferred rendering for Lit Shaders (HDRP still renders advanced Materials using forward rendering).
• **Both**: allows the Camera to use deferred and forward rendering.

Select **Both** to allow you to switch between forward and deferred rendering for Lit Shaders at runtime per Camera. Selecting a specific mode reduces build time and Shader memory because HDRP requires less Shader variants, but it is not possible to switch from one mode to the other at runtime. | | **- Multisample Anti-aliasing Quality** | Use the drop-down to set the number of samples HDRP uses for multisample anti-aliasing (MSAA). The larger the sample count, the better the quality. Select **None** to disable MSAA.
This property is only visible when **Lit Shader Mode** is set to **Forward Only** or **Both**. | | **Motion Vectors** | Enable the checkbox to make HDRP support motion vectors. HDRP uses motion vectors for effects like screen space reflection (SSR) and motion blur. When disabled, motion blur has no effect and HDRP calculates SSR with lower quality. | @@ -123,7 +124,6 @@ Use the Reflection settings to configure the max number and resolution of the pr | **Compress Reflection Probe Cache** | Enable the checkbox to compress the [Reflection Probe](Reflection-Probe.html) cache in order to save space on disk. | | **Reflection Cubemap Size** | Use the drop-down to select the maximum resolution of individual Reflection Probe[ ](https://docs.unity3d.com/Manual/class-Cubemap.html)[cubemaps](https://docs.unity3d.com/Manual/class-Cubemap.html). | | **Probe Cache Size** | The maximum size of the Probe Cache. Defines how many Probe cube maps HDRP can save in cache. | -| **Compress Planar Reflection Probe Cache** | Enable the checkbox to compress the [Planar Reflection Probe](Planar-Reflection-Probe.html) cache in order to save space on disk. | | **Planar Reflection Atlas Size** | Use the drop-down to select the resolution of the planar probe atlas. It defines how many reflection probe you'll be able to render at once and at which resolution. | | **Max Planar Reflection On Screen** | The maximum number of planar reflections on screen at once. | | **Planar Probe Cache Size** | The maximum size of the Planer Reflection Probe cache. Defines how many Probe textures HDRP can save in cache. | diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Planar-Reflection-Probe.md b/com.unity.render-pipelines.high-definition/Documentation~/Planar-Reflection-Probe.md index 3563111cc15..f9360caf8ab 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Planar-Reflection-Probe.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Planar-Reflection-Probe.md @@ -6,6 +6,8 @@ The Planar Reflection Probe component is one of the types of [Reflection Probe]( Planar Reflection Probes share many properties with the the [built-in render pipeline Reflection Probe](), and the [HDRP cubemap Reflection Probe](Reflection-Probe.html). +Planar Reflection Probes use the same texture format than the one selected in [HDRP Asset](HDRP-Asset.md) for Color Buffer Format. + ![](Images/PlanarReflectionProbe1.png) ### General Properties @@ -83,4 +85,4 @@ You can use Scene view gizmos to visually customize specific properties. | ![](Images/ReflectionProbeGizmo1.png) | **Influence Volume bounds boundary** | Provides Scene view handles that allow you to move the boundaries of the [Influence Volume](#InfluenceVolume), which defines the area this Reflection Probe affects reflective Materials. Edits the **Box Size** or **Radius** value, depending on the **Shape** you select. | | ![](Images/ReflectionProbeGizmo2.png) | **Blend Distance boundary** | Provides Scene view handles that allows you to alter the inward distance from the **Box Size** or **Radius** at which this Planar Reflection Probe blends with other Reflection Probes. Its behavior depends on the [workflow mode](#Workflows) you are using. It scales all sides equally in **Normal** mode, scales just the side with the handle you control in **Advanced** mode. | | ![](Images/ReflectionProbeGizmo4.png) | **Mirror Position** | Changes the behavior of the Move Tool so that it alters the **Mirror** **Position** property, rather than the **Position** of the **Transform**. | -| ![](Images/ReflectionProbeGizmo5.png) | **Mirror Rotation** | Changes the behavior of the Rotate Tool so that it alters the **Mirror Rotation** property, rather than the **Rotation** of the **Transform**. | \ No newline at end of file +| ![](Images/ReflectionProbeGizmo5.png) | **Mirror Rotation** | Changes the behavior of the Rotate Tool so that it alters the **Mirror Rotation** property, rather than the **Rotation** of the **Transform**. | diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md index de3badbfb51..05afdc80ff3 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -29,6 +29,8 @@ Select your [HDRP Asset](HDRP-Asset.md). In the Inspector, go to Lighting > Cookies. In the 2D Atlas Size drop-down, select a larger cookie resolution. +From Unity 2020.2, the texture format of the color buffer selected in HDRP asset is apply to planar reflection probe. Previously planar reflection probe where always using float16 rendertarget. + ## Shadows From Unity 2020.2, it is no longer necessary to change the [HDRP Config package](HDRP-Config-Package.md) to set the [shadow filtering quality](HDRP-Asset.md#FilteringQualities) for deferred rendering. Instead, you can now change the filtering quality directly on the [HDRP Asset](HDRP-Asset.md#FilteringQualities). Note if you previously had not set the shadow filtering quality to **Medium** on the HDRP Asset, the automatic project upgrade process changes the shadow quality which means you may need to manually change it back to its original value. diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolumeControllerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolumeControllerEditor.cs index 7029a143118..5be0a330c5b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolumeControllerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolumeControllerEditor.cs @@ -11,11 +11,14 @@ public override void OnInspectorGUI() { base.OnInspectorGUI(); - if (!(GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset) - ?.currentPlatformRenderPipelineSettings.supportProbeVolume ?? false) + if (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled) { - EditorGUILayout.Space(); - EditorGUILayout.HelpBox("The current HDRP Asset does not support Probe Volume Global Illumination.", MessageType.Error, wide: true); + if (!(GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset) + ?.currentPlatformRenderPipelineSettings.supportProbeVolume ?? false) + { + EditorGUILayout.Space(); + EditorGUILayout.HelpBox("The current HDRP Asset does not support Probe Volume Global Illumination.", MessageType.Error, wide: true); + } } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs index a72d37ea47e..b454bfbc590 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs @@ -11,6 +11,7 @@ using UnityEngine.SceneManagement; using UnityEngine.Rendering.HighDefinition; using UnityEditor.Experimental.Rendering; +using UnityEngine.Experimental.Rendering; namespace UnityEditor.Rendering.HighDefinition { @@ -119,6 +120,8 @@ IScriptableBakedReflectionSystemStageNotifier handle // a. If we have to remove a baked data // b. If we have to bake a probe // 4. Bake all required probes + // a. Bake probe that were added or modified + // b. Bake probe with a missing baked texture // 5. Remove unused baked data // 6. Update probe assets @@ -135,11 +138,31 @@ IScriptableBakedReflectionSystemStageNotifier handle // == 2. == var states = stackalloc HDProbeBakingState[bakedProbeCount]; + // A list of indices of probe we may want to force to rebake, even if the hashes matches. + // Usually, add a probe when something external to its state or the world state forces the bake. + var probeForcedToBakeIndices = stackalloc int[bakedProbeCount]; + var probeForcedToBakeIndicesCount = 0; + var probeForcedToBakeIndicesList = new ListBuffer( + probeForcedToBakeIndices, + &probeForcedToBakeIndicesCount, + bakedProbeCount + ); + ComputeProbeInstanceID(bakedProbes, states); ComputeProbeSettingsHashes(bakedProbes, states); // TODO: Handle bounce dependency here ComputeProbeBakingHashes(bakedProbeCount, allProbeDependencyHash, states); + // Force to rebake probe with missing baked texture + for (var i = 0; i < bakedProbeCount; ++i) + { + var instanceId = states[i].instanceID; + var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId); + if (probe.bakedTexture != null && !probe.bakedTexture.Equals(null)) continue; + + probeForcedToBakeIndicesList.TryAdd(i); + } + CoreUnsafeUtils.QuickSort( bakedProbeCount, states ); @@ -173,7 +196,7 @@ IScriptableBakedReflectionSystemStageNotifier handle } } - if (operationCount > 0) + if (operationCount > 0 || probeForcedToBakeIndicesList.Count > 0) { // == 4. == var cubemapSize = (int)hdPipeline.currentPlatformRenderPipelineSettings.lightLoopSettings.reflectionCubemapSize; @@ -185,33 +208,66 @@ IScriptableBakedReflectionSystemStageNotifier handle 0 ); - // Render probes - for (int i = 0; i < addCount; ++i) + // Compute indices of probes to bake: added, modified probe or with a missing baked texture. + var toBakeIndices = stackalloc int[bakedProbeCount]; + var toBakeIndicesCount = 0; + var toBakeIndicesList = new ListBuffer(toBakeIndices, &toBakeIndicesCount, bakedProbeCount); + { + // Note: we will add probes from change check and baked texture missing check. + // So we can add at most 2 time the probe in the list. + var toBakeIndicesTmp = stackalloc int[bakedProbeCount * 2]; + var toBakeIndicesTmpCount = 0; + var toBakeIndicesTmpList = + new ListBuffer(toBakeIndicesTmp, &toBakeIndicesTmpCount, bakedProbeCount * 2); + + // Add the indices from the added or modified detection check + toBakeIndicesTmpList.TryCopyFrom(addIndices, addCount); + // Add the probe with missing baked texture check + probeForcedToBakeIndicesList.TryCopyTo(toBakeIndicesTmpList); + + // Sort indices + toBakeIndicesTmpList.QuickSort(); + // Add to final list without the duplicates + var lastValue = int.MaxValue; + for (var i = 0; i < toBakeIndicesTmpList.Count; ++i) + { + if (lastValue == toBakeIndicesTmpList.GetUnchecked(i)) + // Skip duplicates + continue; + + lastValue = toBakeIndicesTmpList.GetUnchecked(i); + toBakeIndicesList.TryAdd(lastValue); + } + } + + // Render probes that were added or modified + for (int i = 0; i < toBakeIndicesList.Count; ++i) { handle.EnterStage( (int)BakingStages.ReflectionProbes, string.Format("Reflection Probes | {0} jobs", addCount), - i / (float)addCount + i / (float)toBakeIndicesCount ); - var index = addIndices[i]; + var index = toBakeIndicesList.GetUnchecked(i); var instanceId = states[index].instanceID; var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId); var cacheFile = GetGICacheFileForHDProbe(states[index].probeBakingHash); - var planarRT = HDRenderUtilities.CreatePlanarProbeRenderTarget((int)probe.resolution); // Get from cache or render the probe if (!File.Exists(cacheFile)) + { + var planarRT = HDRenderUtilities.CreatePlanarProbeRenderTarget((int)probe.resolution, (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.colorBufferFormat); RenderAndWriteToFile(probe, cacheFile, cubeRT, planarRT); - - planarRT.Release(); + planarRT.Release(); + } } cubeRT.Release(); // Copy texture from cache - for (int i = 0; i < addCount; ++i) + for (int i = 0; i < toBakeIndicesList.Count; ++i) { - var index = addIndices[i]; + var index = toBakeIndicesList.GetUnchecked(i); var instanceId = states[index].instanceID; var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId); var cacheFile = GetGICacheFileForHDProbe(states[index].probeBakingHash); @@ -235,7 +291,7 @@ IScriptableBakedReflectionSystemStageNotifier handle AssetDatabase.StartAssetEditing(); for (int i = 0; i < bakedProbeCount; ++i) { - var index = addIndices[i]; + var index = toBakeIndicesList.GetUnchecked(i); var instanceId = states[index].instanceID; var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId); var bakedTexturePath = HDBakingUtilities.GetBakedTextureFilePath(probe); @@ -246,9 +302,9 @@ IScriptableBakedReflectionSystemStageNotifier handle } // Import assets AssetDatabase.StartAssetEditing(); - for (int i = 0; i < addCount; ++i) + for (int i = 0; i < toBakeIndicesList.Count; ++i) { - var index = addIndices[i]; + var index = toBakeIndicesList.GetUnchecked(i); var instanceId = states[index].instanceID; var probe = (HDProbe)EditorUtility.InstanceIDToObject(instanceId); var bakedTexturePath = HDBakingUtilities.GetBakedTextureFilePath(probe); @@ -275,9 +331,9 @@ IScriptableBakedReflectionSystemStageNotifier handle targetBakedStates[targetI++] = m_HDProbeBakedStates[i]; } // Add new baked states - for (int i = 0; i < addCount; ++i) + for (int i = 0; i < toBakeIndicesList.Count; ++i) { - var state = states[addIndices[i]]; + var state = states[toBakeIndicesList.GetUnchecked(i)]; targetBakedStates[targetI++] = new HDProbeBakedState { instanceID = state.instanceID, @@ -330,7 +386,7 @@ public static bool BakeProbes(IEnumerable bakedProbes) foreach (var probe in bakedProbes) { var bakedTexturePath = HDBakingUtilities.GetBakedTextureFilePath(probe); - var planarRT = HDRenderUtilities.CreatePlanarProbeRenderTarget((int)probe.resolution); + var planarRT = HDRenderUtilities.CreatePlanarProbeRenderTarget((int)probe.resolution, (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.colorBufferFormat); RenderAndWriteToFile(probe, bakedTexturePath, cubeRT, planarRT); planarRT.Release(); } @@ -635,9 +691,7 @@ internal static void ImportAssetAt(HDProbe probe, string file) importer.sRGBTexture = false; importer.filterMode = FilterMode.Bilinear; importer.mipmapEnabled = false; - importer.textureCompression = hd.currentPlatformRenderPipelineSettings.lightLoopSettings.planarReflectionCacheCompressed - ? TextureImporterCompression.Compressed - : TextureImporterCompression.Uncompressed; + importer.textureCompression = TextureImporterCompression.Uncompressed; importer.textureShape = TextureImporterShape.Texture2D; importer.SaveAndReimport(); break; 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 d5aed268be2..7f5f0860b7b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs @@ -272,7 +272,6 @@ static void Drawer_SectionReflection(SerializedHDRenderPipelineAsset serialized, EditorGUILayout.Space(); - EditorGUILayout.PropertyField(serialized.renderPipelineSettings.lightLoopSettings.planarReflectionCacheCompressed, Styles.compressPlanarProbeCacheContent); EditorGUILayout.PropertyField(serialized.renderPipelineSettings.lightLoopSettings.planarReflectionAtlasSize, Styles.planarAtlasSizeContent); if (serialized.renderPipelineSettings.lightLoopSettings.planarReflectionAtlasSize.hasMultipleDifferentValues) EditorGUILayout.HelpBox(Styles.multipleDifferenteValueMessage, MessageType.Info); @@ -849,79 +848,82 @@ static void Drawer_SectionLightingUnsorted(SerializedHDRenderPipelineAsset seria EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetrics, Styles.supportVolumetricContent); - EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent); - using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportProbeVolume.boolValue)) + if (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled) { - ++EditorGUI.indentLevel; + EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent); + using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportProbeVolume.boolValue)) + { + ++EditorGUI.indentLevel; - if (serialized.renderPipelineSettings.supportProbeVolume.boolValue) - EditorGUILayout.HelpBox(Styles.probeVolumeInfo, MessageType.Warning); + if (serialized.renderPipelineSettings.supportProbeVolume.boolValue) + EditorGUILayout.HelpBox(Styles.probeVolumeInfo, MessageType.Warning); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution, Styles.probeVolumeAtlasResolution); - if (EditorGUI.EndChangeCheck()) - { - serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue = Mathf.Max(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue, 0); - } - else - { - long currentCache = HDRenderPipeline.GetApproxProbeVolumeAtlasSizeInByte(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue); - if (currentCache > HDRenderPipeline.k_MaxCacheSize) + EditorGUI.BeginChangeCheck(); + EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution, Styles.probeVolumeAtlasResolution); + if (EditorGUI.EndChangeCheck()) { - int reserved = HDRenderPipeline.GetMaxProbeVolumeAtlasSizeForWeightInByte(HDRenderPipeline.k_MaxCacheSize); - string message = string.Format(Styles.cacheErrorFormat, HDEditorUtils.HumanizeWeight(currentCache), reserved); - EditorGUILayout.HelpBox(message, MessageType.Error); + serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue = Mathf.Max(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue, 0); } else { - string message = string.Format(Styles.cacheInfoFormat, HDEditorUtils.HumanizeWeight(currentCache)); - EditorGUILayout.HelpBox(message, MessageType.Info); + long currentCache = HDRenderPipeline.GetApproxProbeVolumeAtlasSizeInByte(serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue); + if (currentCache > HDRenderPipeline.k_MaxCacheSize) + { + int reserved = HDRenderPipeline.GetMaxProbeVolumeAtlasSizeForWeightInByte(HDRenderPipeline.k_MaxCacheSize); + string message = string.Format(Styles.cacheErrorFormat, HDEditorUtils.HumanizeWeight(currentCache), reserved); + EditorGUILayout.HelpBox(message, MessageType.Error); + } + else + { + string message = string.Format(Styles.cacheInfoFormat, HDEditorUtils.HumanizeWeight(currentCache)); + EditorGUILayout.HelpBox(message, MessageType.Info); + } } - } - EditorGUI.BeginDisabledGroup(ShaderConfig.s_ProbeVolumesBilateralFilteringMode != ProbeVolumesBilateralFilteringModes.OctahedralDepth); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution, Styles.probeVolumeAtlasOctahedralDepthResolution); - if (EditorGUI.EndChangeCheck()) - { - serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue = Mathf.Max(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue, 0); - } - else if (ShaderConfig.s_ProbeVolumesBilateralFilteringMode == ProbeVolumesBilateralFilteringModes.OctahedralDepth) - { - // Only display memory allocation info if octahedral depth feature is actually enabled. Only then will memory be allocated. - long currentCache = HDRenderPipeline.GetApproxProbeVolumeOctahedralDepthAtlasSizeInByte(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue); - if (currentCache > HDRenderPipeline.k_MaxCacheSize) + EditorGUI.BeginDisabledGroup(ShaderConfig.s_ProbeVolumesBilateralFilteringMode != ProbeVolumesBilateralFilteringModes.OctahedralDepth); + EditorGUI.BeginChangeCheck(); + EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution, Styles.probeVolumeAtlasOctahedralDepthResolution); + if (EditorGUI.EndChangeCheck()) { - int reserved = HDRenderPipeline.GetMaxProbeVolumeOctahedralDepthAtlasSizeForWeightInByte(HDRenderPipeline.k_MaxCacheSize); - string message = string.Format(Styles.cacheErrorFormat, HDEditorUtils.HumanizeWeight(currentCache), reserved); - EditorGUILayout.HelpBox(message, MessageType.Error); + serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue = Mathf.Max(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue, 0); } - else + else if (ShaderConfig.s_ProbeVolumesBilateralFilteringMode == ProbeVolumesBilateralFilteringModes.OctahedralDepth) { - string message = string.Format(Styles.cacheInfoFormat, HDEditorUtils.HumanizeWeight(currentCache)); - EditorGUILayout.HelpBox(message, MessageType.Info); + // Only display memory allocation info if octahedral depth feature is actually enabled. Only then will memory be allocated. + long currentCache = HDRenderPipeline.GetApproxProbeVolumeOctahedralDepthAtlasSizeInByte(serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue); + if (currentCache > HDRenderPipeline.k_MaxCacheSize) + { + int reserved = HDRenderPipeline.GetMaxProbeVolumeOctahedralDepthAtlasSizeForWeightInByte(HDRenderPipeline.k_MaxCacheSize); + string message = string.Format(Styles.cacheErrorFormat, HDEditorUtils.HumanizeWeight(currentCache), reserved); + EditorGUILayout.HelpBox(message, MessageType.Error); + } + else + { + string message = string.Format(Styles.cacheInfoFormat, HDEditorUtils.HumanizeWeight(currentCache)); + EditorGUILayout.HelpBox(message, MessageType.Info); + } } - } - EditorGUI.EndDisabledGroup(); + EditorGUI.EndDisabledGroup(); - if (serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue <= 0) - { - // Detected legacy probe volume atlas (atlasResolution did not exist. Was explicitly defined by atlasWidth, atlasHeight, atlasDepth). - // Initialize with default values. - // TODO: (Nick) This can be removed in release. It's currently here to reduce user pain on internal projects actively using this WIP tech. - serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue = GlobalProbeVolumeSettings.@default.atlasResolution; - } + if (serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue <= 0) + { + // Detected legacy probe volume atlas (atlasResolution did not exist. Was explicitly defined by atlasWidth, atlasHeight, atlasDepth). + // Initialize with default values. + // TODO: (Nick) This can be removed in release. It's currently here to reduce user pain on internal projects actively using this WIP tech. + serialized.renderPipelineSettings.probeVolumeSettings.atlasResolution.intValue = GlobalProbeVolumeSettings.@default.atlasResolution; + } - if (serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue <= 0) - { - // Detected legacy probe volume atlas (atlasOctahedralDepthResolution did not exist. Was explicitly defined by atlasWidth, atlasHeight, atlasDepth). - // Initialize with default values. - // TODO: (Nick) This can be removed in release. It's currently here to reduce user pain on internal projects actively using this WIP tech. - serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue = GlobalProbeVolumeSettings.@default.atlasOctahedralDepthResolution; - } + if (serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue <= 0) + { + // Detected legacy probe volume atlas (atlasOctahedralDepthResolution did not exist. Was explicitly defined by atlasWidth, atlasHeight, atlasDepth). + // Initialize with default values. + // TODO: (Nick) This can be removed in release. It's currently here to reduce user pain on internal projects actively using this WIP tech. + serialized.renderPipelineSettings.probeVolumeSettings.atlasOctahedralDepthResolution.intValue = GlobalProbeVolumeSettings.@default.atlasOctahedralDepthResolution; + } - --EditorGUI.indentLevel; - } + --EditorGUI.indentLevel; + } + } // s_ProbeVolumesEvaluationMode EditorGUILayout.Space(); //to separate with following sub sections } @@ -1017,7 +1019,8 @@ static void SupportedSettingsInfoSection(SerializedHDRenderPipelineAsset seriali AppendSupport(builder, serialized.renderPipelineSettings.supportTransparentDepthPrepass, Styles.supportTransparentDepthPrepass); AppendSupport(builder, serialized.renderPipelineSettings.supportTransparentDepthPostpass, Styles.supportTransparentDepthPostpass); AppendSupport(builder, serialized.renderPipelineSettings.supportRayTracing, Styles.supportRaytracing); - AppendSupport(builder, serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent); + if (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled) + AppendSupport(builder, serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent); AppendSupport(builder, serialized.renderPipelineSettings.supportedRayTracingMode, Styles.supportedRayTracingMode); EditorGUILayout.HelpBox(builder.ToString(), MessageType.Info, wide: true); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs index 3e924151579..055b2533ec8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs @@ -316,6 +316,7 @@ static void Drawer_SectionLightingSettings(SerializedFrameSettings serialized, E area.AmmendInfo(FrameSettingsField.Volumetrics, overrideable: () => hdrpSettings.supportVolumetrics); area.AmmendInfo(FrameSettingsField.ReprojectionForVolumetrics, overrideable: () => hdrpSettings.supportVolumetrics); area.AmmendInfo(FrameSettingsField.LightLayers, overrideable: () => hdrpSettings.supportLightLayers); + area.AmmendInfo(FrameSettingsField.ProbeVolume, overrideable: () => hdrpSettings.supportProbeVolume); area.AmmendInfo(FrameSettingsField.ScreenSpaceShadows, overrideable: () => hdrpSettings.hdShadowInitParams.supportScreenSpaceShadows); area.Draw(withOverride); } 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 6584196057e..344000baf94 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 @@ -15,7 +15,6 @@ class SerializedGlobalLightLoopSettings public SerializedProperty reflectionCubemapSize; public SerializedProperty reflectionCacheCompressed; public SerializedProperty planarReflectionAtlasSize; - public SerializedProperty planarReflectionCacheCompressed; public SerializedProperty skyReflectionSize; public SerializedProperty skyLightingOverrideLayerMask; public SerializedProperty supportFabricConvolution; @@ -40,7 +39,6 @@ public SerializedGlobalLightLoopSettings(SerializedProperty root) reflectionCacheCompressed = root.Find((GlobalLightLoopSettings s) => s.reflectionCacheCompressed); planarReflectionAtlasSize = root.Find((GlobalLightLoopSettings s) => s.planarReflectionAtlasSize); - planarReflectionCacheCompressed = root.Find((GlobalLightLoopSettings s) => s.planarReflectionCacheCompressed); skyReflectionSize = root.Find((GlobalLightLoopSettings s) => s.skyReflectionSize); skyLightingOverrideLayerMask = root.Find((GlobalLightLoopSettings s) => s.skyLightingOverrideLayerMask); 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 f1b66ed1403..39522c8fa87 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 @@ -158,8 +158,6 @@ public struct GlobalLightLoopSettings public CubeReflectionResolution reflectionCubemapSize; /// Enable reflection probe cache compression. public bool reflectionCacheCompressed; - /// Enable planar probe cache compression. - public bool planarReflectionCacheCompressed; /// Resolution of the sky reflection cubemap. public SkyResolution skyReflectionSize; 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 d8a69720218..337b1ab1b8c 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 @@ -333,7 +333,7 @@ public void Initialize(HDRenderPipelineAsset hdrpAsset, RenderPipelineResources reflectionProbeCache = new ReflectionProbeCache(defaultResources, iBLFilterBSDFArray, reflectionCubeSize, reflectionCubeResolution, probeCacheFormat, true); // For planar reflection we only convolve with the GGX filter, otherwise it would be too expensive - GraphicsFormat planarProbeCacheFormat = lightLoopSettings.planarReflectionCacheCompressed ? GraphicsFormat.RGB_BC6H_SFloat : GraphicsFormat.R16G16B16A16_SFloat; + GraphicsFormat planarProbeCacheFormat = (GraphicsFormat)hdrpAsset.currentPlatformRenderPipelineSettings.colorBufferFormat; int reflectionPlanarResolution = (int)lightLoopSettings.planarReflectionAtlasSize; reflectionPlanarProbeCache = new PlanarReflectionProbeCache(defaultResources, (IBLFilterGGX)iBLFilterBSDFArray[0], reflectionPlanarResolution, planarProbeCacheFormat, true); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/PlanarReflectionFiltering.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/PlanarReflectionFiltering.compute index 3674229e748..7c128f232be 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/PlanarReflectionFiltering.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/PlanarReflectionFiltering.compute @@ -56,7 +56,7 @@ CBUFFER_START(ShaderVariablesPlanarReflectionFiltering) CBUFFER_END // Output buffer of our filtering code -RW_TEXTURE2D(float4, _FilteredPlanarReflectionBuffer); +RW_TEXTURE2D(float3, _FilteredPlanarReflectionBuffer); // These angles have been experimentally computed to match the result of reflection probes. Initially this was a table dependent on angle and roughness, but given that every planar has a // finite number of LODs and those LODS have fixed roughness and the angle changes the result, but not that much. I changed it to a per LOD LUT @@ -88,7 +88,7 @@ void FilterPlanarReflection(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 if (!IntersectRayPlane(_CaptureCameraPositon, rayDirection, _ReflectionPlanePosition, _ReflectionPlaneNormal, t)) { // If there is no plane intersection, there is nothing to filter (means that is a position that cannot be reflected) - _FilteredPlanarReflectionBuffer[currentCoord] = float4(0.0, 0.0, 0.0, 1.0); + _FilteredPlanarReflectionBuffer[currentCoord] = float3(0.0, 0.0, 0.0); return; } @@ -123,11 +123,11 @@ void FilterPlanarReflection(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 const float3 integrationColor = SAMPLE_TEXTURE2D_LOD(_ReflectionColorMipChain, s_trilinear_clamp_sampler, sampleCoords, clamp(miplevel + _SourceMipIndex + mipBias, 0, _MaxMipLevels)).xyz; // Write the output ray data - _FilteredPlanarReflectionBuffer[currentCoord] = float4(integrationColor, 1.0); + _FilteredPlanarReflectionBuffer[currentCoord] = integrationColor; } // Half resolution output texture for our mip chain build. -RW_TEXTURE2D(float4, _HalfResReflectionBuffer); +RW_TEXTURE2D(float3, _HalfResReflectionBuffer); RW_TEXTURE2D(float, _HalfResDepthBuffer); [numthreads(PLANAR_REFLECTION_TILE_SIZE, PLANAR_REFLECTION_TILE_SIZE, 1)] @@ -155,7 +155,7 @@ void DownScale(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 groupThreadId } } // Normalize and output - _HalfResReflectionBuffer[currentCoord] = float4(averageColor / sumW, 1.0); + _HalfResReflectionBuffer[currentCoord] = averageColor / sumW; // We average the 4 depths and move on _HalfResDepthBuffer[currentCoord] = (LOAD_TEXTURE2D_LOD(_DepthTextureMipChain, currentCoord * 2, _SourceMipIndex).x diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs index c5ad4b6309c..0fe375a9fb0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs @@ -121,7 +121,7 @@ void InitializeProbeVolumes() if (ShaderConfig.s_ProbeVolumesEvaluationMode == ProbeVolumesEvaluationModes.Disabled) return; - m_SupportProbeVolume = asset.currentPlatformRenderPipelineSettings.supportProbeVolume; + m_SupportProbeVolume = asset.currentPlatformRenderPipelineSettings.supportProbeVolume && (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled); s_ProbeVolumeAtlasResolution = asset.currentPlatformRenderPipelineSettings.probeVolumeSettings.atlasResolution; if (GetApproxProbeVolumeAtlasSizeInByte(s_ProbeVolumeAtlasResolution) > HDRenderPipeline.k_MaxCacheSize) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbeSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbeSystem.cs index 4f17ce5df33..8d35d6e655a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbeSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbeSystem.cs @@ -3,6 +3,7 @@ using System.Linq; using Unity.Collections.LowLevel.Unsafe; using UnityEngine.Assertions; +using UnityEngine.Experimental.Rendering; namespace UnityEngine.Rendering.HighDefinition { @@ -94,7 +95,7 @@ public static Texture CreateRenderTargetForMode(HDProbe probe, ProbeSettings.Mod { case ProbeSettings.ProbeType.PlanarProbe: target = HDRenderUtilities.CreatePlanarProbeRenderTarget( - (int)probe.resolution + (int)probe.resolution, (GraphicsFormat)hd.currentPlatformRenderPipelineSettings.colorBufferFormat ); break; case ProbeSettings.ProbeType.ReflectionProbe: @@ -112,7 +113,7 @@ public static Texture CreateRenderTargetForMode(HDProbe probe, ProbeSettings.Mod { case ProbeSettings.ProbeType.PlanarProbe: target = HDRenderUtilities.CreatePlanarProbeRenderTarget( - (int)probe.resolution + (int)probe.resolution, (GraphicsFormat)hd.currentPlatformRenderPipelineSettings.colorBufferFormat ); break; case ProbeSettings.ProbeType.ReflectionProbe: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/PlanarReflectionProbeCache.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/PlanarReflectionProbeCache.cs index 1143e6db8fa..37e53ff7676 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/PlanarReflectionProbeCache.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/PlanarReflectionProbeCache.cs @@ -24,49 +24,33 @@ enum ProbeFilteringState Dictionary m_ProbeBakingState = new Dictionary(); Material m_ConvertTextureMaterial; MaterialPropertyBlock m_ConvertTextureMPB; - bool m_PerformBC6HCompression; Dictionary m_TextureHashes = new Dictionary(); int m_FrameProbeIndex; + GraphicsFormat m_ProbeFormat; public PlanarReflectionProbeCache(RenderPipelineResources defaultResources, IBLFilterGGX iblFilter, int atlasResolution, GraphicsFormat probeFormat, bool isMipmaped) { m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.blitCubeTextureFacePS); m_ConvertTextureMPB = new MaterialPropertyBlock(); - // BC6H requires CPP feature not yet available - probeFormat = GraphicsFormat.R16G16B16A16_SFloat; - - Debug.Assert(probeFormat == GraphicsFormat.RGB_BC6H_SFloat || probeFormat == GraphicsFormat.R16G16B16A16_SFloat, "Reflection Probe Cache format for HDRP can only be BC6H or FP16."); - m_ProbeSize = atlasResolution; m_TextureAtlas = new PowerOfTwoTextureAtlas(atlasResolution, 0, probeFormat, useMipMap: isMipmaped, name: "PlanarReflectionProbe Atlas"); m_IBLFilterGGX = iblFilter; - m_PerformBC6HCompression = probeFormat == GraphicsFormat.RGB_BC6H_SFloat; + m_ProbeFormat = probeFormat; } void Initialize() { if (m_ConvolutionTargetTexture == null) { - // Temporary RT used for convolution and compression - - // Note: Temporarily disabled because planar probe baking is currently disabled so we avoid allocating unused targets - // m_TempRenderTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf); - // m_TempRenderTexture.hideFlags = HideFlags.HideAndDontSave; - // m_TempRenderTexture.dimension = TextureDimension.Tex2D; - // m_TempRenderTexture.useMipMap = true; - // m_TempRenderTexture.autoGenerateMips = false; - // m_TempRenderTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionTemp", mips: true); - // m_TempRenderTexture.Create(); - - m_ConvolutionTargetTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf); + m_ConvolutionTargetTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 0, m_ProbeFormat); m_ConvolutionTargetTexture.hideFlags = HideFlags.HideAndDontSave; m_ConvolutionTargetTexture.dimension = TextureDimension.Tex2D; m_ConvolutionTargetTexture.useMipMap = true; m_ConvolutionTargetTexture.autoGenerateMips = false; m_ConvolutionTargetTexture.filterMode = FilterMode.Point; - m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true); + m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, m_ProbeFormat, "PlanarReflectionConvolution", mips: true); m_ConvolutionTargetTexture.enableRandomWrite = true; m_ConvolutionTargetTexture.Create(); @@ -111,54 +95,20 @@ void ConvertTexture(CommandBuffer cmd, Texture input, RenderTexture target) Texture ConvolveProbeTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, out Vector4 sourceScaleOffset) { - // Probes can be either Cubemaps (for baked probes) or RenderTextures (for realtime probes) Texture2D texture2D = texture as Texture2D; RenderTexture renderTexture = texture as RenderTexture; - RenderTexture convolutionSourceTexture = null; - - // Disabled code path because planar reflection probe baking is currently disabled - if (texture2D != null && false) - { - // if the size if different from the cache probe size or if the input texture format is compressed, we need to convert it - // 1) to a format for which we can generate mip maps - // 2) to the proper reflection probe cache size - var sizeMismatch = texture2D.width != m_ProbeSize || texture2D.height != m_ProbeSize; - var formatMismatch = texture2D.format != TextureFormat.RGBAHalf; // Temporary RT for convolution is always FP16 - if (formatMismatch || sizeMismatch) - { - if (sizeMismatch) - { - Debug.LogWarningFormat("Baked Planar Reflection Probe {0} does not match HDRP Planar Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize); - } - else if (texture2D.format == TextureFormat.BC6H) - { - Debug.LogWarningFormat("Baked Planar Reflection Probe {0} is compressed but the HDRP Planar Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name); - } - ConvertTexture(cmd, texture2D, m_TempRenderTexture); - } - else - cmd.CopyTexture(texture2D, 0, 0, m_TempRenderTexture, 0, 0); - - convolutionSourceTexture = m_TempRenderTexture; - } - else + if (renderTexture.dimension != TextureDimension.Tex2D) { - Debug.Assert(renderTexture != null); - if (renderTexture.dimension != TextureDimension.Tex2D) - { - Debug.LogError("Planar Realtime reflection probe should always be a 2D RenderTexture."); - sourceScaleOffset = Vector4.zero; - return null; - } - - convolutionSourceTexture = renderTexture; + Debug.LogError("Planar Realtime reflection probe should always be a 2D RenderTexture."); + sourceScaleOffset = Vector4.zero; + return null; } float scaleX = (float)texture.width / m_ConvolutionTargetTexture.width; float scaleY = (float)texture.height / m_ConvolutionTargetTexture.height; sourceScaleOffset = new Vector4(scaleX, scaleY, 0, 0); - m_IBLFilterGGX.FilterPlanarTexture(cmd, convolutionSourceTexture, ref planarTextureFilteringParameters, m_ConvolutionTargetTexture); + m_IBLFilterGGX.FilterPlanarTexture(cmd, renderTexture, ref planarTextureFilteringParameters, m_ConvolutionTargetTexture); return m_ConvolutionTargetTexture; } @@ -188,7 +138,6 @@ bool UpdatePlanarTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.P using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ConvolvePlanarReflectionProbe))) { - // For now baking is done directly but will be time sliced in the future. Just preparing the code here. m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Convolving; Vector4 sourceScaleOffset; @@ -196,26 +145,19 @@ bool UpdatePlanarTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.P if (convolvedTexture == null) return false; - if (m_PerformBC6HCompression) + if (m_TextureAtlas.IsCached(out scaleOffset, texture)) { - throw new NotImplementedException("BC6H Support not implemented for PlanarReflectionProbeCache"); + success = m_TextureAtlas.UpdateTexture(cmd, texture, convolvedTexture, ref scaleOffset, sourceScaleOffset); } else { - if (m_TextureAtlas.IsCached(out scaleOffset, texture)) - { - success = m_TextureAtlas.UpdateTexture(cmd, texture, convolvedTexture, ref scaleOffset, sourceScaleOffset); - } - else - { - // Reserve space for the rendertarget and then blit the result of the convolution at this - // location, we don't use the UpdateTexture because it will keep the reference to the - // temporary target used to convolve the result of the probe rendering. - if (!m_TextureAtlas.AllocateTextureWithoutBlit(texture, texture.width, texture.height, ref scaleOffset)) - return false; - m_TextureAtlas.BlitTexture(cmd, scaleOffset, convolvedTexture, sourceScaleOffset); - success = true; - } + // Reserve space for the rendertarget and then blit the result of the convolution at this + // location, we don't use the UpdateTexture because it will keep the reference to the + // temporary target used to convolve the result of the probe rendering. + if (!m_TextureAtlas.AllocateTextureWithoutBlit(texture, texture.width, texture.height, ref scaleOffset)) + return false; + m_TextureAtlas.BlitTexture(cmd, scaleOffset, convolvedTexture, sourceScaleOffset); + success = true; } m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Ready; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs index 54dbc40af2b..c163d23e6d9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs @@ -195,13 +195,14 @@ void CheckIntermediateTexturesSize(int texWidth, int texHeight) // If the first texture is not the right size if (m_PlanarReflectionFilterTex0 == null || m_PlanarReflectionFilterTex0.rt.width < texWidth) { + var hdPipeline = (HDRenderPipeline)RenderPipelineManager.currentPipeline; // We re-allocate them all RTHandles.Release(m_PlanarReflectionFilterTex0); RTHandles.Release(m_PlanarReflectionFilterTex1); RTHandles.Release(m_PlanarReflectionFilterDepthTex0); RTHandles.Release(m_PlanarReflectionFilterDepthTex1); - m_PlanarReflectionFilterTex0 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: true, name: "PlanarReflectionTextureIntermediate0"); - m_PlanarReflectionFilterTex1 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: false, name: "PlanarReflectionTextureIntermediate1"); + m_PlanarReflectionFilterTex0 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.colorBufferFormat, enableRandomWrite: true, useDynamicScale: false, useMipMap: true, name: "PlanarReflectionTextureIntermediate0"); + m_PlanarReflectionFilterTex1 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.colorBufferFormat, enableRandomWrite: true, useDynamicScale: false, useMipMap: false, name: "PlanarReflectionTextureIntermediate1"); m_PlanarReflectionFilterDepthTex0 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: true, name: "PlanarReflectionTextureIntermediateDepth0"); m_PlanarReflectionFilterDepthTex1 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: false, name: "PlanarReflectionTextureIntermediateDepth1"); } @@ -212,7 +213,7 @@ void BuildColorAndDepthMipChain(CommandBuffer cmd, RenderTexture sourceColor, Re int currentTexWidth = sourceColor.width; int currentTexHeight = sourceColor.height; - // The first color level can be copied straight away in the mip chain, nothing special to be done + // The first color level can be copied straight away in the mip chain. Unfortunately due to a format incompatibility, we have to go through a compute shader copy. cmd.CopyTexture(sourceColor, 0, 0, 0, 0, sourceColor.width, sourceColor.height, m_PlanarReflectionFilterTex0, 0, 0, 0, 0); // For depth it is a bit trickier, we want to convert the depth from oblique space to non-oblique space due to the poor interpolation properties of the oblique matrix diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/ffx_a.hlsl b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/ffx_a.hlsl index 423873fb3d6..834f8034661 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/ffx_a.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/ffx_a.hlsl @@ -255,23 +255,24 @@ // //============================================================================================================================== #if defined(A_GLSL) && defined(A_GPU) + // Unity preprocessor complain about #extension #ifndef A_SKIP_EXT #ifdef A_HALF - #extension GL_EXT_shader_16bit_storage:require - #extension GL_EXT_shader_explicit_arithmetic_types:require + //#extension GL_EXT_shader_16bit_storage:require + //#extension GL_EXT_shader_explicit_arithmetic_types:require #endif //------------------------------------------------------------------------------------------------------------------------------ #ifdef A_LONG - #extension GL_ARB_gpu_shader_int64:require + //#extension GL_ARB_gpu_shader_int64:require // TODO: Fixme to more portable extension!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - #extension GL_NV_shader_atomic_int64:require + //#extension GL_NV_shader_atomic_int64:require #endif //------------------------------------------------------------------------------------------------------------------------------ #ifdef A_WAVE - #extension GL_KHR_shader_subgroup_arithmetic:require - #extension GL_KHR_shader_subgroup_ballot:require - #extension GL_KHR_shader_subgroup_quad:require - #extension GL_KHR_shader_subgroup_shuffle:require + //#extension GL_KHR_shader_subgroup_arithmetic:require + //#extension GL_KHR_shader_subgroup_ballot:require + //#extension GL_KHR_shader_subgroup_quad:require + //#extension GL_KHR_shader_subgroup_shuffle:require #endif #endif //============================================================================================================================== diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index fe64cf971a4..3176692aa34 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1843,9 +1843,10 @@ ref List renderDatas break; case ProbeSettings.ProbeType.PlanarProbe: int desiredPlanarProbeSize = (int)visibleProbe.resolution; - if (visibleProbe.realtimeTextureRTH == null || visibleProbe.realtimeTextureRTH.rt.width != desiredPlanarProbeSize) + GraphicsFormat planarFormat = (GraphicsFormat)m_Asset.currentPlatformRenderPipelineSettings.colorBufferFormat; + if (visibleProbe.realtimeTextureRTH == null || visibleProbe.realtimeTextureRTH.rt.width != desiredPlanarProbeSize || visibleProbe.realtimeTextureRTH.rt.graphicsFormat != planarFormat) { - visibleProbe.SetTexture(ProbeSettings.Mode.Realtime, HDRenderUtilities.CreatePlanarProbeRenderTarget(desiredPlanarProbeSize)); + visibleProbe.SetTexture(ProbeSettings.Mode.Realtime, HDRenderUtilities.CreatePlanarProbeRenderTarget(desiredPlanarProbeSize, planarFormat)); } if (visibleProbe.realtimeDepthTextureRTH == null || visibleProbe.realtimeDepthTextureRTH.rt.width != desiredPlanarProbeSize) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs index 8a73cbd7881..eb165f6c380 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs @@ -789,7 +789,7 @@ internal static void Sanitize(ref FrameSettings sanitizedFrameSettings, Camera c // In HD, MSAA is only supported for forward only rendering, no MSAA in deferred mode (for code complexity reasons) sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.FPTLForForwardOpaque] &= !msaa; - sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.ProbeVolume] &= renderPipelineSettings.supportProbeVolume; + sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.ProbeVolume] &= renderPipelineSettings.supportProbeVolume && (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled); } /// Aggregation is default with override of the renderer then sanitized depending on supported features of hdrpasset. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDRenderUtilities.cs b/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDRenderUtilities.cs index d4ed3874de2..3b0cec51802 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDRenderUtilities.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDRenderUtilities.cs @@ -354,9 +354,9 @@ public static RenderTexture CreateReflectionProbeRenderTarget(int cubemapSize) /// /// The size of the texture /// The texture used as planar reflection probe target - public static RenderTexture CreatePlanarProbeRenderTarget(int planarSize) + public static RenderTexture CreatePlanarProbeRenderTarget(int planarSize, GraphicsFormat format) { - return new RenderTexture(planarSize, planarSize, 1, GraphicsFormat.R16G16B16A16_SFloat) + return new RenderTexture(planarSize, planarSize, 1, format) { dimension = TextureDimension.Tex2D, enableRandomWrite = true, diff --git a/com.unity.render-pipelines.high-definition/package.json b/com.unity.render-pipelines.high-definition/package.json index 3c7d1fbc6b3..ca2a831a8cb 100644 --- a/com.unity.render-pipelines.high-definition/package.json +++ b/com.unity.render-pipelines.high-definition/package.json @@ -3,7 +3,7 @@ "description": "The High Definition Render Pipeline (HDRP) is a high-fidelity Scriptable Render Pipeline built by Unity to target modern (Compute Shader compatible) platforms. HDRP utilizes Physically-Based Lighting techniques, linear lighting, HDR lighting, and a configurable hybrid Tile/Cluster deferred/Forward lighting architecture and gives you the tools you need to create games, technical demos, animations, and more to a high graphical standard.", "version": "10.0.0-preview.1", "unity": "2020.2", - "unityRelease": "0a15", + "unityRelease": "0a16", "displayName": "High Definition RP", "dependencies": { "com.unity.render-pipelines.core": "10.0.0-preview.1", diff --git a/com.unity.template-hd/Packages/manifest.json b/com.unity.template-hd/Packages/manifest.json index 29021414235..88a17e9bcaa 100644 --- a/com.unity.template-hd/Packages/manifest.json +++ b/com.unity.template-hd/Packages/manifest.json @@ -2,10 +2,10 @@ "dependencies": { "com.unity.2d.sprite": "1.0.0", "com.unity.2d.tilemap": "1.0.0", - "com.unity.ide.rider": "2.0.3", - "com.unity.ide.visualstudio": "2.0.1", + "com.unity.ide.rider": "2.0.5", + "com.unity.ide.visualstudio": "2.0.2", "com.unity.ide.vscode": "1.2.1", - "com.unity.render-pipelines.high-definition": "10.0.0", + "com.unity.render-pipelines.high-definition": "10.0.0-preview.1", "com.unity.test-framework": "1.1.14", "com.unity.textmeshpro": "3.0.0-preview.1", "com.unity.timeline": "1.2.6", diff --git a/com.unity.template-hd/ProjectSettings/EditorBuildSettings.asset b/com.unity.template-hd/ProjectSettings/EditorBuildSettings.asset index 25297acb507..032cf063ff8 100644 --- a/com.unity.template-hd/ProjectSettings/EditorBuildSettings.asset +++ b/com.unity.template-hd/ProjectSettings/EditorBuildSettings.asset @@ -5,7 +5,10 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: + - enabled: 0 + path: + guid: 00000000000000000000000000000000 - enabled: 1 - path: Assets/Scenes/SampleScene.unity - guid: cbfe36cfddfde964d9dfce63a355d5dd + path: Assets/Scenes/TemplateScene.unity + guid: 3db1837cc97a95e4c98610966fac2b0b m_configObjects: {}