diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 31df09a876b..c3153ba3aa8 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -26,6 +26,7 @@ The version number for this package has increased due to a version update of a r - Fixed an issue where ShaderGraph "view shader" commands were opening in individual windows, and blocking Unity from closing [1367188] - Improved screenspace position accuracy in the fragment shader by using VPOS [1352662] (https://issuetracker.unity3d.com/issues/shadergraph-dither-node-results-in-artifacts-when-far-from-origin-caused-by-screen-position-breaking-down) - Fixed the node searcher results to prefer names over synonyms [1366058] + - Fixed how graph errors were displayed when variant limits were reached [1355815] ## [12.0.0] - 2021-01-11 diff --git a/com.unity.shadergraph/Editor/Drawing/Blackboard/SGBlackboard.cs b/com.unity.shadergraph/Editor/Drawing/Blackboard/SGBlackboard.cs index 48a23b803e5..72af425c692 100644 --- a/com.unity.shadergraph/Editor/Drawing/Blackboard/SGBlackboard.cs +++ b/com.unity.shadergraph/Editor/Drawing/Blackboard/SGBlackboard.cs @@ -37,6 +37,7 @@ class SGBlackboard : GraphSubWindow, ISGControlledElement VisualElement m_ScrollBoundaryBottom; VisualElement m_BottomResizer; TextField m_PathLabelTextField; + public VisualElement m_VariantExceededHelpBox; // --- Begin ISGControlledElement implementation public void OnControllerChanged(ref SGControllerChangedEvent e) @@ -47,6 +48,21 @@ public void OnControllerEvent(SGControllerEvent e) { } + public void SetCurrentVariantUsage(int currentVariantCount, int maxVariantCount) + { + if (currentVariantCount < maxVariantCount && m_VariantExceededHelpBox != null) + { + RemoveAt(0); + m_VariantExceededHelpBox = null; + } + else if (maxVariantCount <= currentVariantCount && m_VariantExceededHelpBox == null) + { + var helpBox = HelpBoxRow.CreateVariantLimitHelpBox(currentVariantCount, maxVariantCount); + m_VariantExceededHelpBox = helpBox; + Insert(0, helpBox); + } + } + public BlackboardController controller { get => m_Controller; diff --git a/com.unity.shadergraph/Editor/Drawing/Controllers/BlackboardController.cs b/com.unity.shadergraph/Editor/Drawing/Controllers/BlackboardController.cs index b8c9b799dd3..e27a7265c97 100644 --- a/com.unity.shadergraph/Editor/Drawing/Controllers/BlackboardController.cs +++ b/com.unity.shadergraph/Editor/Drawing/Controllers/BlackboardController.cs @@ -359,6 +359,25 @@ void CopyCategory(GraphData graphData) public Action modifyGraphDataAction => CopyCategory; } + class ShaderVariantLimitAction : IGraphDataAction + { + public int currentVariantCount { get; set; } = 0; + public int maxVariantCount { get; set; } = 0; + + public ShaderVariantLimitAction(int currentVariantCount, int maxVariantCount) + { + this.maxVariantCount = maxVariantCount; + this.currentVariantCount = currentVariantCount; + } + + // There's no action actually performed on the graph, but we need to implement this as a valid function + public Action modifyGraphDataAction => Empty; + + void Empty(GraphData graphData) + { + } + } + class BlackboardController : SGViewController { // Type changes (adds/removes of Types) only happen after a full assembly reload so its safe to make this static @@ -665,6 +684,9 @@ protected override void ModelChanged(GraphData graphData, IGraphDataAction chang if (blackboardCategory != null) graphView?.AddToSelectionNoUndoRecord(blackboardCategory.blackboardCategoryView); break; + case ShaderVariantLimitAction shaderVariantLimitAction: + blackboard.SetCurrentVariantUsage(shaderVariantLimitAction.currentVariantCount, shaderVariantLimitAction.maxVariantCount); + break; } // Lets all event handlers this controller owns/manages know that the model has changed diff --git a/com.unity.shadergraph/Editor/Drawing/Views/HelpBoxRow.cs b/com.unity.shadergraph/Editor/Drawing/Views/HelpBoxRow.cs index 81cbe7c58e5..10dc3657f29 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/HelpBoxRow.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/HelpBoxRow.cs @@ -47,6 +47,19 @@ public HelpBoxRow(MessageType type) hierarchy.Add(container); } + public static VisualElement CreateVariantLimitHelpBox(int currentVariantCount, int maxVariantCount) + { + var messageType = MessageType.Error; + HelpBoxRow help = new HelpBoxRow(messageType); + var label = new Label("Variant limit exceeded: Hover for more info") + { + tooltip = ShaderKeyword.kVariantLimitWarning, + name = "message-" + (messageType == MessageType.Warning ? "warn" : "info") + }; + help.Add(label); + return help; + } + public static VisualElement TryGetDeprecatedHelpBoxRow(string deprecatedTypeName, Action upgradeAction, string deprecationText = null, string buttonText = null, string labelText = null, MessageType messageType = MessageType.Warning) { if (deprecationText == null) diff --git a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs index 7b3ef3a69df..5463c4f8b64 100644 --- a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs +++ b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs @@ -158,6 +158,11 @@ void BuildShader() } } string path = AssetDatabase.GUIDToAssetPath(m_GraphData.assetGuid); + + // Send an action about our current variant usage. This will either add or clear a warning if it exists + var action = new ShaderVariantLimitAction(shaderKeywords.permutations.Count, ShaderGraphPreferences.variantLimit); + m_GraphData.owner?.graphDataStore?.Dispatch(action); + if (shaderKeywords.permutations.Count > ShaderGraphPreferences.variantLimit) { string graphName = ""; @@ -172,6 +177,8 @@ void BuildShader() m_ConfiguredTextures = shaderProperties.GetConfiguredTextures(); m_Builder.AppendLines(ShaderGraphImporter.k_ErrorShader.Replace("Hidden/GraphErrorShader2", graphName)); + // Don't continue building the shader, we've already built an error shader. + return; } foreach (var activeNode in activeNodeList.OfType()) diff --git a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs index 1467b9b70a9..c947b320780 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs @@ -292,7 +292,10 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp foreach (var child in category.Children) { var prop = propertiesList.Find(p => p.guid == child.guid); - orderedProperties.Add(prop); + // Not all properties in the category are actually on the graph. + // In particular, it seems as if keywords are not properties on sub-graphs. + if (prop != null) + orderedProperties.Add(prop); } }