Skip to content

Hd/new-draw-api #4190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
10 changes: 10 additions & 0 deletions com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 23 additions & 8 deletions com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// Define the correct matrices
#undef unity_ObjectToWorld
#undef unity_MatrixPreviousM
#undef unity_MatrixVP
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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