|
7 | 7 | #include "Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl" |
8 | 8 |
|
9 | 9 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl" |
10 | | -// This must be included first before we declare any global constant buffer and will only affect ray tracing shaders |
| 10 | +// This must be included first before we declare any global constant buffer and will onyl affect ray tracing shaders |
11 | 11 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl" |
12 | 12 |
|
13 | 13 | // CAUTION: |
@@ -324,14 +324,55 @@ float4x4 GetRawUnityWorldToObject() { return unity_WorldToObject; } |
324 | 324 | #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld()) |
325 | 325 | #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject()) |
326 | 326 |
|
| 327 | +// To get instancing working, we must use UNITY_MATRIX_M / UNITY_MATRIX_I_M as UnityInstancing.hlsl redefine them |
| 328 | +#define unity_ObjectToWorld Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld |
| 329 | +#define unity_WorldToObject Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject |
| 330 | + |
327 | 331 | // This define allow to tell to unity instancing that we will use our camera relative functions (ApplyCameraTranslationToMatrix and ApplyCameraTranslationToInverseMatrix) for the model view matrix |
328 | 332 | #define MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING |
329 | 333 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" |
330 | 334 |
|
331 | | -// To get instancing working, we must use UNITY_MATRIX_M / UNITY_MATRIX_I_M as UnityInstancing.hlsl redefine them |
332 | | -// So throw an error if there is an attempt to do direct access |
333 | | -#define unity_ObjectToWorld Use_Macro_UNITY_MATRIX_M_instead_of_unity_ObjectToWorld |
334 | | -#define unity_WorldToObject Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject |
| 335 | +#ifdef UNITY_DOTS_INSTANCING_ENABLED |
| 336 | +// Undef the matrix error macros so that the DOTS instancing macro works |
| 337 | +#undef unity_ObjectToWorld |
| 338 | +#undef unity_WorldToObject |
| 339 | +UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) |
| 340 | + UNITY_DOTS_INSTANCED_PROP(float4x4, unity_ObjectToWorld) |
| 341 | + UNITY_DOTS_INSTANCED_PROP(float4x4, unity_WorldToObject) |
| 342 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_LODFade) |
| 343 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_WorldTransformParams) |
| 344 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_RenderingLayer) |
| 345 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_LightmapST) |
| 346 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_DynamicLightmapST) |
| 347 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAr) |
| 348 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAg) |
| 349 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAb) |
| 350 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBr) |
| 351 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg) |
| 352 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb) |
| 353 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC) |
| 354 | + UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion) |
| 355 | + UNITY_DOTS_INSTANCED_PROP(float4x4, unity_MatrixPreviousM) |
| 356 | + UNITY_DOTS_INSTANCED_PROP(float4x4, unity_MatrixPreviousMI) |
| 357 | +UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) |
| 358 | + |
| 359 | +// Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere |
| 360 | +#define unity_LODFade UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_LODFade) |
| 361 | +#define unity_WorldTransformParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_WorldTransformParams) |
| 362 | +#define unity_RenderingLayer UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_RenderingLayer) |
| 363 | +#define unity_LightmapST UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_LightmapST) |
| 364 | +#define unity_DynamicLightmapST UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_DynamicLightmapST) |
| 365 | +#define unity_SHAr UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAr) |
| 366 | +#define unity_SHAg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAg) |
| 367 | +#define unity_SHAb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAb) |
| 368 | +#define unity_SHBr UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBr) |
| 369 | +#define unity_SHBg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBg) |
| 370 | +#define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) |
| 371 | +#define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) |
| 372 | +#define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion) |
| 373 | +#define unity_MatrixPreviousM UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_MatrixPreviousM) |
| 374 | +#define unity_MatrixPreviousMI UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_MatrixPreviousMI) |
| 375 | +#endif |
335 | 376 |
|
336 | 377 | // Define View/Projection matrix macro |
337 | 378 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" |
|
0 commit comments