Skip to content

New functionality that supports compile time branching based on user created dropdowns.#4137

Merged
marctem merged 32 commits into
masterfrom
sg/surfgrad/dropdowns
Apr 29, 2021
Merged

New functionality that supports compile time branching based on user created dropdowns.#4137
marctem merged 32 commits into
masterfrom
sg/surfgrad/dropdowns

Conversation

@russoh
Copy link
Copy Markdown
Contributor

@russoh russoh commented Apr 8, 2021

Please read the Contributing guide before making a PR.

Checklist for PR maker

  • Have you added a backport label (if needed)? For example, the need-backport-* label. After you backport the PR, the label changes to backported-*.
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR. If you do add documentation, make sure to add the relevant Graphics Docs team member as a reviewer of the PR. If you are not sure which person to add, see the Docs team contacts sheet.
  • Have you added a graphic test for your PR (if needed)? When you add a new feature, or discover a bug that tests don't cover, please add a graphic test.

Purpose of this PR

This PR adds support for branching based on user created dropdowns.

Motivation for work: https://docs.google.com/document/d/1XeUfc2MauivBYx82V68c_u2aQBZJxt2h9VRVu9yemGY/edit

The workflow, and UI for creating dropdowns is very similar to the behavior for working with keyword enums. Dropdowns are a new type of blackboard property, where the user can specify a list of options, and a default. All of the scoping, and keyword specific controls are stripped down, so it is simpler than keywords. The user can drag a dropdown property out onto the graph canvas, which will create a corresponding branch node, with slots for each option.

The key distinction for dropdowns - dropdowns are exposed on the UI of subgraph node instances, where those subgraphs have defined dropdowns. This allows the user to pick the desired branch per subgraph instance from the parent graph. This is all resolved at compile time.

https://jira.unity3d.com/browse/GSG-354


Testing status

Manual testing:

Utilized in Surface Gradient example "Sphere Dropdown And Connection Testing":
https://github.cds.internal.unity3d.com/unity/surfgrad-examples

Automated tests:

Graphics/TestProjects/ShaderGraph/UtilityNodes.unity : Dropdowns
https://jira.unity3d.com/browse/GSG-396


Comments to reviewers

Basic video of this in action:
SubgraphDropdown.zip

For testing, use instructions here for getting the compatible build: https://github.cds.internal.unity3d.com/unity/surfgrad-examples/blob/master/README.md

IMPORTANT - you cannot create more than dropdown using the conventional + via the blackboard. If you do this, any secondarily created properties will not be visible, and the graph will break. You MUST make new properties by duplicating the first dropdown using Ctrl-D, until this bug has been addressed. The issue also affects keyword enums, and will be addressed by a separate PR as it is common to both.

I will merge in latest of master periodically to get ready for final merge.

Version numbers of serialized data will need bumping between landing of PRs.

@russoh russoh changed the title New functionality that adds compile time resolved branching via user configurable dropdowns. New functionality that supports compile time branching based on user created dropdowns. Apr 8, 2021
@russoh russoh requested review from a user, Nightmask3, alindmanUnity and cdxntchou April 9, 2021 00:16
russoh added 12 commits April 12, 2021 16:44
Fix undo for dropdowns.
Limit dropdowns to subgraphs.
Reordering dropdowns does not affect subgraph node selection.
Fix id assignment for keywords (should find unused id, not use current list index).
Fix default dropdown name.
Fix searcher for dropdowns.
… into sg/surfgrad/dropdowns

# Conflicts:
#	com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldView.cs
#	com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs
#	com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderInputPropertyDrawer.cs
#	com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
@russoh russoh marked this pull request as ready for review April 15, 2021 15:14
@russoh russoh requested a review from a team as a code owner April 15, 2021 15:14
@ghost
Copy link
Copy Markdown

ghost commented Apr 15, 2021

Copy link
Copy Markdown
Contributor

@joshua-davis joshua-davis left a comment

Choose a reason for hiding this comment

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

One other small note: When you re-order the items in the keywords the Default value seems to point to whatever's at the index, not the item by name. That is if you have:
{ItemA, ItemB, ItemC} and the default is currently ItemB and you then reorder to {ItemA, ItemC, ItemB} then the default will now be ItemC (both index 1). Is this intended? Not a big deal either way, just something I noticed.

Comment thread com.unity.shadergraph/Editor/Data/Graphs/ShaderDropdown.cs Outdated
Comment thread com.unity.shadergraph/Editor/Data/Graphs/ShaderDropdown.cs Outdated
Comment thread com.unity.shadergraph/Editor/Data/Nodes/Utility/DropdownNode.cs
Comment thread com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs
russoh added 2 commits April 22, 2021 11:41
Fix for preventing default dropdown value changing when reordering dropdown entries.
Add default else to dropdown code gen.
Comment thread com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs Outdated
Comment thread com.unity.shadergraph/Editor/Drawing/ViewModels/BlackboardViewModel.cs Outdated
Comment thread com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
Comment thread com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
}

{
sb.AppendLine("{");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: you could use sb.BlockScope here to clean this up a bit. In particular this becomes:

using(sb.BlockScope())
{
    var value = GetSlotValue(GetSlotIdForPermutation(new KeyValuePair<ShaderDropdown, int>(dropdown, i)), generationMode);
    sb.AppendLine(string.Format($"{GetVariableNameForSlot(OutputSlotId)} = {value};"));
}

Something I just noticed that I didn't before.

Copy link
Copy Markdown
Contributor

@joshua-davis joshua-davis left a comment

Choose a reason for hiding this comment

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

Small nit, but otherwise looks good

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

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

All issues found during my testing were addressed.

russoh added 3 commits April 26, 2021 10:09
… into sg/surfgrad/dropdowns

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
@russoh
Copy link
Copy Markdown
Contributor Author

russoh commented Apr 28, 2021

This one has already had a full green test panel on Shader Graph ABV with the changes specific to this branch:
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Fsurfgrad%252Fdropdowns/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_trunk/6477815/job

… into sg/surfgrad/dropdowns

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
@russoh
Copy link
Copy Markdown
Contributor Author

russoh commented Apr 28, 2021

Copy link
Copy Markdown

@cdxntchou cdxntchou left a comment

Choose a reason for hiding this comment

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

Should probably remove the unnecessary versioning changes. The rest looks good!

Comment thread com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs
Comment thread com.unity.shadergraph/Editor/Data/Legacy/AbstractMaterialNode0.cs Outdated
Comment thread com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs Outdated
Comment thread com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs
Comment thread com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs
keywordGuidMap[input0.m_Guid.m_GuidSerialized] = keyword;
}

foreach (var serializedDropdown in graphData0.m_SerializedDropdowns)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to handle dropdowns in old master node graphs coming in? Are we backporting dropdowns to master nodes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a good question, should definitely get clarity on that flow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we are not (which I would hope at this point tbh), then all the graphdata0 or abstractmaterialnode0 stuff should be unnecessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cheers, I have removed this now.


public string m_KeywordGuidSerialized;

public string m_DropdownGuidSerialized;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again, will dropdowns be ported to old master nodes? If no, not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also removed, cheers.


public List<SerializationHelper.JSONSerializedElement> m_SerializedKeywords;

public List<SerializationHelper.JSONSerializedElement> m_SerializedDropdowns;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if not backporting, unnecessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this one.

@russoh russoh requested review from cdxntchou and removed request for alindmanUnity April 28, 2021 23:27
@russoh
Copy link
Copy Markdown
Contributor Author

russoh commented Apr 29, 2021

All test have now passed. I will only pull to resolve the Changelog conflict.

russoh added 2 commits April 29, 2021 11:56
… into sg/surfgrad/dropdowns

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
… into sg/surfgrad/dropdowns

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
@marctem marctem merged commit e97f16e into master Apr 29, 2021
@marctem marctem deleted the sg/surfgrad/dropdowns branch April 29, 2021 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants