Skip to content

Commit e2f51a3

Browse files
Antoine Lelievresebastienlagarde
authored andcommitted
[HDRP] Improve decal performances when they use different material and the same draw order. #6303
1 parent 0c57486 commit e2f51a3

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- Fixed Lens Flare visible when being behind a camera with Panini Projection on (case 1370214)
2424
- Fixed the ray tracing acceleration structure build marker not being included in the ray tracing stats (case 1379383).
2525
- Fixed alpha channel display in color picker in Local Volumetric Fog component (the alpha is not used for the fog) (case 1381267).
26+
- Fixed default numbder of physically based sky bounce from 8 to 3
27+
- Fixed decal performances when they use different material and the same draw order.
2628

2729
## [12.1.2] - 2021-10-22
2830

@@ -51,7 +53,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5153
- Fixed light unit conversion after changing mid gray value.
5254
- Fixed Focus distance in path traced depth of field now takes into account the focus mode setting (volume vs camera).
5355
- Fixed stencil buffer resolve when MSAA is enabled so that OR operator is used instead of picking the last sample.
54-
- Fixed default numbder of physically based sky bounce from 8 to 3
5556

5657
### Changed
5758
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.

com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,23 @@ public void UpdateCachedData(DecalHandle handle, DecalProjector decalProjector)
492492
m_CachedFadeFactor[index] = data.fadeFactor;
493493
m_CachedDecalLayerMask[index] = data.decalLayerMask;
494494

495+
UpdateCachedDrawOrder();
496+
495497
UpdateJobArrays(index, decalProjector);
496498
}
497499

500+
public void UpdateCachedDrawOrder()
501+
{
502+
if (this.m_Material.HasProperty(HDShaderIDs._DrawOrder))
503+
{
504+
m_CachedDrawOrder = this.m_Material.GetInt(HDShaderIDs._DrawOrder);
505+
}
506+
else
507+
{
508+
m_CachedDrawOrder = 0;
509+
}
510+
}
511+
498512
// Update memory allocation and assign decal handle, then update cached data
499513
public DecalHandle AddDecal(int materialID, DecalProjector decalProjector)
500514
{
@@ -821,20 +835,7 @@ public int Count
821835
}
822836
}
823837

824-
public int DrawOrder
825-
{
826-
get
827-
{
828-
if (this.m_Material.HasProperty(HDShaderIDs._DrawOrder))
829-
{
830-
return this.m_Material.GetInt(HDShaderIDs._DrawOrder);
831-
}
832-
else
833-
{
834-
return 0;
835-
}
836-
}
837-
}
838+
public int DrawOrder => m_CachedDrawOrder;
838839

839840
private List<Matrix4x4[]> m_DecalToWorld = new List<Matrix4x4[]>();
840841
private List<Matrix4x4[]> m_NormalToWorld = new List<Matrix4x4[]>();
@@ -845,6 +846,7 @@ public int DrawOrder
845846
private int m_NumResults = 0;
846847
private int m_InstanceCount = 0;
847848
private int m_DecalsCount = 0;
849+
private int m_CachedDrawOrder = 0;
848850
private Vector2[] m_CachedDrawDistances = new Vector2[kDecalBlockSize]; // x - draw distance, y - fade scale
849851
private Vector2[] m_CachedAngleFade = new Vector2[kDecalBlockSize]; // x - scale fade, y - bias fade
850852
private Vector4[] m_CachedUVScaleBias = new Vector4[kDecalBlockSize]; // xy - scale, zw bias
@@ -1100,10 +1102,12 @@ public void CreateDrawData()
11001102
m_DecalSetsRenderList.Clear();
11011103
foreach (var pair in m_DecalSets)
11021104
{
1105+
pair.Value.UpdateCachedDrawOrder();
1106+
11031107
if (pair.Value.IsDrawn())
11041108
{
11051109
int insertIndex = 0;
1106-
while ((insertIndex < m_DecalSetsRenderList.Count) && (pair.Value.DrawOrder >= m_DecalSetsRenderList[insertIndex].DrawOrder))
1110+
while ((insertIndex < m_DecalSetsRenderList.Count) && (pair.Value.DrawOrder > m_DecalSetsRenderList[insertIndex].DrawOrder))
11071111
{
11081112
insertIndex++;
11091113
}

0 commit comments

Comments
 (0)