Skip to content

[HDRP] Improve decal performances when they use different material and the same draw order. #6303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed range fields for depth of field (case 1376609).
- Fixed exception on DLSS when motion vectors are disabled (case # 1377986).
- Fixed SpeedTree graph compatibility by adding raytracing quality keyword to provide a safe path.
- Fixed decal performances when they use different material and the same draw order.

### Changed
- Optimizations for the physically based depth of field.
- Converted most TGA textures files to TIF to reduce the size of HDRP material samples.
- Changed sample scene in HDRP material samples: add shadow transparency (raster, ray-traced, path-traced).
- Support for encoded HDR cubemaps, configurable via the HDR Cubemap Encoding project setting.
- The rendering order of decals that have a similar draw order value was modified. The new order should be the reverse of the previous order.

## [13.1.1] - 2021-10-04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,23 @@ public void UpdateCachedData(DecalHandle handle, DecalProjector decalProjector)
m_CachedFadeFactor[index] = data.fadeFactor;
m_CachedDecalLayerMask[index] = data.decalLayerMask;

UpdateCachedDrawOrder();

UpdateJobArrays(index, decalProjector);
}

public void UpdateCachedDrawOrder()
{
if (this.m_Material.HasProperty(HDShaderIDs._DrawOrder))
{
m_CachedDrawOrder = this.m_Material.GetInt(HDShaderIDs._DrawOrder);
}
else
{
m_CachedDrawOrder = 0;
}
}

// Update memory allocation and assign decal handle, then update cached data
public DecalHandle AddDecal(int materialID, DecalProjector decalProjector)
{
Expand Down Expand Up @@ -821,20 +835,7 @@ public int Count
}
}

public int DrawOrder
{
get
{
if (this.m_Material.HasProperty(HDShaderIDs._DrawOrder))
{
return this.m_Material.GetInt(HDShaderIDs._DrawOrder);
}
else
{
return 0;
}
}
}
public int DrawOrder => m_CachedDrawOrder;

private List<Matrix4x4[]> m_DecalToWorld = new List<Matrix4x4[]>();
private List<Matrix4x4[]> m_NormalToWorld = new List<Matrix4x4[]>();
Expand All @@ -845,6 +846,7 @@ public int DrawOrder
private int m_NumResults = 0;
private int m_InstanceCount = 0;
private int m_DecalsCount = 0;
private int m_CachedDrawOrder = 0;
private Vector2[] m_CachedDrawDistances = new Vector2[kDecalBlockSize]; // x - draw distance, y - fade scale
private Vector2[] m_CachedAngleFade = new Vector2[kDecalBlockSize]; // x - scale fade, y - bias fade
private Vector4[] m_CachedUVScaleBias = new Vector4[kDecalBlockSize]; // xy - scale, zw bias
Expand Down Expand Up @@ -1100,10 +1102,12 @@ public void CreateDrawData()
m_DecalSetsRenderList.Clear();
foreach (var pair in m_DecalSets)
{
pair.Value.UpdateCachedDrawOrder();

if (pair.Value.IsDrawn())
{
int insertIndex = 0;
while ((insertIndex < m_DecalSetsRenderList.Count) && (pair.Value.DrawOrder >= m_DecalSetsRenderList[insertIndex].DrawOrder))
while ((insertIndex < m_DecalSetsRenderList.Count) && (pair.Value.DrawOrder > m_DecalSetsRenderList[insertIndex].DrawOrder))
{
insertIndex++;
}
Expand Down