From 702c623152f66d2ad0855e056ee402ef8aa9b30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 15:05:05 +0200 Subject: [PATCH 1/7] Fixed sorting criteria display bug in the draw renderers custom pass --- .../RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs index dfcb90d269a..633f0569d3c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs @@ -161,7 +161,8 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect) #endif // TODO: remove all this code when the fix for SerializedReference lands - EditorGUI.PropertyField(rect, m_SortingCriteria, Styles.sortingCriteria); + m_SortingCriteria.intValue = (int)(SortingCriteria)EditorGUI.EnumFlagsField(rect, Styles.sortingCriteria, (SortingCriteria)m_SortingCriteria.intValue); + // EditorGUI.PropertyField(rect, m_SortingCriteria, Styles.sortingCriteria); rect.y += Styles.defaultLineSpace; EditorGUI.indentLevel--; From bf6503ac7d25aaac4a662b2d9e233d763b56547e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 16:04:30 +0200 Subject: [PATCH 2/7] Fixed custom pass after post process not reading the correct color buffer --- .../Runtime/RenderPipeline/HDStringConstants.cs | 1 + .../RenderPass/CustomPass/CustomPassCommon.hlsl | 6 ++++++ .../RenderPass/CustomPass/CustomPassVolume.cs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 70a1400e68d..25503e36b38 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -379,6 +379,7 @@ static class HDShaderIDs public static readonly int _CustomDepthTexture = Shader.PropertyToID("_CustomDepthTexture"); public static readonly int _CustomColorTexture = Shader.PropertyToID("_CustomColorTexture"); public static readonly int _CustomPassInjectionPoint = Shader.PropertyToID("_CustomPassInjectionPoint"); + public static readonly int _AfterPostProcessColorBuffer = Shader.PropertyToID("_AfterPostProcessColorBuffer"); public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap"); public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl index 00f86e02957..fb5e97ceed7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl @@ -10,6 +10,10 @@ float _CustomPassInjectionPoint; float _FadeValue; +// This texture is only available in after post process and contains the result of post processing effects. +// While SampleCameraColor still returns the color pyramid without post processes +TEXTURE2D_X(_AfterPostProcessColorBuffer); + float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true) { if (uvGuards) @@ -22,6 +26,7 @@ float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true) // Also, we don't use _RTHandleScaleHistory to sample because the color pyramid bound is the actual camera color buffer which is at the resolution of the camera case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT: case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb; + case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return SAMPLE_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb; default: return SampleCameraColor(uv, lod); } } @@ -34,6 +39,7 @@ float3 CustomPassLoadCameraColor(uint2 pixelCoords, float lod) // there is no color pyramid yet for before transparent so we can't sample with mips. case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT: case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return LOAD_TEXTURE2D_X_LOD(_ColorPyramidTexture, pixelCoords, 0).rgb; + case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return LOAD_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, pixelCoords, 0).rgb; default: return LoadCameraColor(pixelCoords, lod); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs index 323b3f55b5d..c622bf946ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs @@ -88,6 +88,8 @@ internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, return false; Shader.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)injectionPoint); + if (injectionPoint == CustomPassInjectionPoint.AfterPostProcess) + Shader.SetGlobalTexture(HDShaderIDs._AfterPostProcessColorBuffer, targets.cameraColorBuffer); foreach (var pass in customPasses) { From 5c3ac9b049dc1d9374e3aa8d9693b6627db53fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 16:05:24 +0200 Subject: [PATCH 3/7] Updated changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 74ec5927688..694b3ef212e 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -702,6 +702,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed typo in the Render Pipeline Wizard under HDRP+VR - Change transparent SSR name in frame settings to avoid clipping. - Fixed fallback for ray tracing and light layers (1258837). +- Fixed Sorting Priority not displayed correctly in the DrawRenderers custom pass UI. ### Changed - Improve MIP selection for decals on Transparents From 5fe3dc8ac75e2cd9f496e1cb0745611b2f96f3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 16:05:30 +0200 Subject: [PATCH 4/7] Updated documentation --- .../Documentation~/Custom-Pass.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md index 8ed7d3db022..0df5d50f09e 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md @@ -79,7 +79,7 @@ float4 FullScreenPass(Varyings varyings) : SV_Target // Load the camera color buffer at the mip 0 if we're not at the before rendering injection point if (_CustomPassInjectionPoint != CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING) - color = float4(CustomPassSampleCameraColor(posInput.positionNDC.xy, 0), 1); + color = float4(CustomPassLoadCameraColor(varyings.positionCS.xy, 0), 1); // Add your custom pass code here @@ -98,6 +98,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your | **Sampling the camera color with lods is only available in after and before post process passes**. Calling `CustomPassSampleCameraColor` at before rendering will only return black. | | **DrawRenderers Pass chained with FullScreen Pass**: In multi-pass setups where you draw objects in the camera color buffer and then read it from a fullscreen custom pass, you'll not see the objects you've drawn in the passes before your fullscreen pass (unless you are in Before Transparent). | | **MSAA**: When dealing with MSAA, you must check that the `Fetch color buffer` boolean is correctly setup because it will determine whether or not you'll be able to fetch the color buffer in this pass or not. | +| **Before Pre-Refraction and After post-process**: on these injection points the camera color buffer set as target for the fullscreen pass is the same than the one you can sample from in the shader. It means that you can't directly sample the camera color buffer if you render to the camera color buffer because of Read/Write restrictions on certain platforms. You'll have to split your effect in two passes using the custom color buffer as an intermediate buffer to avoid reading and writing simultaneously to the same buffer. | ### DrawRenderers Custom Pass From 0cfd1a93392b49e29284ee7e3244d714b8c4c519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 16:07:29 +0200 Subject: [PATCH 5/7] Fix doc --- .../Documentation~/Custom-Pass.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md index 0df5d50f09e..b82ca815705 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md @@ -98,7 +98,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your | **Sampling the camera color with lods is only available in after and before post process passes**. Calling `CustomPassSampleCameraColor` at before rendering will only return black. | | **DrawRenderers Pass chained with FullScreen Pass**: In multi-pass setups where you draw objects in the camera color buffer and then read it from a fullscreen custom pass, you'll not see the objects you've drawn in the passes before your fullscreen pass (unless you are in Before Transparent). | | **MSAA**: When dealing with MSAA, you must check that the `Fetch color buffer` boolean is correctly setup because it will determine whether or not you'll be able to fetch the color buffer in this pass or not. | -| **Before Pre-Refraction and After post-process**: on these injection points the camera color buffer set as target for the fullscreen pass is the same than the one you can sample from in the shader. It means that you can't directly sample the camera color buffer if you render to the camera color buffer because of Read/Write restrictions on certain platforms. You'll have to split your effect in two passes using the custom color buffer as an intermediate buffer to avoid reading and writing simultaneously to the same buffer. | +| **Before Pre-Refraction and After post-process**: on these injection points the camera color buffer set as target for the fullscreen pass is the same as the one you can sample from in the shader. It means that you can't directly sample the camera color buffer if you render to the camera color buffer because of Read/Write restrictions on certain platforms. You'll have to split your effect in two passes using the custom color buffer as an intermediate buffer to avoid reading and writing simultaneously to the same buffer. | ### DrawRenderers Custom Pass From 18b981e78b509872b30c3e49a5de53ff563e090b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 1 Jul 2020 16:07:35 +0200 Subject: [PATCH 6/7] Updated changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 694b3ef212e..7b15b4e0ccb 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -859,6 +859,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Renamed the debug name from SSAO to ScreenSpaceAmbientOcclusion (1254974). - Added missing tooltips and improved the UI of the aperture control (case 1254916). - Fixed wrong tooltips in the Dof Volume (case 1256641). +- The `CustomPassLoadCameraColor` and `CustomPassSampleCameraColor` functions now returns the correct color buffer when used in after post process instead of the color pyramid (which didn't had post processes). ## [7.1.1] - 2019-09-05 From 10d3042760c8e3c739bc16ae74b614b2fd38d5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 2 Jul 2020 12:51:49 +0200 Subject: [PATCH 7/7] Updated doc --- .../Documentation~/Custom-Pass.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md index b82ca815705..4c6a04bb926 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md @@ -98,7 +98,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your | **Sampling the camera color with lods is only available in after and before post process passes**. Calling `CustomPassSampleCameraColor` at before rendering will only return black. | | **DrawRenderers Pass chained with FullScreen Pass**: In multi-pass setups where you draw objects in the camera color buffer and then read it from a fullscreen custom pass, you'll not see the objects you've drawn in the passes before your fullscreen pass (unless you are in Before Transparent). | | **MSAA**: When dealing with MSAA, you must check that the `Fetch color buffer` boolean is correctly setup because it will determine whether or not you'll be able to fetch the color buffer in this pass or not. | -| **Before Pre-Refraction and After post-process**: on these injection points the camera color buffer set as target for the fullscreen pass is the same as the one you can sample from in the shader. It means that you can't directly sample the camera color buffer if you render to the camera color buffer because of Read/Write restrictions on certain platforms. You'll have to split your effect in two passes using the custom color buffer as an intermediate buffer to avoid reading and writing simultaneously to the same buffer. | +| **Before Pre-Refraction and After post-process**: On these injection points, the camera color buffer set as the target for the fullscreen pass is the same as the one you can access inside the shader. Because the camera color buffer is the target, and because of read/write restrictions on certain platforms, you cannot directly sample from the camera color buffer inside the shader. Instead, you need to split your effect into two passes and use the custom color buffer as an intermediate buffer. This avoids reading and writing simultaneously to the same buffer. | ### DrawRenderers Custom Pass