Skip to content

Commit c6aa4cf

Browse files
Merge branch 'master' into HDRP/staging
2 parents 1df31c6 + 453423b commit c6aa4cf

File tree

4 files changed

+87
-79
lines changed

4 files changed

+87
-79
lines changed

com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,37 @@ void ApplyDepthOffsetPositionInput(float3 V, float depthOffsetVS, float3 viewFor
11111111
posInput.linearDepth += depthOffsetVS * abs(dot(V, viewForwardDir));
11121112
}
11131113

1114+
// ----------------------------------------------------------------------------
1115+
// Terrain/Brush heightmap encoding/decoding
1116+
// ----------------------------------------------------------------------------
1117+
1118+
#if defined(SHADER_API_VULKAN) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
1119+
1120+
real4 PackHeightmap(real height)
1121+
{
1122+
uint a = (uint)(65535.0 * height);
1123+
return real4((a >> 0) & 0xFF, (a >> 8) & 0xFF, 0, 0) / 255.0;
1124+
}
1125+
1126+
real UnpackHeightmap(real4 height)
1127+
{
1128+
return (height.r + height.g * 256.0) / 257.0; // (255.0 * height.r + 255.0 * 256.0 * height.g) / 65535.0
1129+
}
1130+
1131+
#else
1132+
1133+
real4 PackHeightmap(real height)
1134+
{
1135+
return real4(height, 0, 0, 0);
1136+
}
1137+
1138+
real UnpackHeightmap(real4 height)
1139+
{
1140+
return height.r;
1141+
}
1142+
1143+
#endif
1144+
11141145
// ----------------------------------------------------------------------------
11151146
// Misc utilities
11161147
// ----------------------------------------------------------------------------

com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -217,37 +217,6 @@ real3 UnpackNormalScale(real4 packedNormal, real bumpScale)
217217
#endif
218218
}
219219

220-
// ----------------------------------------------------------------------------
221-
// Terrain/Brush heightmap encoding/decoding
222-
// ----------------------------------------------------------------------------
223-
224-
#if defined(SHADER_API_VULKAN) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
225-
226-
real4 PackHeightmap(real height)
227-
{
228-
uint a = (uint)(65535.0 * height);
229-
return real4((a >> 0) & 0xFF, (a >> 8) & 0xFF, 0, 0) / 255.0;
230-
}
231-
232-
real UnpackHeightmap(real4 height)
233-
{
234-
return (height.r + height.g * 256.0) / 257.0; // (255.0 * height.r + 255.0 * 256.0 * height.g) / 65535.0
235-
}
236-
237-
#else
238-
239-
real4 PackHeightmap(real height)
240-
{
241-
return real4(height, 0, 0, 0);
242-
}
243-
244-
real UnpackHeightmap(real4 height)
245-
{
246-
return height.r;
247-
}
248-
249-
#endif
250-
251220
//-----------------------------------------------------------------------------
252221
// HDR packing
253222
//-----------------------------------------------------------------------------

com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -353,50 +353,17 @@
353353
UNITY_INSTANCING_BUFFER_END(unity_Builtins2)
354354
#endif
355355

356+
// TODO: What about UNITY_DONT_INSTANCE_OBJECT_MATRICES for DOTS?
356357
#if defined(UNITY_DOTS_INSTANCING_ENABLED)
357-
UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata)
358-
UNITY_DOTS_INSTANCED_PROP(float4x4, unity_ObjectToWorld)
359-
UNITY_DOTS_INSTANCED_PROP(float4x4, unity_WorldToObject)
360-
UNITY_DOTS_INSTANCED_PROP(float4, unity_LODFade)
361-
UNITY_DOTS_INSTANCED_PROP(float4, unity_WorldTransformParams)
362-
UNITY_DOTS_INSTANCED_PROP(float4, unity_RenderingLayer)
363-
UNITY_DOTS_INSTANCED_PROP(float4, unity_LightmapST)
364-
UNITY_DOTS_INSTANCED_PROP(float4, unity_DynamicLightmapST)
365-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAr)
366-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAg)
367-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHAb)
368-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBr)
369-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg)
370-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb)
371-
UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC)
372-
UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion)
373-
UNITY_DOTS_INSTANCED_PROP(float4x4, unity_MatrixPreviousM)
374-
UNITY_DOTS_INSTANCED_PROP(float4x4, unity_MatrixPreviousMI)
375-
UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata)
376-
377-
#define unity_LODFade UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_LODFade)
378-
#define unity_WorldTransformParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_WorldTransformParams)
379-
#define unity_RenderingLayer UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_RenderingLayer)
380-
#define unity_LightmapST UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_LightmapST)
381-
#define unity_DynamicLightmapST UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_DynamicLightmapST)
382-
#define unity_SHAr UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAr)
383-
#define unity_SHAg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAg)
384-
#define unity_SHAb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHAb)
385-
#define unity_SHBr UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBr)
386-
#define unity_SHBg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBg)
387-
#define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb)
388-
#define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC)
389-
#define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion)
390-
#define unity_MatrixPreviousM UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_MatrixPreviousM)
391-
#define unity_MatrixPreviousMI UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_MatrixPreviousMI)
392-
393-
// Redirect GetRawUnityObjectToWorld etc to load from DOTS instancing buffers, which should also make UNITY_MATRIX_M work correctly
394-
float4x4 GetRawUnityObjectToWorldDotsInstanced() { return UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_ObjectToWorld); }
395-
float4x4 GetRawUnityWorldToObjectDotsInstanced() { return UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4x4, Metadata_unity_WorldToObject); }
396-
397-
#define GetRawUnityObjectToWorld GetRawUnityObjectToWorldDotsInstanced
398-
#define GetRawUnityWorldToObject GetRawUnityWorldToObjectDotsInstanced
399-
358+
#undef UNITY_MATRIX_M
359+
#undef UNITY_MATRIX_I_M
360+
#ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
361+
#define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_DOTS_INSTANCED_PROP(float4x4, unity_ObjectToWorld))
362+
#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_DOTS_INSTANCED_PROP(float4x4, unity_WorldToObject))
363+
#else
364+
#define UNITY_MATRIX_M UNITY_ACCESS_DOTS_INSTANCED_PROP(float4x4, unity_ObjectToWorld)
365+
#define UNITY_MATRIX_I_M UNITY_ACCESS_DOTS_INSTANCED_PROP(float4x4, unity_WorldToObject)
366+
#endif
400367
#else
401368

402369
#ifndef UNITY_DONT_INSTANCE_OBJECT_MATRICES

com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl"
88

99
#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
1111
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl"
1212

1313
// CAUTION:
@@ -324,14 +324,55 @@ float4x4 GetRawUnityWorldToObject() { return unity_WorldToObject; }
324324
#define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld())
325325
#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject())
326326

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+
327331
// This define allow to tell to unity instancing that we will use our camera relative functions (ApplyCameraTranslationToMatrix and ApplyCameraTranslationToInverseMatrix) for the model view matrix
328332
#define MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
329333
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
330334

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
335376

336377
// Define View/Projection matrix macro
337378
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl"

0 commit comments

Comments
 (0)