Skip to content

Avoid using duplicate names when creating new sublayers in graphics compositor #1288

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 2 commits into from
Jul 16, 2020
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
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Improved robustness of normal mapping when scale is 0, and mapping is extreme (normals in or below the tangent plane).
- Fixed rendering breaking when disabling tonemapping in the frame settings.
- Fixed issue with serialization of exposure modes in volume profiles not being consistent between HDRP versions (case 1261385).
- Fixed issue with duplicate names in newly created sub-layers in the graphics compositor (case 1263093).

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,62 @@ public void AddInputFilterAtLayer(CompositionFilter filter, int index)
m_InputLayers[index].AddInputFilter(filter);
}

int GetBaseLayerForSubLayerAtIndex(int index)
{
int baseIndex = 0;
index = (index > m_InputLayers.Count - 1) ? m_InputLayers.Count - 1 : index;
for (int i = index; i >= 0; --i)
{
if (m_InputLayers[i].outputTarget == CompositorLayer.OutputTarget.CompositorLayer)
{
baseIndex = i;
break;
}
}
return baseIndex;
}

static string GetSubLayerName(int count)
{
if (count == 0)
{
return "New SubLayer";
}
else
{
return $"New SubLayer ({count + 1})";
}
}

public string GetNewSubLayerName(int index, CompositorLayer.LayerType type = CompositorLayer.LayerType.Camera)
{
// First find the base layer
int baseIndex = GetBaseLayerForSubLayerAtIndex(index - 1);

// Get a candidate name and check if it already exists
int count = 0;
string candidateName = GetSubLayerName(count);
int i = baseIndex + 1;
while (i < m_InputLayers.Count && m_InputLayers[i].outputTarget != CompositorLayer.OutputTarget.CompositorLayer)
{
if (m_InputLayers[i].name == candidateName)
{
// If this candidate name exists, get the next one and start again
candidateName = GetSubLayerName(++count);
i = baseIndex + 1;
}
else
{
++i;
}
}

return candidateName;
}

public void AddNewLayer(int index, CompositorLayer.LayerType type = CompositorLayer.LayerType.Camera)
{
var newLayer = CompositorLayer.CreateStackLayer(type, "New SubLayer");
var newLayer = CompositorLayer.CreateStackLayer(type, GetNewSubLayerName(index, type));

if (index >= 0 && index < m_InputLayers.Count)
{
Expand Down