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 @@ -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

Expand Down
16 changes: 16 additions & 0 deletions com.unity.shadergraph/Editor/Drawing/Blackboard/SGBlackboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SGBlackboard : GraphSubWindow, ISGControlledElement<BlackboardController>
VisualElement m_ScrollBoundaryBottom;
VisualElement m_BottomResizer;
TextField m_PathLabelTextField;
public VisualElement m_VariantExceededHelpBox;

// --- Begin ISGControlledElement implementation
public void OnControllerChanged(ref SGControllerChangedEvent e)
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ void CopyCategory(GraphData graphData)
public Action<GraphData> 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<GraphData> modifyGraphDataAction => Empty;

void Empty(GraphData graphData)
{
}
}

class BlackboardController : SGViewController<GraphData, BlackboardViewModel>
{
// Type changes (adds/removes of Types) only happen after a full assembly reload so its safe to make this static
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions com.unity.shadergraph/Editor/Drawing/Views/HelpBoxRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents the duplicate shader from being put in the same file.

}

foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down