-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2023.2][URP] Fix missing LOD CrossFade and AlphaClip support in the …
…motion vector pass This PR fixes: https://jira.unity3d.com/browse/UUM-25476 Primarily this PR: - Adds missing `_ALPHATEST_ON` and `LOD_FADE_CROSSFADE` shader variant support to the URP object motion vector shaders (as the added variants are in a new pass, this does not multiply the existing "billions" of variants, and only adds a handful of them) - Adds a motion vector pass to each of the basic URP shader types instead of relying on `ObjectMotionVectors.shader` for all materials (doing this as Getting AlphaClip inputs is shader specific (texture/color alpha and sometimes a threshold) - Adds a material upgrader to disable the newly added `MOTIONVECTORS` pass by adding it to the `disabledShaderPasses` list to avoid performance regressions (i.e. so MVs would not be rendered for static objects; the engine will still draw the pass if the renderer is moving due to skeletal animation and/or if its transform changes between frames - this is built-in behaviour) - Upgrades the default materials located in URP to the new version This PR also: - Makes the object and camera motion vector arithmetic more conservative by avoiding `half` (I was seeing visual discrepancies in background camera motion vectors on Nintendo Switch - were getting rounded to 0) - Renames the `ObjectMotionVectors.shader` to `ObjectMotionVectorFallback.shader` as it will no longer be used for all materials, it will only be used for user written HLSL shaders which don't provide their own motion vector pass and for our materials which aren't `Lit`, `Unlit`, `Complex Lit`, `Simple Lit`, `Baked Lit`, `ShaderGraph Lit`, or `ShaderGraph Unlit` - Fixes an issue where `ComplexLit` wasn't ever being upgraded (as it didn't have entries in the `ShaderID` and `ShaderPathID` enums (in `Editor/ShaderUtils.cs` and `Runtime/ShaderUtils.cs`)). However, simply enabling upgrading seemed to in certain cases alter visuals for transparent premultiplied ComplexLit materials (happened in our Foundation test project), so I also modified the V5 to V6 upgrade logic so this wouldn't happen (very detailed explanation in the code comments)
- Loading branch information
Showing
148 changed files
with
69,528 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...es/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/MotionVectorPass.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifndef SG_MOTION_VECTORS_PASS_INCLUDED | ||
#define SG_MOTION_VECTORS_PASS_INCLUDED | ||
|
||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MotionVectorsCommon.hlsl" | ||
|
||
struct MotionVectorPassAttributes | ||
{ | ||
float3 previousPositionOS : TEXCOORD4; // Contains previous frame local vertex position (for skinned meshes) | ||
}; | ||
|
||
// Note: these will have z == 0.0f in the pixel shader to save on bandwidth | ||
struct MotionVectorPassVaryings | ||
{ | ||
float4 positionCSNoJitter; | ||
float4 previousPositionCSNoJitter; | ||
}; | ||
|
||
struct PackedMotionVectorPassVaryings | ||
{ | ||
float3 positionCSNoJitter : CLIP_POSITION_NO_JITTER; | ||
float3 previousPositionCSNoJitter : PREVIOUS_CLIP_POSITION_NO_JITTER; | ||
}; | ||
|
||
PackedMotionVectorPassVaryings PackMotionVectorVaryings(MotionVectorPassVaryings regularVaryings) | ||
{ | ||
PackedMotionVectorPassVaryings packedVaryings; | ||
packedVaryings.positionCSNoJitter = regularVaryings.positionCSNoJitter.xyw; | ||
packedVaryings.previousPositionCSNoJitter = regularVaryings.previousPositionCSNoJitter.xyw; | ||
return packedVaryings; | ||
} | ||
|
||
MotionVectorPassVaryings UnpackMotionVectorVaryings(PackedMotionVectorPassVaryings packedVaryings) | ||
{ | ||
MotionVectorPassVaryings regularVaryings; | ||
regularVaryings.positionCSNoJitter = float4(packedVaryings.positionCSNoJitter.xy, 0, packedVaryings.positionCSNoJitter.z); | ||
regularVaryings.previousPositionCSNoJitter = float4(packedVaryings.previousPositionCSNoJitter.xy, 0, packedVaryings.previousPositionCSNoJitter.z); | ||
return regularVaryings; | ||
} | ||
|
||
// ------------------------------------- | ||
// Vertex | ||
void vert( | ||
Attributes input, | ||
MotionVectorPassAttributes passInput, | ||
out PackedMotionVectorPassVaryings packedMvOutput, | ||
out PackedVaryings packedOutput) | ||
{ | ||
Varyings output = (Varyings)0; | ||
MotionVectorPassVaryings mvOutput = (MotionVectorPassVaryings)0; | ||
output = BuildVaryings(input); | ||
ApplyMotionVectorZBias(output.positionCS); | ||
packedOutput = PackVaryings(output); | ||
|
||
const bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; | ||
if(!forceNoMotion) | ||
{ | ||
const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation | ||
float3 previousPositionOS = hasDeformation ? passInput.previousPositionOS : input.positionOS; | ||
|
||
mvOutput.positionCSNoJitter = mul(_NonJitteredViewProjMatrix, mul(UNITY_MATRIX_M, float4(input.positionOS, 1.0f))); | ||
mvOutput.previousPositionCSNoJitter = mul(_PrevViewProjMatrix, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f))); | ||
} | ||
|
||
packedMvOutput = PackMotionVectorVaryings(mvOutput); | ||
} | ||
|
||
// ------------------------------------- | ||
// Fragment | ||
float4 frag( | ||
// Note: packedMvInput needs to be before packedInput as otherwise we get the following error in the speed tree 8 SG: | ||
// "Non system-generated input signature parameter () cannot appear after a system generated value" | ||
PackedMotionVectorPassVaryings packedMvInput, | ||
PackedVaryings packedInput) : SV_Target | ||
{ | ||
Varyings input = UnpackVaryings(packedInput); | ||
MotionVectorPassVaryings mvInput = UnpackMotionVectorVaryings(packedMvInput); | ||
UNITY_SETUP_INSTANCE_ID(input); | ||
SurfaceDescription surfaceDescription = BuildSurfaceDescription(input); | ||
|
||
#if _ALPHATEST_ON | ||
clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); | ||
#endif | ||
|
||
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE | ||
LODFadeCrossFade(input.positionCS); | ||
#endif | ||
|
||
return float4(CalcNdcMotionVectorFromCsPositions(mvInput.positionCSNoJitter, mvInput.previousPositionCSNoJitter), 0, 0); | ||
} | ||
#endif |
9 changes: 9 additions & 0 deletions
9
...m.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/MotionVectorPass.hlsl.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.