Skip to content

Commit c581435

Browse files
amsXYZEvergreen
authored andcommitted
Ensure _DecalLayerMaskFromDecal is allocated with enough size for instancing
This PR fixes an issue where the following error was being spawned on the console when enabling the instancing property of a *Decal* `Material` at runtime: ```"Property (_DecalLayerMaskFromDecal) exceeds previous array size (250 vs 1). Cap to previous size. Restart Unity to recreate the arrays."``` This happened because this `MaterialPropertyBlock` property only gets reallocated at domain-reload, which creates an issue when passing from regular drawing (size `1`) to instanced drawing (size `250`) at runtime.
1 parent cf2a1ac commit c581435

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void Execute()
207207
instanceIndex++;
208208

209209
int instanceCount = instanceIndex - instanceStart;
210-
bool isReachedMaximumBatchSize = instanceCount >= 250;
210+
bool isReachedMaximumBatchSize = instanceCount >= DecalDrawSystem.MaxBatchSize;
211211
if (isReachedMaximumBatchSize)
212212
{
213213
subCalls[subCallIndex++] = new DecalSubDrawCall()

Packages/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalDrawSystem.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace UnityEngine.Rendering.Universal
99
/// </summary>
1010
internal abstract class DecalDrawSystem
1111
{
12+
readonly static internal uint MaxBatchSize = 250;
13+
1214
protected DecalEntityManager m_EntityManager;
1315
private Matrix4x4[] m_WorldToDecals;
1416
private Matrix4x4[] m_NormalToDecals;
@@ -21,9 +23,9 @@ public DecalDrawSystem(string sampler, DecalEntityManager entityManager)
2123
{
2224
m_EntityManager = entityManager;
2325

24-
m_WorldToDecals = new Matrix4x4[250];
25-
m_NormalToDecals = new Matrix4x4[250];
26-
m_DecalLayerMasks = new float[250];
26+
m_WorldToDecals = new Matrix4x4[MaxBatchSize];
27+
m_NormalToDecals = new Matrix4x4[MaxBatchSize];
28+
m_DecalLayerMasks = new float[MaxBatchSize];
2729

2830
m_Sampler = new ProfilingSampler(sampler);
2931
}

Packages/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalEntityManager.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ private int CreateChunkIndex(Material material)
283283
{
284284
var propertyBlock = new MaterialPropertyBlock();
285285

286-
// In order instanced and non instanced rendering to work with _NormalToWorld
287-
// We need to make sure array is created with maximum size
288-
propertyBlock.SetMatrixArray("_NormalToWorld", new Matrix4x4[250]);
286+
// In order instanced and non instanced rendering to work with _NormalToWorld and _DecalLayerMaskFromDecal
287+
// We need to make sure the array are created with maximum size
288+
propertyBlock.SetMatrixArray("_NormalToWorld", new Matrix4x4[DecalDrawSystem.MaxBatchSize]);
289+
propertyBlock.SetFloatArray("_DecalLayerMaskFromDecal", new float[DecalDrawSystem.MaxBatchSize]);
289290

290291
entityChunks.Add(new DecalEntityChunk() { material = material });
291292
cachedChunks.Add(new DecalCachedChunk()

0 commit comments

Comments
 (0)