Skip to content

[ShaderGraph][2021.2][Backport] Ensure blackboard ordering of subgraph properties on subgraph node #5716

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
Sep 17, 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
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a serialization bug wrt PVT property flags when using subgraphs. This fixes SRP batcher compatibility.
- Fixed an incorrect direction transform from view to world space [1365186]
- Fixed the appearance (wrong text color, and not wrapped) of a warning in Node Settings [1365780]
- Fixed the ordering of inputs on a SubGraph node to match the properties on the blackboard of the subgraph itself [1366052]

## [11.0.0] - 2020-10-21

Expand Down
25 changes: 22 additions & 3 deletions com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace UnityEditor.ShaderGraph
{
[ExcludeFromPreset]
[ScriptedImporter(28, Extension, -905)]
[ScriptedImporter(29, Extension, -905)]
class ShaderSubGraphImporter : ScriptedImporter
{
public const string Extension = "shadersubgraph";
Expand Down Expand Up @@ -281,6 +281,24 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp
}
}

// Need to order the properties so that they are in the same order on a subgraph node in a shadergraph
// as they are in the blackboard for the subgraph itself. The (blackboard) categories keep that ordering,
// so traverse those and add those items to the ordered properties list. Needs to be used to set up the
// function _and_ to write out the final asset data so that the function call parameter order matches as well.
var orderedProperties = new List<AbstractShaderProperty>();
var propertiesList = graph.properties.ToList();
foreach (var category in graph.categories)
{
foreach (var child in category.Children)
{
var prop = propertiesList.Find(p => p.guid == child.guid);
orderedProperties.Add(prop);
}
}

// If we are importing an older file that has not had categories generated for it yet, include those now.
orderedProperties.AddRange(graph.properties.Except(orderedProperties));

// provide top level subgraph function
// NOTE: actual concrete precision here shouldn't matter, it's irrelevant when building the subgraph asset
registry.ProvideFunction(asset.functionName, asset.subGraphGraphPrecision, ConcretePrecision.Single, sb =>
Expand All @@ -290,7 +308,7 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp

// Generate the arguments... first INPUTS
var arguments = new List<string>();
foreach (var prop in graph.properties)
foreach (var prop in orderedProperties)
{
// apply fallback to the graph default precision (but don't convert to concrete)
// this means "graph switchable" properties will use the precision token
Expand Down Expand Up @@ -388,7 +406,8 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp
prop.OverrideGuid(namespaceId, nameId + "_Guid_" + i);
}
}
asset.WriteData(graph.properties, graph.keywords, graph.dropdowns, collector.properties, outputSlots, graph.unsupportedTargets);

asset.WriteData(orderedProperties, graph.keywords, graph.dropdowns, collector.properties, outputSlots, graph.unsupportedTargets);
outputSlots.Dispose();
}

Expand Down