Skip to content

Commit ffdc83e

Browse files
[8.x.x Backport] Fix transparent/opaque motion vector inconsistencies by allowing camera-only transparent motion vectors (#837)
* port * changelog * Update HDRenderPipeline.cs Co-authored-by: sebastienlagarde <[email protected]>
1 parent 3a00afa commit ffdc83e

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6969
- 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).
7070
- Fixed for area light not updating baked light result when modifying with gizmo.
7171
- Fixed issue with white flash when enabling SSR.
72+
- Fix inconsistencies with transparent motion vectors and opaque by allowing camera only transparent motion vectors.
7273

7374
### Changed
7475
- Shadowmask and realtime reflection probe property are hide in Quality settings

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ internal void SetupGlobalParams(CommandBuffer cmd, int frameCount)
662662
cmd.SetGlobalVectorArray(HDShaderIDs._XRPrevWorldSpaceCameraPos, m_XRPrevWorldSpaceCameraPos);
663663
}
664664

665+
cmd.SetGlobalInt(HDShaderIDs._TransparentCameraOnlyMotionVectors, (frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && !frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) ? 1 : 0);
665666
}
666667

667668
internal void AllocateAmbientOcclusionHistoryBuffer(float scaleFactor)

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,7 @@ out ScriptableCullingParameters cullingParams
27282728
if (camera.cameraType != CameraType.Game)
27292729
{
27302730
currentFrameSettings.SetEnabled(FrameSettingsField.ObjectMotionVectors, false);
2731+
currentFrameSettings.SetEnabled(FrameSettingsField.TransparentsWriteMotionVector, false);
27312732
}
27322733

27332734
hdCamera = HDCamera.GetOrCreate(camera, xrPass.multipassId);
@@ -3596,7 +3597,7 @@ void RenderForwardOpaque(CullingResults cullResults, HDCamera hdCamera, Scriptab
35963597

35973598
static bool NeedMotionVectorForTransparent(FrameSettings frameSettings)
35983599
{
3599-
return frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector) && frameSettings.IsEnabled(FrameSettingsField.ObjectMotionVectors);
3600+
return frameSettings.IsEnabled(FrameSettingsField.MotionVectors);
36003601
}
36013602

36023603
RendererListDesc PrepareForwardTransparentRendererList(CullingResults cullResults, HDCamera hdCamera, bool preRefraction)

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ static class HDShaderIDs
310310
public static readonly int _TaaFrameInfo = Shader.PropertyToID("_TaaFrameInfo");
311311
public static readonly int _TaaJitterStrength = Shader.PropertyToID("_TaaJitterStrength");
312312

313+
public static readonly int _TransparentCameraOnlyMotionVectors = Shader.PropertyToID("_TransparentCameraOnlyMotionVectors ");
314+
313315
public static readonly int _WorldSpaceCameraPos1 = Shader.PropertyToID("_WorldSpaceCameraPos1");
314316
public static readonly int _ViewMatrix1 = Shader.PropertyToID("_ViewMatrix1");
315317

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes
133133
ApplyVertexModification(inputMesh, normalWS, previousPositionRWS, _LastTimeParameters.xyz);
134134
#endif
135135

136+
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
137+
if (_TransparentCameraOnlyMotionVectors > 0)
138+
{
139+
previousPositionRWS = varyingsType.vmesh.positionRWS.xyz;
140+
}
141+
#endif
142+
136143
varyingsType.vpass.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0));
137144
}
138145

com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ CBUFFER_START(UnityGlobal)
283283

284284
float4 _CoarseStencilBufferSize;
285285

286+
int _TransparentCameraOnlyMotionVectors;
287+
float3 _Pad;
288+
286289
CBUFFER_END
287290

288291
// Custom generated by HDRP, not from Unity Engine (passed in via HDCamera)

0 commit comments

Comments
 (0)