diff --git a/com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl index 9dfccc03776..e9b2d49e805 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl @@ -150,14 +150,21 @@ static const uint kDOTSInstancingFlagCameraMotion = (1 << 2); // Object uses static const uint kDOTSInstancingFlagHasPrevPosition = (1 << 3); // Object has a separate previous frame position vertex streams (e.g. for deformed objects) static const uint kDOTSInstancingFlagMainLightEnabled = (1 << 4); // Object should receive direct lighting from the main light (e.g. light not baked into lightmap) +static DOTSVisibleData unity_SampledDOTSVisibleData; + +void SetupDOTSVisibleInstancingData() +{ + unity_SampledDOTSVisibleData = unity_DOTSVisibleInstances[unity_InstanceID]; +} + uint GetDOTSInstanceIndex() { - return unity_DOTSVisibleInstances[unity_InstanceID].VisibleData.x; + return unity_SampledDOTSVisibleData.VisibleData.x; } int GetDOTSInstanceCrossfadeSnorm8() { - return unity_DOTSVisibleInstances[unity_InstanceID].VisibleData.y; + return unity_SampledDOTSVisibleData.VisibleData.y; } bool IsDOTSInstancedProperty(uint metadata) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl index 139bc7e6297..555df8d8eb9 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl @@ -238,6 +238,12 @@ #define UNITY_ACCESS_INSTANCED_PROP(arr, var) var #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl" + #if defined(UNITY_SETUP_INSTANCE_ID) + #undef UNITY_SETUP_INSTANCE_ID + #define UNITY_SETUP_INSTANCE_ID(input) {\ + DEFAULT_UNITY_SETUP_INSTANCE_ID(input);\ + SetupDOTSVisibleInstancingData();} + #endif #else #define UNITY_INSTANCING_BUFFER_START(buf) UNITY_INSTANCING_CBUFFER_SCOPE_BEGIN(UnityInstancing_##buf) struct {