From cc2a6f1e63feca22172e813f2bbd01c0a8522339 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Fri, 9 Apr 2021 19:53:52 +0200 Subject: [PATCH 1/6] Update refraction documentation (#4101) --- .../ShaderLibrary/Refraction.hlsl | 2 +- .../Documentation~/Refraction-in-HDRP.md | 12 ++++++------ .../Editor/Material/UIBlocks/RefractionUIBlock.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Refraction.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Refraction.hlsl index 5ad1d16ee23..66059e3af34 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Refraction.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Refraction.hlsl @@ -17,7 +17,7 @@ RefractionModelResult RefractionModelSphere(real3 V, float3 positionWS, real3 no // Sphere shape model: // We approximate locally the shape of the object as sphere, that is tangent to the shape. // The sphere has a diameter of {thickness} - // The center of the sphere is at {positionWS} - {normalWS} * {thickness} + // The center of the sphere is at {positionWS} - {normalWS} * {thickness} * 0.5 // // So the light is refracted twice: in and out of the tangent sphere diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Refraction-in-HDRP.md b/com.unity.render-pipelines.high-definition/Documentation~/Refraction-in-HDRP.md index 757bfa813c2..e64aa5f7e6b 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Refraction-in-HDRP.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Refraction-in-HDRP.md @@ -58,7 +58,7 @@ This means that, if screen space refraction does not return information for a pi The first tier of the refraction hierarchy is a screen space solution. To calculate screen space refraction, the algorithm traces a ray starting from the refractive object. It then refracts the ray according to the properties of the material. To compute the refracted ray, the algorithm assumes that the refractive object can be approximated as a simple shape ([Refraction Model](#RefractionModel)) . -The refracted ray will be then intersected against the proxy volume to find the right pixel in screen space that best approximates the result of the refracted ray. +The refracted ray will be then intersected against the closest probe proxy volume to find the pixel in screen space that best approximates the result of the refracted ray. If there is no reflection probe proxy available, HDRP will fallback to a projection at infinite. @@ -82,15 +82,15 @@ For more information on Reflection Probes, see: HDRP uses simple shapes to approximate the surface of GameObjects: - **Sphere**: Approximates the surface as a sphere. -- **Box**: Approximates the surface as an hollow box. In this case think of the thickness as being the distance between two parallel faces of the box. -- **Thin**: Approximated the surface as a box with a fixed thickness of 5cm. +- **Box**: Approximates the surface as a hollow box. In this case think of the thickness as being the distance between two parallel faces of the box. +- **Thin**: Approximates the surface as a hollow box with a fixed thickness of 5cm. ### Examples -- For a filled GameObject, use a **Sphere** Refraction Model with a thickness that is approximately the size of the GameObject that the Material is for. To set the thickness, use the **Refraction Thickness**. +- For a solid GameObject, use the **Sphere** Refraction Model with a thickness that is approximately the size of the GameObject that the Material is for. To set the thickness, use the **Refraction Thickness**. ![](Images/RefractionInHDRP1.png) -- For a hollow refractive GameObject (for example, a bubble), use a **Box** refraction Mode with a small value for thickness. To set the thickness, use the **Refraction Thickness**. +- For a hollow refractive GameObject (for example, a bubble), use the **Thin** refraction Model, or **Box** with a small thickness value. To set the thickness, use the **Refraction Thickness**. -![](Images/RefractionInHDRP2.png) + ![](Images/RefractionInHDRP2.png) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs index 83568222420..e8ecca2afe6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs @@ -16,7 +16,7 @@ internal static class Styles { public static string refractionModelText = "Refraction Model"; public static GUIContent refractionIorText = new GUIContent("Index Of Refraction", "Controls the index of refraction for this Material."); - public static GUIContent refractionThicknessText = new GUIContent("Thickness", "Controls the thickness for rough refraction."); + public static GUIContent refractionThicknessText = new GUIContent("Thickness", "Controls the thickness for rough refraction.\nFor a Sphere model, this is the diameter of the sphere."); public static GUIContent refractionThicknessMapText = new GUIContent("Thickness Map", "Specifies the Refraction Thickness Map (R) for this Material - This acts as a thickness multiplier map."); public static GUIContent refractionThicknessRemappingText = new GUIContent("Thickness Remapping", "Controls the maximum thickness for rough refraction."); public static GUIContent thicknessMapText = new GUIContent("Thickness Map", "Specifies the Thickness Map (R) for this Material - This map describes the thickness of the object. When subsurface scattering is enabled, low values allow some light to transmit through the object."); From 6c6d12cbd27d45fd2d112e945a8600a052506530 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Thu, 15 Apr 2021 17:49:15 +0200 Subject: [PATCH 2/6] Merge Hd/bugfix #4192 --- .../Vulkan/None/9800_Compositor.png | 4 +- .../OSXEditor/Metal/None/9800_Compositor.png | 4 +- .../Direct3D11/None/9800_Compositor.png | 4 +- .../Direct3D12/None/9800_Compositor.png | 4 +- .../Vulkan/None/9800_Compositor.png | 4 +- .../CHANGELOG.md | 10 ++- .../Lighting/Shadow/MicroShadowingEditor.cs | 16 +++++ .../Shadow/MicroShadowingEditor.cs.meta | 11 ++++ .../Camera/HDCameraEditor.Handlers.cs | 28 +++++--- .../RenderPipeline/Camera/HDCameraEditor.cs | 28 +++++--- .../Runtime/Debug/DebugDisplay.cs | 2 + .../Runtime/Debug/DebugDisplay.cs.hlsl | 1 + .../Runtime/RenderPipeline/Camera/HDCamera.cs | 64 +++++++++++++++++++ .../RenderPipeline/HDRenderPipeline.cs | 9 +++ .../RenderPipeline/PathTracing/PathTracing.cs | 2 +- .../RenderPass/AOV/AOVRequest.cs | 52 +++++++++++++++ .../RenderPass/AOV/AOVRequestData.cs | 39 +++++++++++ .../ShaderPass/ShaderPassForward.hlsl | 4 +- .../ShaderPass/ShaderPassForwardUnlit.hlsl | 4 +- 19 files changed, 255 insertions(+), 35 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs.meta diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/9800_Compositor.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/9800_Compositor.png index c3444fce114..9b0ae3cfb84 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/9800_Compositor.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/9800_Compositor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fae7334c0189de563adff3d2547c5eee8f750f8f0587722389615c42cfd057f8 -size 90574 +oid sha256:560f65375036eb1901a2b397609c4f2b766fe4f4a769cbbdf61fc66ca065a4f0 +size 90859 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/9800_Compositor.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/9800_Compositor.png index 4d32dde27c3..4e8c7627221 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/9800_Compositor.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/9800_Compositor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:77ab31f6262195834e8335063a62b06804476ef5bf4f41ed7ff1d721558b498b -size 89682 +oid sha256:242f316c9e40115f0d0447dd3545a7716f1fb16f852fc32b04d13b8482a22747 +size 90530 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/9800_Compositor.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/9800_Compositor.png index 882d40bac50..9914ab7cad1 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/9800_Compositor.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/9800_Compositor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b64cf2b79e284812084bcadfa8f5252860cf7d8710b5db3a18f833d1a371b4c9 -size 90576 +oid sha256:5c8a47ab2d42a002ece2727b11177144db13278f39b1b3e49fb5e8b6fc3a019d +size 90912 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/9800_Compositor.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/9800_Compositor.png index 882d40bac50..9914ab7cad1 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/9800_Compositor.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/9800_Compositor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b64cf2b79e284812084bcadfa8f5252860cf7d8710b5db3a18f833d1a371b4c9 -size 90576 +oid sha256:5c8a47ab2d42a002ece2727b11177144db13278f39b1b3e49fb5e8b6fc3a019d +size 90912 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/9800_Compositor.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/9800_Compositor.png index c3444fce114..9914ab7cad1 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/9800_Compositor.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/9800_Compositor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fae7334c0189de563adff3d2547c5eee8f750f8f0587722389615c42cfd057f8 -size 90574 +oid sha256:5c8a47ab2d42a002ece2727b11177144db13278f39b1b3e49fb5e8b6fc3a019d +size 90912 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 0a3d8668bc9..473155a8dc0 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [10.5.0] - 2020-03-15 ### Added -Added a fallback for the ray traced directional shadow in case of a transmission (case 1307870). - +- Added a fallback for the ray traced directional shadow in case of a transmission (case 1307870). +- Added an info box for micro shadow editor (case 1322830). + ### Fixed - Fixed grey screen on playstation platform when histogram exposure is enabled but the curve mapping is not used. - Fixed HDRPAsset loosing its reference to the ray tracing resources when clicking on a different quality level that doesn't have ray tracing (case 1320304). @@ -29,6 +30,10 @@ Added a fallback for the ray traced directional shadow in case of a transmission - Fixed SSS materials in planar reflections (case 1319027). - Fixed Decal's pivot edit mode 2D slider gizmo not supporting multi-edition - Fixed an error on Xbox / PS4 with SubsurfaceScattering not binding the right texture +- Fixed Decal's UV edit mode with negative UV +- Fixed issue with the color space of AOVs (case 1324759) +- Fixed issue with history buffers when using multiple AOVs (case 1323684). +- Fixed camera preview with multi selection (case 1324126). ### Changed - Reduced the maximal number of bounces for both RTGI and RTR (case 1318876). @@ -37,6 +42,7 @@ Added a fallback for the ray traced directional shadow in case of a transmission - The default LookDev volume profile is now copied and referened in the Asset folder instead of the package folder. - Changed normal used in path tracing to create a local light list from the geometric to the smooth shading one. - Assets going through the migration system are now dirtied. +- Increased path tracing max samples from 4K to 16K (case 1327729). ## [10.4.0] - 2020-01-26 diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs new file mode 100644 index 00000000000..2a499e83914 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs @@ -0,0 +1,16 @@ +using UnityEngine.Rendering.HighDefinition; + +namespace UnityEditor.Rendering.HighDefinition +{ + [VolumeComponentEditor(typeof(MicroShadowing))] + sealed class MicroShadowingEditor : VolumeComponentEditor + { + static public readonly string k_DirectionnalWarning = "Micro Shadows only works with directional Lights"; + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + EditorGUILayout.HelpBox(k_DirectionnalWarning, MessageType.Info); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs.meta new file mode 100644 index 00000000000..47292dbeae0 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/Shadow/MicroShadowingEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: faceeca3ea8e9664bbd1485f9966da7a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.Handlers.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.Handlers.cs index 2be99125948..db52abd15b3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.Handlers.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.Handlers.cs @@ -28,20 +28,32 @@ void OnOverlayGUI(Object target, SceneView sceneView) Camera InitializePreviewCamera(Camera c, Vector2 previewSize) { - m_PreviewCamera.CopyFrom(c); - EditorUtility.CopySerialized(c, m_PreviewCamera); + Camera previewCamera = null; + HDAdditionalCameraData previewAdditionalCameraData = null; + for (int i = 0; i < serializedObject.targetObjects.Length; i++) + { + if (serializedObject.targetObjects[i] == c) + { + previewCamera = m_PreviewCameras[i]; + previewAdditionalCameraData = m_PreviewAdditionalCameraDatas[i]; + break; + } + } + + previewCamera.CopyFrom(c); + EditorUtility.CopySerialized(c, previewCamera); var cameraData = c.GetComponent(); - EditorUtility.CopySerialized(cameraData, m_PreviewAdditionalCameraData); + EditorUtility.CopySerialized(cameraData, previewAdditionalCameraData); // We need to explicitly reset the camera type here // It is probably a CameraType.Game, because we copied the source camera's properties. - m_PreviewCamera.cameraType = CameraType.Preview; - m_PreviewCamera.gameObject.SetActive(false); + previewCamera.cameraType = CameraType.Preview; + previewCamera.gameObject.SetActive(false); var previewTexture = GetPreviewTextureWithSize((int)previewSize.x, (int)previewSize.y); - m_PreviewCamera.targetTexture = previewTexture; - m_PreviewCamera.pixelRect = new Rect(0, 0, previewSize.x, previewSize.y); + previewCamera.targetTexture = previewTexture; + previewCamera.pixelRect = new Rect(0, 0, previewSize.x, previewSize.y); - return m_PreviewCamera; + return previewCamera; } static Type k_SceneViewOverlay_WindowFunction = Type.GetType("UnityEditor.SceneViewOverlay+WindowFunction,UnityEditor"); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.cs index bc84862c7be..91f91ccae5f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.cs @@ -14,19 +14,25 @@ partial class HDCameraEditor : Editor SerializedHDCamera m_SerializedCamera; RenderTexture m_PreviewTexture; - Camera m_PreviewCamera; - HDAdditionalCameraData m_PreviewAdditionalCameraData; + Camera[] m_PreviewCameras; + HDAdditionalCameraData[] m_PreviewAdditionalCameraDatas; void OnEnable() { m_SerializedCamera = new SerializedHDCamera(serializedObject); - m_PreviewCamera = EditorUtility.CreateGameObjectWithHideFlags("Preview Camera", HideFlags.HideAndDontSave, typeof(Camera)).GetComponent(); - m_PreviewCamera.enabled = false; - m_PreviewCamera.cameraType = CameraType.Preview; // Must be init before adding HDAdditionalCameraData - m_PreviewAdditionalCameraData = m_PreviewCamera.gameObject.AddComponent(); - // Say that we are a camera editor preview and not just a regular preview - m_PreviewAdditionalCameraData.isEditorCameraPreview = true; + var targetCount = serializedObject.targetObjects.Length; + m_PreviewCameras = new Camera[targetCount]; + m_PreviewAdditionalCameraDatas = new HDAdditionalCameraData[targetCount]; + for (int i = 0; i < targetCount; i++) + { + m_PreviewCameras[i] = EditorUtility.CreateGameObjectWithHideFlags("Preview " + serializedObject.targetObject.name, HideFlags.HideAndDontSave, typeof(Camera)).GetComponent(); + m_PreviewCameras[i].enabled = false; + m_PreviewCameras[i].cameraType = CameraType.Preview; // Must be init before adding HDAdditionalCameraData + m_PreviewAdditionalCameraDatas[i] = m_PreviewCameras[i].gameObject.AddComponent(); + // Say that we are a camera editor preview and not just a regular preview + m_PreviewAdditionalCameraDatas[i].isEditorCameraPreview = true; + } } void OnDisable() @@ -36,8 +42,10 @@ void OnDisable() m_PreviewTexture.Release(); m_PreviewTexture = null; } - DestroyImmediate(m_PreviewCamera.gameObject); - m_PreviewCamera = null; + for (int i = 0; i < serializedObject.targetObjects.Length; i++) + DestroyImmediate(m_PreviewCameras[i].gameObject); + m_PreviewCameras = null; + m_PreviewAdditionalCameraDatas = null; } public override void OnInspectorGUI() diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 21adb9e1a20..773fc510c5e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -41,6 +41,8 @@ unsafe struct ShaderVariablesDebugDisplay public int _DebugProbeVolumeMode; public Vector3 _DebugDisplayPad0; + + public int _DebugAOVOutput; } /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index f23e6568552..72cc2cb72ad 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -69,6 +69,7 @@ CBUFFER_START(ShaderVariablesDebugDisplay) int _DebugSingleShadowIndex; int _DebugProbeVolumeMode; float3 _DebugDisplayPad0; + int _DebugAOVOutput; CBUFFER_END diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 05c28cf2096..27c8925d8c1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -541,8 +541,19 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, if (numColorPyramidBuffersRequired != 0) { AllocHistoryFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain, HistoryBufferAllocatorFunction, numColorPyramidBuffersRequired); + + // Handle the AOV history buffers + var cameraHistory = GetHistoryRTHandleSystem(); + foreach (var aovRequest in aovRequests) + { + var aovHistory = GetHistoryRTHandleSystem(aovRequest); + BindHistoryRTHandleSystem(aovHistory); + AllocHistoryFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain, HistoryBufferAllocatorFunction, numColorPyramidBuffersRequired); + } + BindHistoryRTHandleSystem(cameraHistory); } + if (numVolumetricBuffersRequired != 0) { HDRenderPipeline.CreateVolumetricHistoryBuffers(this, numVolumetricBuffersRequired); @@ -604,6 +615,12 @@ internal void SetReferenceSize() { RTHandles.SetReferenceSize(actualWidth, actualHeight, msaaSamples); m_HistoryRTSystem.SwapAndSetReferenceSize(actualWidth, actualHeight, msaaSamples); + + foreach (var aovHistory in m_AOVHistoryRTSystem) + { + var historySystem = aovHistory.Value; + historySystem.SwapAndSetReferenceSize(actualWidth, actualHeight, msaaSamples); + } } // Updating RTHandle needs to be done at the beginning of rendering (not during update of HDCamera which happens in batches) @@ -691,6 +708,12 @@ internal static void ResetAllHistoryRTHandleSystems(int width, int height) if (width < currentHistorySize.x || height < currentHistorySize.y) { hdCamera.m_HistoryRTSystem.ResetReferenceSize(width, height); + + foreach (var aovHistory in hdCamera.m_AOVHistoryRTSystem) + { + var historySystem = aovHistory.Value; + historySystem.ResetReferenceSize(width, height); + } } } } @@ -977,6 +1000,10 @@ public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSyst int m_NumVolumetricBuffersAllocated = 0; float m_AmbientOcclusionResolutionScale = 0.0f; // Factor used to track if history should be reallocated for Ambient Occlusion float m_ScreenSpaceAccumulationResolutionScale = 0.0f; // Use another scale if AO & SSR don't have the same resolution + + Dictionary m_AOVHistoryRTSystem = new Dictionary(new AOVRequestDataComparer()); + + /// /// Store current algorithm which help to know if we trigger to reset history SSR Buffers. /// @@ -1426,6 +1453,13 @@ void Dispose() m_HistoryRTSystem = null; } + foreach (var aovHistory in m_AOVHistoryRTSystem) + { + var historySystem = aovHistory.Value; + historySystem.Dispose(); + } + m_AOVHistoryRTSystem.Clear(); + if (lightingSky != null && lightingSky != visualSky) lightingSky.Cleanup(); @@ -1447,6 +1481,12 @@ static RTHandle HistoryBufferAllocatorFunction(string viewName, int frameIndex, void ReleaseHistoryBuffer() { m_HistoryRTSystem.ReleaseAll(); + + foreach (var aovHistory in m_AOVHistoryRTSystem) + { + var historySystem = aovHistory.Value; + historySystem.ReleaseAll(); + } } Rect GetPixelRect() @@ -1456,6 +1496,30 @@ Rect GetPixelRect() else return new Rect(camera.pixelRect.x, camera.pixelRect.y, camera.pixelWidth, camera.pixelHeight); } + internal BufferedRTHandleSystem GetHistoryRTHandleSystem() + { + return m_HistoryRTSystem; + } + + internal void BindHistoryRTHandleSystem(BufferedRTHandleSystem historyRTSystem) + { + m_HistoryRTSystem = historyRTSystem; + } + + internal BufferedRTHandleSystem GetHistoryRTHandleSystem(AOVRequestData aovRequest) + { + if (m_AOVHistoryRTSystem.TryGetValue(aovRequest, out var aovHistory)) + { + return aovHistory; + } + else + { + var newHistory = new BufferedRTHandleSystem(); + m_AOVHistoryRTSystem.Add(aovRequest, newHistory); + return newHistory; + } + } + #endregion } } 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 0907569c3f1..2e9a44ead7c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2232,11 +2232,17 @@ ref _cullingResults probe.SetRenderData(ProbeSettings.Mode.Realtime, probeRenderData); } + // Save the camera history before rendering the AOVs + var cameraHistory = renderRequest.hdCamera.GetHistoryRTHandleSystem(); + // var aovRequestIndex = 0; foreach (var aovRequest in renderRequest.hdCamera.aovRequests) { using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.HDRenderPipelineRenderAOV))) { + // Before rendering the AOV, bind the correct history buffers + var aovHistory = renderRequest.hdCamera.GetHistoryRTHandleSystem(aovRequest); + renderRequest.hdCamera.BindHistoryRTHandleSystem(aovHistory); cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling); ExecuteRenderRequest(renderRequest, renderContext, cmd, aovRequest); cmd.SetInvertCulling(false); @@ -2246,6 +2252,9 @@ ref _cullingResults cmd.Clear(); } + // We are now going to render the main camera, so bind the correct HistoryRTHandleSystem (in case we previously render an AOV) + renderRequest.hdCamera.BindHistoryRTHandleSystem(cameraHistory); + using (new ProfilingScope(cmd, renderRequest.hdCamera.profilingSampler)) { cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs index 18d747e2237..5b849b7e455 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs @@ -31,7 +31,7 @@ public sealed class PathTracing : VolumeComponent /// Defines the maximum number of paths cast within each pixel, over time (one per frame). /// [Tooltip("Defines the maximum number of paths cast within each pixel, over time (one per frame).")] - public ClampedIntParameter maximumSamples = new ClampedIntParameter(256, 1, 4096); + public ClampedIntParameter maximumSamples = new ClampedIntParameter(256, 1, 16384); /// /// Defines the minimum number of bounces for each path, in [1, 10]. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index 97bedec4d4f..26f8a8a83c4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -176,6 +176,58 @@ public void FillDebugData(DebugDisplaySettings debug) throw new ArgumentException("Unknown DebugFullScreen"); } } + + /// + /// Equality operator. + /// + /// The AOV request to compare to. + /// True if the provided AOV request is equal to this. + public override bool Equals(object obj) + { + return obj is AOVRequest && ((AOVRequest)obj) == this; + } + + /// + /// Compares if two AOV requests have the same settings. + /// + /// The first AOVRequest to compare. + /// The second AOVRequest to compare. + /// True if the two AOV requests have the same settings. + public static bool operator==(AOVRequest a, AOVRequest b) + { + return a.m_DebugFullScreen == b.m_DebugFullScreen && + a.m_LightFilterProperty == b.m_LightFilterProperty && + a.m_LightingProperty == b.m_LightingProperty && + a.m_MaterialProperty == b.m_MaterialProperty && + a.m_OverrideRenderFormat == b.m_OverrideRenderFormat; + } + + /// + /// Compares if two AOV requests have the same settings. + /// + /// The first AOVRequest to compare. + /// The second AOVRequest to compare. + /// True if the two AOV requests have not the same settings. + public static bool operator!=(AOVRequest a, AOVRequest b) + { + return !(a == b); + } + + /// + /// Computes a hash code for the AOV Request. + /// + /// A hash code for the AOV Request. + public override int GetHashCode() + { + int hash = 17; + hash = hash * 23 + (int)m_DebugFullScreen; + hash = hash * 23 + (int)m_LightFilterProperty; + hash = hash * 23 + (int)m_LightingProperty; + hash = hash * 23 + (int)m_MaterialProperty; + hash = m_OverrideRenderFormat ? hash * 23 + 1 : hash; + + return hash; + } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs index 23e1635c372..a06fc0f5cce 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs @@ -383,5 +383,44 @@ public void SetupDebugData(ref DebugDisplaySettings debugDisplaySettings) /// The game object of the light to be rendered. /// true when the light must be rendered, false when it should be ignored. public bool IsLightEnabled(GameObject gameObject) => m_LightFilter == null || m_LightFilter.Contains(gameObject); + + internal int GetHash() + { + int hash = m_Settings.GetHashCode(); + + if (m_LightFilter != null) + { + foreach (var obj in m_LightFilter) + { + hash += obj.GetHashCode(); + } + } + + return hash; + } + + internal bool HasSameSettings(AOVRequestData other) + { + if (m_Settings != other.m_Settings) + return false; + + if (m_LightFilter != null) + return m_LightFilter.Equals(other.m_LightFilter); + + return true; + } + } + + internal class AOVRequestDataComparer : IEqualityComparer + { + public bool Equals(AOVRequestData x, AOVRequestData y) + { + return x.HasSameSettings(y); + } + + public int GetHashCode(AOVRequestData obj) + { + return obj.GetHash(); + } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl index b4b8f76bc69..1810134ed59 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl @@ -183,8 +183,8 @@ void Frag(PackedVaryingsToPS packedInput, // TEMP! // For now, the final blit in the backbuffer performs an sRGB write - // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) + // So in the meantime we apply the inverse transform to linear data to compensate, unless we output to AOVs. + if (!needLinearToSRGB && _DebugAOVOutput == 0) result = SRGBToLinear(max(0, result)); outColor = float4(result, 1.0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl index 8627bbae2f3..6248f31d7ac 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl @@ -138,8 +138,8 @@ void Frag(PackedVaryingsToPS packedInput, // TEMP! // For now, the final blit in the backbuffer performs an sRGB write - // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) + // So in the meantime we apply the inverse transform to linear data to compensate, unless we output to AOVs. + if (!needLinearToSRGB && _DebugAOVOutput == 0) result = SRGBToLinear(max(0, result)); outResult = float4(result, 1.0); From adaa0b2c67131823393a09f1dc7760a2806ec07e Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Thu, 15 Apr 2021 18:57:51 +0200 Subject: [PATCH 3/6] Update HDRenderPipeline.cs --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 2e9a44ead7c..2f2408a577c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2440,9 +2440,9 @@ AOVRequestData aovRequest Resize(hdCamera); m_PostProcessSystem.BeginFrame(cmd, hdCamera, this); - ApplyDebugDisplaySettings(hdCamera, cmd); + ApplyDebugDisplaySettings(hdCamera, cmd, aovRequest.isValid); - if (DebugManager.instance.displayRuntimeUI + if (DebugManager.instance.displayRuntimeUI #if UNITY_EDITOR || DebugManager.instance.displayEditorUI #endif @@ -5098,7 +5098,7 @@ void UpsampleTransparent(HDCamera hdCamera, CommandBuffer cmd) } } - unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd) + unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd, bool aovOutput) { // See ShaderPassForward.hlsl: for forward shaders, if DEBUG_DISPLAY is enabled and no DebugLightingMode or DebugMipMapMod // modes have been set, lighting is automatically skipped (To avoid some crashed due to lighting RT not set on console). @@ -5182,6 +5182,8 @@ unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd) cb._DebugSingleShadowIndex = m_CurrentDebugDisplaySettings.data.lightingDebugSettings.shadowDebugUseSelection ? m_DebugSelectedLightShadowIndex : (int)m_CurrentDebugDisplaySettings.data.lightingDebugSettings.shadowMapIndex; + cb._DebugAOVOutput = aovOutput ? 1 : 0; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesDebugDisplayCB, HDShaderIDs._ShaderVariablesDebugDisplay); cmd.SetGlobalTexture(HDShaderIDs._DebugFont, defaultResources.textures.debugFontTex); From 6f3c94b67bdf6bd5dabcd7637bd3d5555040d066 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Thu, 15 Apr 2021 22:50:20 +0200 Subject: [PATCH 4/6] Update AOVRequest.cs --- .../Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index 26f8a8a83c4..7a810c3fd9b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -198,8 +198,7 @@ public override bool Equals(object obj) return a.m_DebugFullScreen == b.m_DebugFullScreen && a.m_LightFilterProperty == b.m_LightFilterProperty && a.m_LightingProperty == b.m_LightingProperty && - a.m_MaterialProperty == b.m_MaterialProperty && - a.m_OverrideRenderFormat == b.m_OverrideRenderFormat; + a.m_MaterialProperty == b.m_MaterialProperty; } /// @@ -224,7 +223,6 @@ public override int GetHashCode() hash = hash * 23 + (int)m_LightFilterProperty; hash = hash * 23 + (int)m_LightingProperty; hash = hash * 23 + (int)m_MaterialProperty; - hash = m_OverrideRenderFormat ? hash * 23 + 1 : hash; return hash; } From 7f5369e8c6e22fb7e2a7b562d1bdd2c480d1d24f Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Wed, 21 Apr 2021 08:57:42 +0200 Subject: [PATCH 5/6] try to fix alignment issue for metal --- .../Runtime/Debug/DebugDisplay.cs | 4 ++-- .../Runtime/Debug/DebugDisplay.cs.hlsl | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 773fc510c5e..88ac3fd2209 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -40,9 +40,9 @@ unsafe struct ShaderVariablesDebugDisplay public int _DebugSingleShadowIndex; public int _DebugProbeVolumeMode; - public Vector3 _DebugDisplayPad0; - public int _DebugAOVOutput; + public int _DebugDisplayPad0; + public int _DebugDisplayPad1; } /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index 72cc2cb72ad..01f7a9a59ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -68,8 +68,9 @@ CBUFFER_START(ShaderVariablesDebugDisplay) float _MatcapViewScale; int _DebugSingleShadowIndex; int _DebugProbeVolumeMode; - float3 _DebugDisplayPad0; int _DebugAOVOutput; + int _DebugDisplayPad0; + int _DebugDisplayPad1; CBUFFER_END From d885e5857673e1dc4be774bf663b2b66aed6fa3e Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Thu, 22 Apr 2021 00:45:53 +0200 Subject: [PATCH 6/6] Update 4053_TAA-FP16Alpha.png --- .../Linear/OSXEditor/Metal/None/4053_TAA-FP16Alpha.png | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4053_TAA-FP16Alpha.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4053_TAA-FP16Alpha.png index e6e200ccc6d..6b1bfea837e 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4053_TAA-FP16Alpha.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4053_TAA-FP16Alpha.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0b38360822081cc34867c062e1dbd7c5c2d09929c100698df2c2122151851c2b -size 338305 +oid sha256:732028a3a8fcc1e5128fd171fb976d3520418313cef486d5bd8dad399246f671 +size 316723