Skip to content
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 @@ -18,6 +18,7 @@ The version number for this package has increased due to a version update of a r
- Fixed ShaderGraph HDRP master preview disappearing for a few seconds when graph is modified [1330289] (https://issuetracker.unity3d.com/issues/shadergraph-hdrp-main-preview-is-invisible-until-moved)
- Fixed noise nodes to use a deterministic integer hash, instead of platform dependent floating point hashes [1156544]
- Fixed the appearance (wrong text color, and not wrapped) of a warning in Node Settings [1356725] (https://issuetracker.unity3d.com/product/unity/issues/guid/1356725/)
- Fixed the ordering of inputs on a SubGraph node to match the properties on the blackboard of the subgraph itself [1354463]

## [12.0.0] - 2021-01-11

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