Skip to content

Commit 052479a

Browse files
Fix transparent/opaque motion vector inconsistencies by allowing camera-only transparent motion vectors (#788)
* Allow camera only transparent motion vectors * Changelog * revert old way of doing it. Co-authored-by: sebastienlagarde <[email protected]>
1 parent ec00eb3 commit 052479a

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-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
@@ -659,6 +659,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
659659
- Fixed white flash when enabling SSR or SSGI.
660660
- The ray traced indrect diffuse and RTGI were combined wrongly with the rest of the lighting (1254318).
661661
- Fixed an exception happening when using RTSSS without using RTShadows.
662+
- Fix inconsistencies with transparent motion vectors and opaque by allowing camera only transparent motion vectors.
662663

663664
### Changed
664665
- Improve MIP selection for decals on Transparents

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb,
666666

667667
float exposureMultiplierForProbes = 1.0f / Mathf.Max(probeRangeCompressionFactor, 1e-6f);
668668
cb._ProbeExposureScale = exposureMultiplierForProbes;
669+
670+
cb._TransparentCameraOnlyMotionVectors = (frameSettings.IsEnabled(FrameSettingsField.MotionVectors) &&
671+
!frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) ? 1 : 0;
669672
}
670673

671674

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,7 @@ out ScriptableCullingParameters cullingParams
30713071
if (camera.cameraType != CameraType.Game)
30723072
{
30733073
currentFrameSettings.SetEnabled(FrameSettingsField.ObjectMotionVectors, false);
3074+
currentFrameSettings.SetEnabled(FrameSettingsField.TransparentsWriteMotionVector, false);
30743075
}
30753076

30763077
hdCamera = HDCamera.GetOrCreate(camera, xrPass.multipassId);
@@ -4015,7 +4016,7 @@ void RenderForwardOpaque(CullingResults cullResults, HDCamera hdCamera, Scriptab
40154016

40164017
static bool NeedMotionVectorForTransparent(FrameSettings frameSettings)
40174018
{
4018-
return frameSettings.IsEnabled(FrameSettingsField.MotionVectors) && frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector) && frameSettings.IsEnabled(FrameSettingsField.ObjectMotionVectors);
4019+
return frameSettings.IsEnabled(FrameSettingsField.MotionVectors);
40194020
}
40204021

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

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/ShaderVariablesGlobal.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,10 @@ unsafe struct ShaderVariablesGlobal
252252

253253
[HLSLArray(7, typeof(Vector4))]
254254
public fixed float _ProbeVolumeAmbientProbeFallbackPackedCoeffs[7 * 4]; // 3 bands of SH, packed for storing global ambient probe lighting as fallback to probe volumes.
255+
256+
public int _TransparentCameraOnlyMotionVectors;
257+
public float _Pad8;
258+
public float _Pad9;
259+
public float _Pad10;
255260
}
256261
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0)
142142
float _ProbeVolumeBilateralFilterWeight;
143143
float _Pad8;
144144
float4 _ProbeVolumeAmbientProbeFallbackPackedCoeffs[7];
145+
int _TransparentCameraOnlyMotionVectors;
146+
float _Pad8;
147+
float _Pad9;
148+
float _Pad10;
145149
CBUFFER_END
146150

147151

0 commit comments

Comments
 (0)