From 3d68cfc974e6af39086434833b80029a32c6ab0f Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 9 Jun 2020 13:37:11 +0200 Subject: [PATCH 1/3] Allow camera only transparent motion vectors --- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 3 +++ .../Runtime/RenderPipeline/HDRenderPipeline.cs | 3 ++- .../ShaderPass/MotionVectorVertexShaderCommon.hlsl | 7 +++++++ .../RenderPipeline/ShaderPass/ShaderPassForward.hlsl | 7 ++++++- .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs | 5 +++++ .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) 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 c14e096b4e0..0e92fee0e04 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 @@ -664,6 +664,9 @@ unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb, float exposureMultiplierForProbes = 1.0f / Mathf.Max(probeRangeCompressionFactor, 1e-6f); cb._ProbeExposureScale = exposureMultiplierForProbes; + + cb._TransparentCameraOnlyMotionVectors = (frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && + !frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) ? 1 : 0; } 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 becb97dd8ff..79003063164 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3069,6 +3069,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); @@ -4013,7 +4014,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) 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/RenderPipeline/ShaderPass/ShaderPassForward.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl index b9d548d1443..ac7dc69a342 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 @@ -232,7 +232,12 @@ void Frag(PackedVaryingsToPS packedInput, // outMotionVec is already initialize at the value of forceNoMotion (see above) if (!forceNoMotion) { - float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS); + float4 previousPosCS = inputPass.previousPositionCS; + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPosCS = mul(UNITY_MATRIX_PREV_VP, posInput.positionWS); + } + float2 motionVec = CalculateMotionVector(inputPass.positionCS, previousPosCS); EncodeMotionVector(motionVec * 0.5, outMotionVec); outMotionVec.zw = 1.0; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index ca44206beb9..820099f042c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -252,5 +252,10 @@ unsafe struct ShaderVariablesGlobal [HLSLArray(7, typeof(Vector4))] public fixed float _ProbeVolumeAmbientProbeFallbackPackedCoeffs[7 * 4]; // 3 bands of SH, packed for storing global ambient probe lighting as fallback to probe volumes. + + public int _TransparentCameraOnlyMotionVectors; + public float _Pad8; + public float _Pad9; + public float _Pad10; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index ce07922e4f1..393f1581bcd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -142,6 +142,10 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) float _ProbeVolumeBilateralFilterWeightMin; float _ProbeVolumeBilateralFilterWeight; float4 _ProbeVolumeAmbientProbeFallbackPackedCoeffs[7]; + int _TransparentCameraOnlyMotionVectors; + float _Pad8; + float _Pad9; + float _Pad10; CBUFFER_END From 4dd2f085250eadb9b2499c639626eef34bb2c58c Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 9 Jun 2020 13:38:07 +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 95ecf55ea4f..1f854cab603 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -652,6 +652,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix an issue with the color intensity of emissive for performance rtgi - Fixed issue with rendering being mostly broken when target platform disables VR. - Workaround an issue caused by GetKernelThreadGroupSizes failing to retrieve correct group size. +- Fix inconsistencies with transparent motion vectors and opaque by allowing camera only transparent motion vectors. ### Changed - Improve MIP selection for decals on Transparents From f9410daa2d2a8f34999adfd0f3eb1db67198a2bd Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 9 Jun 2020 13:45:50 +0200 Subject: [PATCH 3/3] revert old way of doing it. --- .../RenderPipeline/ShaderPass/ShaderPassForward.hlsl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 ac7dc69a342..b9d548d1443 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 @@ -232,12 +232,7 @@ void Frag(PackedVaryingsToPS packedInput, // outMotionVec is already initialize at the value of forceNoMotion (see above) if (!forceNoMotion) { - float4 previousPosCS = inputPass.previousPositionCS; - if (_TransparentCameraOnlyMotionVectors > 0) - { - previousPosCS = mul(UNITY_MATRIX_PREV_VP, posInput.positionWS); - } - float2 motionVec = CalculateMotionVector(inputPass.positionCS, previousPosCS); + float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS); EncodeMotionVector(motionVec * 0.5, outMotionVec); outMotionVec.zw = 1.0; }