From f024cf5aed590776651b6f79de492b0711ad8527 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Tue, 8 Jun 2021 13:53:05 +0200 Subject: [PATCH 1/3] Added support of motion vector in custom postprocess --- .../CHANGELOG.md | 1 + .../HDRenderPipeline.PostProcess.cs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 3d8127d7b3e..18ae62e163a 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added two toggles to control occluder rejection and receiver rejection for the ray traced ambient occlusion (case 1330168). - Added the receiver motion rejection toggle to RTGI (case 1330168). - Added info box when low resolution transparency is selected, but its not enabled in the HDRP settings. This will help new users find the correct knob in the HDRP Asset. +- Added support of motion vector buffer in custom postprocess ### Fixed - Fixed Intensity Multiplier not affecting realtime global illumination. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 27d01e64e7f..1828add934d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -474,7 +474,7 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph, SetCurrentResolutionGroup(renderGraph, hdCamera, ResolutionGroup.AfterDynamicResUpscale); } - source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, m_GlobalSettings.beforeTAACustomPostProcesses, HDProfileId.CustomPostProcessBeforeTAA); + source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, motionVectors, m_GlobalSettings.beforeTAACustomPostProcesses, HDProfileId.CustomPostProcessBeforeTAA); // Temporal anti-aliasing goes first if (m_AntialiasingFS) @@ -489,7 +489,7 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph, } } - source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, m_GlobalSettings.beforePostProcessCustomPostProcesses, HDProfileId.CustomPostProcessBeforePP); + source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, motionVectors, m_GlobalSettings.beforePostProcessCustomPostProcesses, HDProfileId.CustomPostProcessBeforePP); source = DepthOfFieldPass(renderGraph, hdCamera, depthBuffer, motionVectors, depthBufferMipChain, source); @@ -508,7 +508,7 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph, source = UberPass(renderGraph, hdCamera, logLutOutput, bloomTexture, source); PushFullScreenDebugTexture(renderGraph, source, hdCamera.postProcessRTScales, FullScreenDebugMode.ColorLog); - source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, m_GlobalSettings.afterPostProcessCustomPostProcesses, HDProfileId.CustomPostProcessAfterPP); + source = CustomPostProcessPass(renderGraph, hdCamera, source, depthBuffer, normalBuffer, motionVectors, m_GlobalSettings.afterPostProcessCustomPostProcesses, HDProfileId.CustomPostProcessAfterPP); source = LensFlareDataDrivenPass(renderGraph, hdCamera, source); @@ -1251,7 +1251,7 @@ TextureHandle DynamicExposurePass(RenderGraph renderGraph, HDCamera hdCamera, Te #endregion #region Custom Post Process - void DoUserAfterOpaqueAndSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle depthBuffer, TextureHandle normalBuffer) + void DoUserAfterOpaqueAndSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectors) { if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.CustomPostProcess)) return; @@ -1259,7 +1259,7 @@ void DoUserAfterOpaqueAndSky(RenderGraph renderGraph, HDCamera hdCamera, Texture using (new RenderGraphProfilingScope(renderGraph, ProfilingSampler.Get(HDProfileId.CustomPostProcessAfterOpaqueAndSky))) { TextureHandle source = colorBuffer; - bool needBlitToColorBuffer = DoCustomPostProcess(renderGraph, hdCamera, ref source, depthBuffer, normalBuffer, m_GlobalSettings.beforeTransparentCustomPostProcesses); + bool needBlitToColorBuffer = DoCustomPostProcess(renderGraph, hdCamera, ref source, depthBuffer, normalBuffer, motionVectors, m_GlobalSettings.beforeTransparentCustomPostProcesses); if (needBlitToColorBuffer) { @@ -1278,7 +1278,7 @@ class CustomPostProcessData public CustomPostProcessVolumeComponent customPostProcess; } - bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref TextureHandle source, TextureHandle depthBuffer, TextureHandle normalBuffer, List postProcessList) + bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref TextureHandle source, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, List postProcessList) { bool customPostProcessExecuted = false; foreach (var typeString in postProcessList) @@ -1305,6 +1305,7 @@ bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref Texture // Until we can upgrade CustomPP to be full render graph, we'll always read and bind them globally. passData.depthBuffer = builder.ReadTexture(depthBuffer); passData.normalBuffer = builder.ReadTexture(normalBuffer); + passData.motionVecTexture = builder.ReadTexture(motionVectors); passData.source = builder.ReadTexture(source); passData.destination = builder.UseColorBuffer(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) @@ -1317,6 +1318,7 @@ bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref Texture // Temporary: see comment above ctx.cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, data.depthBuffer); ctx.cmd.SetGlobalTexture(HDShaderIDs._NormalBufferTexture, data.normalBuffer); + ctx.cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, data.motionVecTexture); data.customPostProcess.Render(ctx.cmd, data.hdCamera, data.source, data.destination); }); @@ -1332,14 +1334,14 @@ bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref Texture return customPostProcessExecuted; } - TextureHandle CustomPostProcessPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source, TextureHandle depthBuffer, TextureHandle normalBuffer, List postProcessList, HDProfileId profileId) + TextureHandle CustomPostProcessPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, List postProcessList, HDProfileId profileId) { if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.CustomPostProcess)) return source; using (new RenderGraphProfilingScope(renderGraph, ProfilingSampler.Get(profileId))) { - DoCustomPostProcess(renderGraph, hdCamera, ref source, depthBuffer, normalBuffer, postProcessList); + DoCustomPostProcess(renderGraph, hdCamera, ref source, depthBuffer, normalBuffer, motionVectors, postProcessList); } return source; From 776cd0377caa617b50764e6de7cac55d38557d70 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Tue, 8 Jun 2021 16:04:57 +0200 Subject: [PATCH 2/3] Missed changed --- .../Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 1828add934d..9a9a7f28f11 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -1274,6 +1274,7 @@ class CustomPostProcessData public TextureHandle destination; public TextureHandle depthBuffer; public TextureHandle normalBuffer; + public TextureHandle motionVecTexture; public HDCamera hdCamera; public CustomPostProcessVolumeComponent customPostProcess; } From 86605c5fac67aceb7fe9495719949c62c2f3867d Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Thu, 10 Jun 2021 20:23:08 +0200 Subject: [PATCH 3/3] Missed another changed --- .../Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index abc0e40258a..b65ada37721 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -181,7 +181,7 @@ void RecordRenderGraph(RenderRequest renderRequest, // Send all the geometry graphics buffer to client systems if required (must be done after the pyramid and before the transparent depth pre-pass) SendGeometryGraphicsBuffers(m_RenderGraph, prepassOutput.normalBuffer, prepassOutput.depthPyramidTexture, hdCamera); - DoUserAfterOpaqueAndSky(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.resolvedDepthBuffer, prepassOutput.resolvedNormalBuffer); + DoUserAfterOpaqueAndSky(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.resolvedDepthBuffer, prepassOutput.resolvedNormalBuffer, prepassOutput.resolvedMotionVectorsBuffer); // No need for old stencil values here since from transparent on different features are tagged ClearStencilBuffer(m_RenderGraph, hdCamera, prepassOutput.depthBuffer);