Skip to content

Commit 8fefabd

Browse files
Nightmask3Kink3dsainarayan-cse
authored
[9.x.x] Shader Graph Internal Inspector (#173)
* Initial implementation * Remove Master Preview * Migrate blackboard field views * Migrate graph options * Inspectable StickyNotes * Handle other selectables * Fix for shader graph nodes not pasting at the cursor location * Revert "Fix for shader graph nodes not pasting at the cursor location" This reverts commit b18f4b1c8606286c757a27039b209884f9d20138. * Added comments * Reflection based data gathering for the inspector * Added property drawers and drawer registration with view to handle certain types * Added GraphSubWindow class and switched inspector over to it * fixed scrolling issues and single object selection * Added GetUnderlyingObject() to IInspectable GetUnderlyingObject() is used to let InspectorView get the actual object that backs whatever its currently inspecting, in order to retrieve data from it * Moved property drawer stuff to its own class file * Added float/slider property drawers * Removed ugly callback mess, running into issues with UI updating * Finished vector1 property drawer support * Finished porting blackboard to property drawer system * Removing exception for MaterialNodeView * Fixed compilation issues with merge Also removed BlackboardFieldKewordView and BlackboardFieldPropertyView * Added missing files from master * Fixed issue with undo/redo killing the blackboard property selection * Fixed issues with updating inspector Issues were with selection/deselection and undo/redo not triggering the inspector to update as it should * Added support for HDRP and removed old settings views for master nodes * updated changelog * Fixed softlock bug when connecting master nodes and making keywords * Converted unsafe cast to safe cast * converted is to equality check * Removed changes to master nodes to get more clean PR for inspector * Added master node views back for universal nodes * more fixes for PR cleanup * Fixing issue to prevent touching HD files in PR * Trying to reduce master branch delta * issues with CRLF vs LF * More cleanup for PR submission * undoing unrelated change to xr file * undoing change to xr file * not sure why it keeps undoing itself * more pre-PR cleanup * fixed weird styling issue with property rows * Fixing issue with scrollbars being visible on hidden inspector * Fixing issue with exception when boolean default changed * fixed issue with sampler state reference name not updating * Fixed a bunch of bugs and added support for property node views * removed code to handle min > max and vice versa for now * should handle reverse sliders * Fixed issue with slider property drawing * Fixed issue with min/max sliders * undoing change for PR cleanup * cleaned up files for PR * Added test to check if slider property range has min < max Also added code to PropertyNode to enforce that min will be lesser than max, and to change that value in graphs encountered * swapped values for min/max slider range test property * Added fix for slider behavior and graph sub-window serialization * Removed TODOs, separated property drawers into individual files Also cleaned up blackboard property selection persistence with undo/redo handling * Fixed up vector2 property drawer * addressing more review coments from Marc * removed commented code [skip ci] skip ci * removing unneeded access modifiers Co-authored-by: Matt Dean <[email protected]> Co-authored-by: Sai Narayan <[email protected]>
1 parent cc76463 commit 8fefabd

File tree

89 files changed

+4205
-1281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4205
-1281
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NUnit.Framework;
5+
using UnityEngine;
6+
using UnityEditor.Graphing;
7+
using UnityEditor.ShaderGraph.Internal;
8+
9+
namespace UnityEditor.ShaderGraph.UnitTests
10+
{
11+
[TestFixture]
12+
internal class PropertyTests
13+
{
14+
static string kGraphName = "Assets/CommonAssets/Graphs/Properties.shadergraph";
15+
GraphData m_Graph;
16+
17+
PropertyCollector m_Collector;
18+
19+
Dictionary<string, PreviewNode> m_TestNodes = new Dictionary<string, PreviewNode>();
20+
21+
[OneTimeSetUp]
22+
public void LoadGraph()
23+
{
24+
List<PropertyCollector.TextureInfo> lti;
25+
var lsadp = new List<string>();
26+
ShaderGraphImporter.GetShaderText(kGraphName, out lti, lsadp, out m_Graph);
27+
Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}");
28+
29+
m_Graph.ValidateGraph();
30+
31+
m_Collector = new PropertyCollector();
32+
m_Graph.CollectShaderProperties(m_Collector, GenerationMode.ForReals);
33+
}
34+
35+
[Test]
36+
public void SliderPropertyRangeMinLesserThanMax()
37+
{
38+
foreach(AbstractShaderProperty property in m_Collector.properties)
39+
{
40+
if (property is Vector1ShaderProperty vector1ShaderProperty && vector1ShaderProperty.floatType == FloatType.Slider)
41+
{
42+
Assert.IsTrue(vector1ShaderProperty.rangeValues.x < vector1ShaderProperty.rangeValues.y,
43+
"Slider property cannot have min be greater than max!");
44+
}
45+
}
46+
}
47+
}
48+
}

TestProjects/ShaderGraph/Assets/CommonAssets/Editor/PropertyTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"m_SerializedProperties": [
3+
{
4+
"typeInfo": {
5+
"fullName": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty"
6+
},
7+
"JSONnodeData": "{\n \"m_Guid\": {\n \"m_GuidSerialized\": \"d13f1c8f-912c-4202-88dd-1d81f762d260\"\n },\n \"m_Name\": \"FlippedSliderProperty\",\n \"m_DefaultReferenceName\": \"Vector1_829D8397\",\n \"m_OverrideReferenceName\": \"\",\n \"m_GeneratePropertyBlock\": true,\n \"m_Precision\": 0,\n \"m_GPUInstanced\": false,\n \"m_Hidden\": false,\n \"m_Value\": 1.0,\n \"m_FloatType\": 1,\n \"m_RangeValues\": {\n \"x\": 1.0,\n \"y\": -1.0\n }\n}"
8+
}
9+
],
10+
"m_SerializedKeywords": [],
11+
"m_SerializableNodes": [
12+
{
13+
"typeInfo": {
14+
"fullName": "UnityEditor.ShaderGraph.PropertyNode"
15+
},
16+
"JSONnodeData": "{\n \"m_GuidSerialized\": \"419f7fde-45d3-413d-a681-3f80de32bc31\",\n \"m_GroupGuidSerialized\": \"a0c9f82f-8f00-4690-8ef3-bf4079519d15\",\n \"m_Name\": \"Property\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": -551.0000610351563,\n \"y\": 283.0,\n \"width\": 190.00001525878907,\n \"height\": 34.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"FlippedSliderProperty\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": 0.0,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_PropertyGuidSerialized\": \"d13f1c8f-912c-4202-88dd-1d81f762d260\"\n}"
17+
},
18+
{
19+
"typeInfo": {
20+
"fullName": "UnityEditor.ShaderGraph.PreviewNode"
21+
},
22+
"JSONnodeData": "{\n \"m_GuidSerialized\": \"47df49fd-91a7-4c8a-8404-c3710b050632\",\n \"m_GroupGuidSerialized\": \"a0c9f82f-8f00-4690-8ef3-bf4079519d15\",\n \"m_Name\": \"Preview\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": -301.00006103515627,\n \"y\": 242.0,\n \"width\": 208.0,\n \"height\": 278.0\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.DynamicVectorMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"In\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"In\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n }\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.DynamicVectorMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Out\\\",\\n \\\"m_SlotType\\\": 1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Out\\\",\\n \\\"m_StageCapability\\\": 3,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n }\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_Width\": 208.0,\n \"m_Height\": 208.0\n}"
23+
},
24+
{
25+
"typeInfo": {
26+
"fullName": "UnityEditor.ShaderGraph.UnlitMasterNode"
27+
},
28+
"JSONnodeData": "{\n \"m_GuidSerialized\": \"faac5ed4-8a55-4c7e-a36f-e4380ae3593a\",\n \"m_GroupGuidSerialized\": \"00000000-0000-0000-0000-000000000000\",\n \"m_Name\": \"Unlit Master\",\n \"m_NodeVersion\": 0,\n \"m_DrawState\": {\n \"m_Expanded\": true,\n \"m_Position\": {\n \"serializedVersion\": \"2\",\n \"x\": 287.0,\n \"y\": 168.99998474121095,\n \"width\": 200.00001525878907,\n \"height\": 197.00001525878907\n }\n },\n \"m_SerializableSlots\": [\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.PositionMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 9,\\n \\\"m_DisplayName\\\": \\\"Vertex Position\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Position\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.NormalMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 10,\\n \\\"m_DisplayName\\\": \\\"Vertex Normal\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Normal\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.TangentMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 11,\\n \\\"m_DisplayName\\\": \\\"Vertex Tangent\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Vertex Tangent\\\",\\n \\\"m_StageCapability\\\": 1,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_Space\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.ColorRGBMaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 0,\\n \\\"m_DisplayName\\\": \\\"Color\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Color\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": {\\n \\\"x\\\": 0.7353569269180298,\\n \\\"y\\\": 0.7353569269180298,\\n \\\"z\\\": 0.7353569269180298\\n },\\n \\\"m_DefaultValue\\\": {\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0\\n },\\n \\\"m_Labels\\\": [\\n \\\"X\\\",\\n \\\"Y\\\",\\n \\\"Z\\\"\\n ],\\n \\\"m_ColorMode\\\": 0\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 7,\\n \\\"m_DisplayName\\\": \\\"Alpha\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"Alpha\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": 1.0,\\n \\\"m_DefaultValue\\\": 1.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\": \"UnityEditor.ShaderGraph.Vector1MaterialSlot\"\n },\n \"JSONnodeData\": \"{\\n \\\"m_Id\\\": 8,\\n \\\"m_DisplayName\\\": \\\"AlphaClipThreshold\\\",\\n \\\"m_SlotType\\\": 0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_Hidden\\\": false,\\n \\\"m_ShaderOutputName\\\": \\\"AlphaClipThreshold\\\",\\n \\\"m_StageCapability\\\": 2,\\n \\\"m_Value\\\": 0.5,\\n \\\"m_DefaultValue\\\": 0.0,\\n \\\"m_Labels\\\": [\\n \\\"X\\\"\\n ]\\n}\"\n }\n ],\n \"m_Precision\": 0,\n \"m_PreviewExpanded\": true,\n \"m_CustomColors\": {\n \"m_SerializableColors\": []\n },\n \"m_SurfaceType\": 0,\n \"m_AlphaMode\": 0,\n \"m_TwoSided\": false,\n \"m_AddPrecomputedVelocity\": false,\n \"m_DOTSInstancing\": false,\n \"m_ShaderGUIOverride\": \"\",\n \"m_OverrideEnabled\": false\n}"
29+
}
30+
],
31+
"m_Groups": [
32+
{
33+
"m_GuidSerialized": "a0c9f82f-8f00-4690-8ef3-bf4079519d15",
34+
"m_Title": "Min < Max",
35+
"m_Position": {
36+
"x": 10.0,
37+
"y": 10.0
38+
}
39+
}
40+
],
41+
"m_StickyNotes": [],
42+
"m_SerializableEdges": [
43+
{
44+
"typeInfo": {
45+
"fullName": "UnityEditor.Graphing.Edge"
46+
},
47+
"JSONnodeData": "{\n \"m_OutputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"419f7fde-45d3-413d-a681-3f80de32bc31\"\n },\n \"m_InputSlot\": {\n \"m_SlotId\": 0,\n \"m_NodeGUIDSerialized\": \"47df49fd-91a7-4c8a-8404-c3710b050632\"\n }\n}"
48+
}
49+
],
50+
"m_PreviewData": {
51+
"serializedMesh": {
52+
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
53+
"m_Guid": ""
54+
}
55+
},
56+
"m_Path": "Shader Graphs",
57+
"m_ConcretePrecision": 0,
58+
"m_ActiveOutputNodeGuidSerialized": "faac5ed4-8a55-4c7e-a36f-e4380ae3593a"
59+
}

TestProjects/ShaderGraph/Assets/CommonAssets/Graphs/Properties.shadergraph.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.core/Editor/Drawing.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.shadergraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9+
- Added the Internal Inspector which allows the user to view data contained in selected nodes and properties in a new floating graph sub-window. Also added support for custom property drawers to let you visualize any data type you like and expose it to the inspector.
910
- Added samples for Procedural Patterns to the package.
1011
- You can now use the right-click context menu to delete Sticky Notes.
1112
- You can now save your graph as a new Asset.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace UnityEditor.ShaderGraph.Drawing
4+
{
5+
[AttributeUsage(AttributeTargets.Property)]
6+
public class InspectableAttribute : Attribute
7+
{
8+
// String value to use in the Property name TextLabel
9+
public string labelName { get; private set; }
10+
11+
// The default value of this property
12+
public object defaultValue { get; private set; }
13+
14+
// String value to supply if you wish to use a custom style when drawing this property
15+
public string customStyleName { get; private set; }
16+
17+
public InspectableAttribute(string labelName, object defaultValue, string customStyleName = "")
18+
{
19+
this.labelName = labelName;
20+
this.defaultValue = defaultValue;
21+
this.customStyleName = customStyleName;
22+
}
23+
}
24+
}

com.unity.shadergraph/Editor/Data/Attributes/InspectableAttribute.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace UnityEditor.ShaderGraph.Drawing
4+
{
5+
[AttributeUsage(AttributeTargets.Class)]
6+
public class SGPropertyDrawerAttribute : Attribute
7+
{
8+
public Type propertyType { get; private set; }
9+
10+
public SGPropertyDrawerAttribute(Type propertyType)
11+
{
12+
this.propertyType = propertyType;
13+
}
14+
}
15+
}

com.unity.shadergraph/Editor/Data/Attributes/SGPropertyDrawerAttribute.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)