From 2490b33b6701f7a8b2827c3a2687c0d705482aef Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 11 Jun 2020 11:21:02 +0200 Subject: [PATCH 1/3] port --- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 1 + .../Runtime/RenderPipeline/HDRenderPipeline.cs | 3 ++- .../Runtime/RenderPipeline/HDStringConstants.cs | 2 ++ .../ShaderPass/MotionVectorVertexShaderCommon.hlsl | 7 +++++++ .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) 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 d59f6cc0911..9de326dff55 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 @@ -661,6 +661,7 @@ internal void SetupGlobalParams(CommandBuffer cmd, int frameCount) cmd.SetGlobalVectorArray(HDShaderIDs._XRPrevWorldSpaceCameraPos, m_XRPrevWorldSpaceCameraPos); } + cmd.SetGlobalInt(HDShaderIDs._TransparentCameraOnlyMotionVectors, (frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && !frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) ? 1 : 0); } internal void AllocateAmbientOcclusionHistoryBuffer(float scaleFactor) 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 b7678a90b1b..bc68c984417 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2687,6 +2687,7 @@ out ScriptableCullingParameters cullingParams if (camera.cameraType != CameraType.Game) { currentFrameSettings.SetEnabled(FrameSettingsField.ObjectMotionVectors, false); + currentFrameSettings.SetEnabled(FrameSettingsField.TransparentsWriteMotionVector, false); } hdCamera = HDCamera.GetOrCreate(camera, xrPass.multipassId); @@ -3555,7 +3556,7 @@ void RenderForwardOpaque(CullingResults cullResults, HDCamera hdCamera, Scriptab static bool NeedMotionVectorForTransparent(FrameSettings frameSettings) { - return frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector); + return frameSettings.IsEnabled(FrameSettingsField.MotionVectors); } RendererListDesc PrepareForwardTransparentRendererList(CullingResults cullResults, HDCamera hdCamera, bool preRefraction) 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 ef300ef3a6b..313f6db6378 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -307,6 +307,8 @@ static class HDShaderIDs public static readonly int _TaaFrameInfo = Shader.PropertyToID("_TaaFrameInfo"); public static readonly int _TaaJitterStrength = Shader.PropertyToID("_TaaJitterStrength"); + public static readonly int _TransparentCameraOnlyMotionVectors = Shader.PropertyToID("_TransparentCameraOnlyMotionVectors "); + public static readonly int _WorldSpaceCameraPos1 = Shader.PropertyToID("_WorldSpaceCameraPos1"); public static readonly int _ViewMatrix1 = Shader.PropertyToID("_ViewMatrix1"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index 60903b412d6..d96713326dc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -133,6 +133,13 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes ApplyVertexModification(inputMesh, normalWS, previousPositionRWS, _LastTimeParameters.xyz); #endif +#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = varyingsType.vmesh.positionRWS.xyz; + } +#endif + varyingsType.vpass.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 3ae291f141e..c1a2619a6ab 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -283,6 +283,9 @@ CBUFFER_START(UnityGlobal) float4 _CoarseStencilBufferSize; + int _TransparentCameraOnlyMotionVectors; + float3 _Pad; + CBUFFER_END // Custom generated by HDRP, not from Unity Engine (passed in via HDCamera) From 46d71084812e96c7f091e3927b30d76010458507 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 11 Jun 2020 11:30:05 +0200 Subject: [PATCH 2/3] 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 ea826f2f878..344eff80bcc 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed depth prepass and postpass being disabled after changing the shader in the material UI. - Fix an issue in reading the gbuffer for ray traced subsurface scattering (case 1248358). - Fixed an issue where editing the Look Dev default profile would not reflect directly in the Look Dev window. +- Fix inconsistencies with transparent motion vectors and opaque by allowing camera only transparent motion vectors. ### Changed - Shadowmask and realtime reflection probe property are hide in Quality settings From dc8ed8f8c96b5c2f60a23337276936e236c731b1 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Tue, 7 Jul 2020 19:52:18 +0200 Subject: [PATCH 3/3] Update HDRenderPipeline.cs --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f1e5af77b66..f2622bfb2ea 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3597,7 +3597,7 @@ void RenderForwardOpaque(CullingResults cullResults, HDCamera hdCamera, Scriptab static bool NeedMotionVectorForTransparent(FrameSettings frameSettings) { - return frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector) && frameSettings.IsEnabled(FrameSettingsField.ObjectMotionVectors); + return frameSettings.IsEnabled(FrameSettingsField.MotionVectors); } RendererListDesc PrepareForwardTransparentRendererList(CullingResults cullResults, HDCamera hdCamera, bool preRefraction)