From 35175128afca7ea0cb995ea7a71a8ede9fb4d62d Mon Sep 17 00:00:00 2001 From: Vincent Breysse Date: Thu, 9 Sep 2021 15:08:37 +0200 Subject: [PATCH 1/2] Fix previous matrix shader compilation errors # Conflicts: # com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl --- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 8 +++++--- .../ShaderLibrary/UniversalDOTSInstancing.hlsl | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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 f4ee8db4208..feb63d0eae6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -460,9 +460,11 @@ float4x4 GetRawUnityPrevWorldToObject() { return unity_MatrixPreviousMI; } #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 +// To get instancing working, we must use UNITY_MATRIX_M/UNITY_MATRIX_I_M/UNITY_PREV_MATRIX_M/UNITY_PREV_MATRIX_I_M as UnityInstancing.hlsl redefine them #define unity_ObjectToWorld Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld #define unity_WorldToObject Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject +#define unity_MatrixPreviousM Use_Macro_UNITY_PREV_MATRIX_M_instead_of_unity_MatrixPreviousM +#define unity_MatrixPreviousMI Use_Macro_UNITY_PREV_MATRIX_I_M_instead_of_unity_MatrixPreviousMI // This define allow to tell to unity instancing that we will use our camera relative functions (ApplyCameraTranslationToMatrix and ApplyCameraTranslationToInverseMatrix) for the model view matrix #define MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING @@ -475,6 +477,8 @@ float4x4 GetRawUnityPrevWorldToObject() { return unity_MatrixPreviousMI; } // Undef the matrix error macros so that the DOTS instancing macro works #undef unity_ObjectToWorld #undef unity_WorldToObject +#undef unity_MatrixPreviousM +#undef unity_MatrixPreviousMI UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_ObjectToWorld) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_WorldToObject) @@ -511,8 +515,6 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) #define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) #define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion) -#define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) -#define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) #endif diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl index c36525e77f2..fca94d79565 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl @@ -5,6 +5,8 @@ #undef unity_ObjectToWorld #undef unity_WorldToObject +#undef unity_MatrixPreviousM +#undef unity_MatrixPreviousMI // TODO: This might not work correctly in all cases, double check! UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_ObjectToWorld) @@ -26,9 +28,11 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC) + UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) + UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) -// Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared in UnityInstancing.hlsl +// Note: Macros for unity_ObjectToWorld, unity_WorldToObject, unity_MatrixPreviousM and unity_MatrixPreviousMI are declared in UnityInstancing.hlsl // because of some special handling #define unity_LODFade UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_LODFade) #define unity_WorldTransformParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_WorldTransformParams) From 193d1db969cf20b2ceea8597a0736b33c9a9cd83 Mon Sep 17 00:00:00 2001 From: Vincent Breysse Date: Thu, 16 Sep 2021 16:42:33 +0200 Subject: [PATCH 2/2] Remove unnecessary change outside of the DOTS_INSTANCING_ON variant --- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 feb63d0eae6..3e02021f34d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -460,11 +460,9 @@ float4x4 GetRawUnityPrevWorldToObject() { return unity_MatrixPreviousMI; } #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/UNITY_PREV_MATRIX_M/UNITY_PREV_MATRIX_I_M as UnityInstancing.hlsl redefine them +// 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 #define unity_WorldToObject Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject -#define unity_MatrixPreviousM Use_Macro_UNITY_PREV_MATRIX_M_instead_of_unity_MatrixPreviousM -#define unity_MatrixPreviousMI Use_Macro_UNITY_PREV_MATRIX_I_M_instead_of_unity_MatrixPreviousMI // This define allow to tell to unity instancing that we will use our camera relative functions (ApplyCameraTranslationToMatrix and ApplyCameraTranslationToInverseMatrix) for the model view matrix #define MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING