diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index d7165b56061..1586c03b8a4 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added OverridablePropertyScope (for VolumeComponentEditor child class only) to handle the Additional Property, the override checkbox and disable display and decorator attributes in one scope. - Added IndentLevelScope (for VolumeComponentEditor child class only) to handle indentation of the field and the checkbox. - Added class for drawing shadow cascades `UnityEditor.Rendering.ShadowCascadeGUI.DrawShadowCascades`. +- Added UNITY_PREV_MATRIX_M and UNITY_PREV_MATRIX_I_M shader macros to support instanced motion vector rendering ### Fixed - Fixed missing warning UI about Projector component being unsupported (case 1300327). diff --git a/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl index 52903b13e55..101ab023c97 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl @@ -18,6 +18,16 @@ float4x4 GetWorldToObjectMatrix() return UNITY_MATRIX_I_M; } +float4x4 GetPrevObjectToWorldMatrix() +{ + return UNITY_PREV_MATRIX_M; +} + +float4x4 GetPrevWorldToObjectMatrix() +{ + return UNITY_PREV_MATRIX_I_M; +} + float4x4 GetWorldToViewMatrix() { return UNITY_MATRIX_V; diff --git a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl index 513094e6c89..d276986bf85 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl @@ -355,18 +355,29 @@ #define unity_ProbesOcclusion UNITY_ACCESS_INSTANCED_PROP(unity_Builtins2, unity_ProbesOcclusionArray) #endif UNITY_INSTANCING_BUFFER_END(unity_Builtins2) + + UNITY_INSTANCING_BUFFER_START(PerDraw3) + UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_PrevObjectToWorldArray) + UNITY_DEFINE_INSTANCED_PROP(float4x4, unity_PrevWorldToObjectArray) + UNITY_INSTANCING_BUFFER_END(unity_Builtins3) #endif // TODO: What about UNITY_DONT_INSTANCE_OBJECT_MATRICES for DOTS? #if defined(UNITY_DOTS_INSTANCING_ENABLED) #undef UNITY_MATRIX_M #undef UNITY_MATRIX_I_M + #undef UNITY_PREV_MATRIX_M + #undef UNITY_PREV_MATRIX_I_M #ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING - #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_ObjectToWorld))) - #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_WorldToObject))) + #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_ObjectToWorld))) + #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_WorldToObject))) + #define UNITY_PREV_MATRIX_M ApplyCameraTranslationToMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM))) + #define UNITY_PREV_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI))) #else - #define UNITY_MATRIX_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_ObjectToWorld)) - #define UNITY_MATRIX_I_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_WorldToObject)) + #define UNITY_MATRIX_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_ObjectToWorld)) + #define UNITY_MATRIX_I_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_WorldToObject)) + #define UNITY_PREV_MATRIX_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) + #define UNITY_PREV_MATRIX_I_M LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) #endif #else @@ -383,11 +394,15 @@ #endif #ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING - #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)) - #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(UNITY_BUILTINS_WITH_WORLDTOOBJECTARRAY, unity_WorldToObjectArray)) + #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)) + #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(UNITY_BUILTINS_WITH_WORLDTOOBJECTARRAY, unity_WorldToObjectArray)) + #define UNITY_PREV_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins3, unity_PrevObjectToWorldArray)) + #define UNITY_PREV_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins3, unity_PrevWorldToObjectArray)) #else - #define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray) - #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(UNITY_BUILTINS_WITH_WORLDTOOBJECTARRAY, unity_WorldToObjectArray) + #define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray) + #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(UNITY_BUILTINS_WITH_WORLDTOOBJECTARRAY, unity_WorldToObjectArray) + #define UNITY_PREV_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins3, unity_PrevObjectToWorldArray) + #define UNITY_PREV_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins3, unity_PrevWorldToObjectArray) #endif #endif diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index efb604a6d02..501af47afa9 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -330,6 +330,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed misc TAA issue: Slightly improved TAA flickering, Reduced ringing of TAA sharpening, tweak TAA High quality central color filtering. - Fixed TAA upsampling algorithm, now work properly - Fixed custom post process template not working with Blit method. +- Fixed support for instanced motion vector rendering ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl index 7623688cfc2..d8262706756 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl @@ -11,6 +11,7 @@ // Define the correct matrices #undef unity_ObjectToWorld +#undef unity_MatrixPreviousM #undef unity_MatrixVP float4x4 unity_MatrixV; float4x4 unity_MatrixVP; @@ -22,6 +23,12 @@ float4x4 glstate_matrix_projection; #undef UNITY_MATRIX_I_M #define UNITY_MATRIX_I_M Inverse(unity_ObjectToWorld) +#undef UNITY_PREV_MATRIX_M +#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM + +#undef UNITY_PREV_MATRIX_I_M +#define UNITY_PREV_MATRIX_I_M Inverse(unity_MatrixPreviousM) + #undef UNITY_MATRIX_V #define UNITY_MATRIX_V unity_MatrixV @@ -35,6 +42,8 @@ float4x4 glstate_matrix_projection; // Overwrite the SpaceTransforms functions #define GetObjectToWorldMatrix GetObjectToWorldMatrix_Picking #define GetWorldToObjectMatrix GetWorldToObjectMatrix_Picking +#define GetPrevObjectToWorldMatrix GetPrevObjectToWorldMatrix_Picking +#define GetPrevWorldToObjectMatrix GetPrevWorldToObjectMatrix_Picking #define GetWorldToViewMatrix GetWorldToViewMatrix_Picking #define GetWorldToHClipMatrix GetWorldToHClipMatrix_Picking #define GetViewToHClipMatrix GetViewToHClipMatrix_Picking 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 aec44d3ec73..3546a34403d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -452,11 +452,15 @@ uint Get1DAddressFromPixelCoord(uint2 pixCoord, uint2 screenSize) // Define Model Matrix Macro // Note: In order to be able to define our macro to forbid usage of unity_ObjectToWorld/unity_WorldToObject // We need to declare inline function. Using uniform directly mean they are expand with the macro -float4x4 GetRawUnityObjectToWorld() { return unity_ObjectToWorld; } -float4x4 GetRawUnityWorldToObject() { return unity_WorldToObject; } - -#define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld()) -#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject()) +float4x4 GetRawUnityObjectToWorld() { return unity_ObjectToWorld; } +float4x4 GetRawUnityWorldToObject() { return unity_WorldToObject; } +float4x4 GetRawUnityPrevObjectToWorld() { return unity_MatrixPreviousM; } +float4x4 GetRawUnityPrevWorldToObject() { return unity_MatrixPreviousMI; } + +#define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld()) +#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject()) +#define UNITY_PREV_MATRIX_M ApplyCameraTranslationToMatrix(GetRawUnityPrevObjectToWorld()) +#define UNITY_PREV_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(GetRawUnityPrevWorldToObject()) // To get instancing working, we must use UNITY_MATRIX_M / UNITY_MATRIX_I_M as UnityInstancing.hlsl redefine them #define unity_ObjectToWorld Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl index 3de4892d739..916e01ee6eb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl @@ -145,18 +145,17 @@ float3x3 BuildTangentToWorld(float4 tangentWS, float3 normalWS) float3 TransformPreviousObjectToWorldNormal(float3 normalOS) { #ifdef UNITY_ASSUME_UNIFORM_SCALING - return normalize(mul((float3x3)unity_MatrixPreviousM, normalOS)); + return normalize(mul((float3x3)UNITY_PREV_MATRIX_M, normalOS)); #else // Normal need to be multiply by inverse transpose - return normalize(mul(normalOS, (float3x3)unity_MatrixPreviousMI)); + return normalize(mul(normalOS, (float3x3)UNITY_PREV_MATRIX_I_M)); #endif } // Transforms local position to camera relative world space float3 TransformPreviousObjectToWorld(float3 positionOS) { - float4x4 previousModelMatrix = ApplyCameraTranslationToMatrix(unity_MatrixPreviousM); - return mul(previousModelMatrix, float4(positionOS, 1.0)).xyz; + return mul(UNITY_PREV_MATRIX_M, float4(positionOS, 1.0)).xyz; } diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl index ad3dbf92268..52d801b6ef9 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl @@ -149,6 +149,8 @@ CBUFFER_END #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) +#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM +#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI // Note: #include order is important here. // UnityInput.hlsl must be included before UnityInstancing.hlsl, so constant buffer diff --git a/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Input.hlsl b/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Input.hlsl index 4d489e7cc93..c8aa968544f 100644 --- a/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Input.hlsl +++ b/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Input.hlsl @@ -83,11 +83,14 @@ CBUFFER_END #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) +#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM +#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI #else // Not defined already by built-in #define UNITY_MATRIX_I_M unity_WorldToObject #define UNITY_MATRIX_I_P (float4x4)0 #define UNITY_MATRIX_I_VP (float4x4)0 +#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI #endif diff --git a/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesMatrixDefsLegacyUnity.hlsl b/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesMatrixDefsLegacyUnity.hlsl index 38043f49bba..4e805eb8de2 100644 --- a/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesMatrixDefsLegacyUnity.hlsl +++ b/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesMatrixDefsLegacyUnity.hlsl @@ -17,5 +17,7 @@ #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) +#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM +#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI #endif // UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED