浏览代码

Merge pull request #70 from Unity-Technologies/tidyup

Tidyup
/main
GitHub 7 年前
当前提交
1d08cd88
共有 127 个文件被更改,包括 1614 次插入1186 次删除
  1. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs
  2. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs
  4. 2
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
  5. 2
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientField.cs
  6. 12
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs
  7. 4
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/ParallaxNode.cs
  8. 2
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs
  9. 16
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/TextureSamplerNode.cs
  10. 19
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs
  11. 56
      MaterialGraphProject/Assets/NewNodes/Editor/Kill/MultiLayerParallaxNode.cs
  12. 12
      MaterialGraphProject/Assets/NewNodes/Editor/Kill/VertexNormalNode.cs
  13. 146
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph
  14. 2
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph.meta
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs
  16. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs
  17. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs.meta
  18. 245
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  19. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractShaderProperty.cs
  20. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialGraph.cs
  21. 655
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
  22. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/MaterialGraphChange.cs
  23. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightMetallicMasterNode.cs
  24. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightSpecularMasterNode.cs
  25. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightUnlitMasterNode.cs
  26. 172
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  27. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Art/Adjustments/LevelsNode.cs
  28. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SplitNode.cs
  29. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/HLSLNode.cs
  30. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
  31. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/BitangentNode.cs
  32. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/NormalNode.cs
  33. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/PositionNode.cs
  34. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs
  35. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/VertexColorNode.cs
  36. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ViewDirectionNode.cs
  37. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/WorldSpacePositionNode.cs
  38. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/WorldSpaceTangentNode.cs
  39. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
  40. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
  41. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs
  42. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs
  43. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/CameraDirNode.cs
  44. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/CameraPosNode.cs
  45. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/ScreenPosNode.cs
  46. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time/SinTimeNode.cs
  47. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time/TimeNode.cs
  48. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs
  49. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs
  50. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs
  51. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs
  52. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs
  53. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyNode.cs
  54. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
  55. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
  56. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/VertexInterpolatorNode.cs
  57. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph.meta
  58. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
  59. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs
  60. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
  61. 66
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs
  62. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs.meta
  63. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  64. 87
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  65. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
  66. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
  67. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs
  68. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs
  69. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphAnchorPresenter.cs
  70. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEdgePresenter.cs
  71. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  72. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  73. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  74. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  75. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs
  76. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
  77. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderSubGraphImporterEditor.cs
  78. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add-Sub-Graph.ShaderSubGraph
  79. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add.ShaderGraph
  80. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add.ShaderGraph.meta
  81. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/AddSubGraph.ShaderGraph
  82. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/AddSubGraph.ShaderGraph.meta
  83. 190
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph
  84. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph.meta
  85. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Multiply.ShaderGraph
  86. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Multiply.ShaderGraph.meta
  87. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph
  88. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph.meta
  89. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/TextureSample.ShaderGraph
  90. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/TextureSample.ShaderGraph.meta
  91. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs
  92. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/DynamicSlotTests.cs
  93. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs
  94. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs
  95. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
  96. 92
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
  97. 83
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyGeneratorTests.cs
  98. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  99. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs
  100. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateLayeredShaderGraph.cs

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs


Debug.LogWarning("Node does not exist");
return Enumerable.Empty<IEdge>();
}
ISlot slot = slot = node.FindSlot<ISlot>(s.slotId);
ISlot slot = node.FindSlot<ISlot>(s.slotId);
List<IEdge> candidateEdges;
if (!m_NodeEdges.TryGetValue(s.nodeGuid, out candidateEdges))

AddEdgeToNodeEdges(edge);
OnEnable();
ValidateGraph();
ValidateGraph();
}
public virtual void ValidateGraph()

//manually modifies serialized data
//of if they delete a node in the inspector
//debug view.
foreach (var edge in edges.ToArray())
//debug view.
foreach (var edge in edges.ToArray())
{
var outputNode = GetNodeFromGuid(edge.outputSlot.nodeGuid);
var inputNode = GetNodeFromGuid(edge.inputSlot.nodeGuid);

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs


get { return m_SlotType == SlotType.Output; }
}
public SlotType slotType
{
get { return m_SlotType; }
}
// used via reflection / serialization after deserialize
// to reconstruct this slot.
public SerializableSlot()

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs


[TestFixture]
public class SerializableGraphTests
{
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

2
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientField.cs


#region Initial Setup
private static MethodInfo s_miGradientField1;
private static MethodInfo s_miGradientField2;
static GUIGradientField()
{

s_miGradientField2 = tyEditorGUILayout.GetMethod("GradientField", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { GradientWrapper.s_tyGradient, typeof(GUILayoutOption[]) }, null);
}
#endregion

12
MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(TimeInputSlotId, k_TimeInputSlotName, k_TimeInputSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(RGBAOutputSlotId, k_RGBAOutputSlotName, k_RGBAOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(ROutputSlotId, k_ROutputSlotName, k_ROutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(GOutputSlotId, k_GOutputSlotName, k_GOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(BOutputSlotId, k_BOutputSlotName, k_BOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AOutputSlotId, k_AOutputSlotName, k_AOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector1MaterialSlot(TimeInputSlotId, k_TimeInputSlotName, k_TimeInputSlotName, SlotType.Input,0));
AddSlot(new Vector4MaterialSlot(RGBAOutputSlotId, k_RGBAOutputSlotName, k_RGBAOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(ROutputSlotId, k_ROutputSlotName, k_ROutputSlotName, SlotType.Output,0));
AddSlot(new Vector1MaterialSlot(GOutputSlotId, k_GOutputSlotName, k_GOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(BOutputSlotId, k_BOutputSlotName, k_BOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(AOutputSlotId, k_AOutputSlotName, k_AOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { TimeInputSlotId, RGBAOutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId });
m_Gradient = new Gradient();
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray();

4
MaterialGraphProject/Assets/NewNodes/Editor/Keep/ParallaxNode.cs


protected virtual MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
return new Vector1MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, 1);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector2, Vector4.zero);
return new Vector2MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, Vector2.zero);
}
protected virtual string GetInputSlot1Name()

2
MaterialGraphProject/Assets/NewNodes/Editor/Keep/SamplerStateNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.SamplerState, Vector4.zero));
AddSlot(new SamplerStateMaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

16
MaterialGraphProject/Assets/NewNodes/Editor/Keep/TextureSamplerNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(TextureInputId, kTextureInputName, kTextureInputName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero));
AddSlot(new MaterialSlot(UVInput, kUVInputName, kUVInputName, SlotType.Input, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output,0));
AddSlot(new Vector1MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, 0));
AddSlot(new Texture2DMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName, SlotType.Input));
AddSlot(new Vector2MaterialSlot(UVInput, kUVInputName, kUVInputName, SlotType.Input, Vector4.zero));
AddSlot(new SamplerStateMaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input));
RemoveSlotsNameNotMatching(new[] { OutputSlotRGBAId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, TextureInputId, UVInput, SamplerInput });
}

19
MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs


protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero);
return new Vector3MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, Vector3.zero);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
return new Vector3MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotName, SlotType.Output, Vector4.zero);
}
protected virtual string GetInputSlotName()

if (requiresTangentTransform)
visitor.AddShaderChunk("float3x3 tangentTransform = float3x3( worldSpaceTangent, worldSpaceBitangent, worldSpaceNormal);", false);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + transformString + ";", true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};",
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType),
GetVariableNameForSlot(OutputSlotId),
transformString), true);
}
//float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);------

//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz - view to world
//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_MV ).xyz - view to local
//mul( tangentTransform, mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz ).xyz - view to tangent
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
private string inputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); }
}
public NeededCoordinateSpace RequiresTangent()
{

56
MaterialGraphProject/Assets/NewNodes/Editor/Kill/MultiLayerParallaxNode.cs


protected virtual MaterialSlot GetInputDepthSlot()
{
return new MaterialSlot(InputDepthSlotId, GetInputSlot1Name(), kInputDepthShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
return new Vector1MaterialSlot(InputDepthSlotId, GetInputSlot1Name(), kInputDepthShaderName, SlotType.Input,0);
return new MaterialSlot(InputFadeRateSlotId, GetInputSlot2Name(), kInputFadeRateShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new DynamicVectorMaterialSlot(InputFadeRateSlotId, GetInputSlot2Name(), kInputFadeRateShaderName, SlotType.Input, Vector4.zero);
return new MaterialSlot(InputLayerCountSlotId, GetInputSlot3Name(), kInputLayerCountShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new DynamicVectorMaterialSlot(InputLayerCountSlotId, GetInputSlot3Name(), kInputLayerCountShaderName, SlotType.Input, Vector4.zero);
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
return new Texture2DMaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
return new DynamicVectorMaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, Vector4.zero);
}
protected virtual string GetInputSlot1Name()

{
return kOutputSlotShaderName;
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputDepthSlotId).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputFadeRateSlotId).concreteValueType); }
}
private string input3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputLayerCountSlotId).concreteValueType); }
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" +
precision + input1Dimension + " " + depth + ", " +
precision + input2Dimension + " " + fadeRate + ", " +
precision + input3Dimension + " " + layerCount + ", " +
"sampler2D " + tex + ", " +
precision + "2 " + UVs + ", " +
precision + "3 " + viewTangentSpace + ")";
var input1 = ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputDepthSlotId).concreteValueType);
var input2 = ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputFadeRateSlotId).concreteValueType);
var input3 = ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputLayerCountSlotId).concreteValueType);
var output = ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType);
return string.Format("inline {0} {1} ({2} {3}, {4} {5}, {6} {7}, " + "sampler2D {8}, {9}2 {10}, {9}3 {11})", output, GetFunctionName(), input1, depth, input2, fadeRate, input3, layerCount, tex, precision, UVs, viewTangentSpace);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

string fadeRateValue = GetSlotValue(InputFadeRateSlotId, generationMode);
string layerCountValue = GetSlotValue(InputLayerCountSlotId, generationMode);
string textureValue = GetSlotValue(TextureSlotId, generationMode);
visitor.AddShaderChunk(
precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) +
" = " + GetFunctionCallBody(depthValue, fadeRateValue, layerCountValue, textureValue) + ";", true);
var output = ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", output, GetVariableNameForSlot(OutputSlotId), GetFunctionCallBody(depthValue, fadeRateValue, layerCountValue, textureValue)), true);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.AddShaderChunk(precision + "2 texcoord = UVs;", false);
outputString.AddShaderChunk(precision + "2 offset = -viewTangentSpace.xy * depth / layerCount;", false);
outputString.AddShaderChunk(precision + outputDimension + " result = 0.0f;", false);
outputString.AddShaderChunk(precision + outputDimension + " fade = 1.0f;", false);
var output = ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType);
outputString.AddShaderChunk(output + " result = 0.0f;", false);
outputString.AddShaderChunk(output + " fade = 1.0f;", false);
outputString.AddShaderChunk(precision + " alpha = 0.0f;", false);
outputString.AddShaderChunk("for (int i = 0; i < 10; i++) {", false);

12
MaterialGraphProject/Assets/NewNodes/Editor/Kill/VertexNormalNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdXYZ, kOutputSlotNameXYZ, kOutputSlotNameXYZ, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotIdXYZ, kOutputSlotNameXYZ, kOutputSlotNameXYZ, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output,0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output,0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, 0));
RemoveSlotsNameNotMatching(validSlots);
}

146
MaterialGraphProject/Assets/PartyPreview.ShaderGraph
文件差异内容过多而无法显示
查看文件

2
MaterialGraphProject/Assets/PartyPreview.ShaderGraph.meta


externalObjects: {}
defaultTextures: []
nonModifiableTextures:
- Texture: {fileID: 2800000, guid: e2e7994f2c9b58f40aaebdaabbbd0ad8, type: 3}
- Texture_AE39B836: {fileID: 2800000, guid: e2e7994f2c9b58f40aaebdaabbbd0ad8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs


public override void Action(int instanceId, string pathName, string resourceFile)
{
var graph = new UnityEngine.MaterialGraph.MaterialGraph();
// graph.AddNode(new MetallicMasterNode());
graph.AddNode(new LightweightMetallicMasterNode());
File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
AssetDatabase.Refresh();
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs


using System.IO;
using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEngine.MaterialGraph;

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs.meta


fileFormatVersion: 2
guid: 706886b5adec4e3409ceb9a30e04440e
guid: f329b5b280b7f6f449659f05937ac2f2
timeCreated: 1465559218
licenseType: Pro
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

245
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


return result;
}
class IndexedProperty
{
public int index;
public IShaderProperty property;
}
public override void ReplaceWith(IGraph other)
{
var otherMG = other as AbstractMaterialGraph;

base.OnAfterDeserialize();
}
static ShaderGraphRequirements GetRequierments(AbstractMaterialNode nodeForRequirements)
protected static ShaderGraphRequirements GetRequierments(AbstractMaterialNode nodeForRequirements)
if (nodeForRequirements == null)
return ShaderGraphRequirements.none;
var activeNodeList = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, nodeForRequirements);

return reqs;
}
static void GenerateSpaceTranslationSurfaceInputs(
protected static void GenerateSpaceTranslationSurfaceInputs(
NeededCoordinateSpace neededSpaces,
ShaderGenerator surfaceInputs,
string objectSpaceName,

return GetShader(node, GenerationMode.Preview, string.Format("hidden/preview/{0}", node.GetVariableNameForNode()), out configuredTextures, out previewMode);
}
public string GetShader(AbstractMaterialNode node, GenerationMode mode, string name, out List<PropertyCollector.TextureInfo> configuredTextures, out PreviewMode previewMode)
protected static void GenerateSurfaceDescriptionStruct(ShaderGenerator surfaceDescriptionStruct, AbstractMaterialNode node, bool isMasterNode)
if (node == null)
throw new ArgumentNullException("node");
var vertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();
var surfaceDescriptionStruct = new ShaderGenerator();
var shaderFunctionVisitor = new ShaderGenerator();
var surfaceInputs = new ShaderGenerator();
var graphVertexInput = @"
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceDescriptionStruct.AddShaderChunk("struct SurfaceDescription{", false);
surfaceDescriptionStruct.Indent();
if (isMasterNode)
{
foreach (var slot in node.GetInputSlots<MaterialSlot>())
surfaceDescriptionStruct.AddShaderChunk(string.Format("{0} {1};", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), slot.shaderOutputName), false);
}
else
{
foreach (var slot in node.GetOutputSlots<MaterialSlot>())
surfaceDescriptionStruct.AddShaderChunk(string.Format("{0} {1};", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), node.GetVariableNameForSlot(slot.id)), false);
}
surfaceDescriptionStruct.Deindent();
surfaceDescriptionStruct.AddShaderChunk("};", false);
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);
surfaceInputs.Indent();
var requirements = GetRequierments(node);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceNormal, ShaderGeneratorNames.ViewSpaceNormal,
ShaderGeneratorNames.WorldSpaceNormal, ShaderGeneratorNames.TangentSpaceNormal);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceTangent, ShaderGeneratorNames.ViewSpaceTangent,
ShaderGeneratorNames.WorldSpaceTangent, ShaderGeneratorNames.TangentSpaceTangent);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceBiTangent, ShaderGeneratorNames.ViewSpaceBiTangent,
ShaderGeneratorNames.WorldSpaceBiTangent, ShaderGeneratorNames.TangentSpaceBiTangent);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceViewDirection, ShaderGeneratorNames.ViewSpaceViewDirection,
ShaderGeneratorNames.WorldSpaceViewDirection, ShaderGeneratorNames.TangentSpaceViewDirection);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, surfaceInputs,
ShaderGeneratorNames.ObjectSpacePosition, ShaderGeneratorNames.ViewSpacePosition,
ShaderGeneratorNames.WorldSpacePosition, ShaderGeneratorNames.TangentSpacePosition);
if (requirements.requiresVertexColor)
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false);
if (requirements.requiresScreenPosition)
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false);
var activeNodeList = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, node);
previewMode = PreviewMode.Preview2D;
foreach (var pNode in activeNodeList.OfType<AbstractMaterialNode>())
surfaceDescriptionStruct.AddShaderChunk("void ScaleSurfaceDescription(inout SurfaceDescription surface, float scale){", false);
surfaceDescriptionStruct.Indent();
if (isMasterNode)
{
foreach (var slot in node.GetInputSlots<MaterialSlot>())
surfaceDescriptionStruct.AddShaderChunk( string.Format("surface.{0} = scale * surface.{0};", slot.shaderOutputName), false);
}
else
if (pNode.previewMode == PreviewMode.Preview3D)
{
previewMode = PreviewMode.Preview3D;
break;
}
foreach (var slot in node.GetOutputSlots<MaterialSlot>())
surfaceDescriptionStruct.AddShaderChunk(string.Format("surface.{0} = scale * surface.{0};", node.GetVariableNameForSlot(slot.id)), false);
foreach (var channel in requirements.requiresMeshUVs.Distinct())
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false);
surfaceInputs.Deindent();
surfaceInputs.AddShaderChunk("};", false);
vertexShader.AddShaderChunk("GraphVertexInput PopulateVertexData(GraphVertexInput v){", false);
vertexShader.Indent();
vertexShader.AddShaderChunk("return v;", false);
vertexShader.Deindent();
vertexShader.AddShaderChunk("}", false);
surfaceDescriptionStruct.Deindent();
surfaceDescriptionStruct.AddShaderChunk("};", false);
surfaceDescriptionStruct.AddShaderChunk("struct SurfaceDescription{", false);
surfaceDescriptionStruct.AddShaderChunk("void AddSurfaceDescription(inout SurfaceDescription base, in SurfaceDescription add){", false);
if (node is IMasterNode)
if (isMasterNode)
surfaceDescriptionStruct.AddShaderChunk(AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType) + " " + slot.shaderOutputName + ";", false);
{
var str = string.Format("base.{0} = base.{0} + add.{0};", slot.shaderOutputName);
surfaceDescriptionStruct.AddShaderChunk(str, false);
}
surfaceDescriptionStruct.AddShaderChunk(AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType) + " " + node.GetVariableNameForSlot(slot.id) + ";", false);
{
var str = string.Format("base.{0} = base.{0} + add.{0};", node.GetVariableNameForSlot(slot.id));
surfaceDescriptionStruct.AddShaderChunk(str, false);
}
}
surfaceDescriptionFunction.AddShaderChunk("SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {", false);
protected static void GenerateSurfaceDescription(
AbstractMaterialNode node,
ShaderGenerator surfaceDescriptionFunction,
ShaderGenerator shaderFunctionVisitor,
PropertyCollector shaderProperties,
ShaderGraphRequirements requirements,
GenerationMode mode,
bool isMasterNode,
string functionName = "PopulateSurfaceData",
string surfaceDescriptionName = "SurfaceDescription")
{
var graph = node.owner as AbstractMaterialGraph;
if (graph == null)
return;
surfaceDescriptionFunction.AddShaderChunk(string.Format("{0} {1}(SurfaceInputs IN) {{", surfaceDescriptionName, functionName), false);
surfaceDescriptionFunction.Indent();
if ((requirements.requiresNormal & NeededCoordinateSpace.Object) > 0)

foreach (var channel in requirements.requiresMeshUVs.Distinct())
surfaceDescriptionFunction.AddShaderChunk(string.Format("half4 {0} = IN.{0};", channel.GetUVName()), false);
var shaderProperties = new PropertyCollector();
CollectShaderProperties(shaderProperties, mode);
graph.CollectShaderProperties(shaderProperties, mode);
var activeNodeList = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, node);
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>())
{
if (activeNode is IGeneratesFunction)

activeNode.CollectShaderProperties(shaderProperties, mode);
}
surfaceDescriptionFunction.AddShaderChunk("SurfaceDescription surface = (SurfaceDescription)0;", false);
if (node is IMasterNode)
surfaceDescriptionFunction.AddShaderChunk(string.Format("{0} surface = ({0})0;", surfaceDescriptionName), false);
if (isMasterNode)
var foundEdges = GetEdges(input.slotReference).ToArray();
var foundEdges = graph.GetEdges(input.slotReference).ToArray();
var fromNode = GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
var fromNode = graph.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
}
else

surfaceDescriptionFunction.Deindent();
surfaceDescriptionFunction.AddShaderChunk("}", false);
ListPool<INode>.Release(activeNodeList);
}
public string GetShader(AbstractMaterialNode node, GenerationMode mode, string name, out List<PropertyCollector.TextureInfo> configuredTextures, out PreviewMode previewMode)
{
if (node == null)
throw new ArgumentNullException("node");
var vertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();
var surfaceDescriptionStruct = new ShaderGenerator();
var shaderFunctionVisitor = new ShaderGenerator();
var surfaceInputs = new ShaderGenerator();
var graphVertexInput = @"
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);
surfaceInputs.Indent();
var requirements = GetRequierments(node);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceNormal, ShaderGeneratorNames.ViewSpaceNormal,
ShaderGeneratorNames.WorldSpaceNormal, ShaderGeneratorNames.TangentSpaceNormal);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceTangent, ShaderGeneratorNames.ViewSpaceTangent,
ShaderGeneratorNames.WorldSpaceTangent, ShaderGeneratorNames.TangentSpaceTangent);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceBiTangent, ShaderGeneratorNames.ViewSpaceBiTangent,
ShaderGeneratorNames.WorldSpaceBiTangent, ShaderGeneratorNames.TangentSpaceBiTangent);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, surfaceInputs,
ShaderGeneratorNames.ObjectSpaceViewDirection, ShaderGeneratorNames.ViewSpaceViewDirection,
ShaderGeneratorNames.WorldSpaceViewDirection, ShaderGeneratorNames.TangentSpaceViewDirection);
GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, surfaceInputs,
ShaderGeneratorNames.ObjectSpacePosition, ShaderGeneratorNames.ViewSpacePosition,
ShaderGeneratorNames.WorldSpacePosition, ShaderGeneratorNames.TangentSpacePosition);
if (requirements.requiresVertexColor)
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false);
if (requirements.requiresScreenPosition)
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false);
var activeNodeList = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, node);
previewMode = PreviewMode.Preview2D;
foreach (var pNode in activeNodeList.OfType<AbstractMaterialNode>())
{
if (pNode.previewMode == PreviewMode.Preview3D)
{
previewMode = PreviewMode.Preview3D;
break;
}
}
ListPool<INode>.Release(activeNodeList);
foreach (var channel in requirements.requiresMeshUVs.Distinct())
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false);
surfaceInputs.Deindent();
surfaceInputs.AddShaderChunk("};", false);
vertexShader.AddShaderChunk("GraphVertexInput PopulateVertexData(GraphVertexInput v){", false);
vertexShader.Indent();
vertexShader.AddShaderChunk("return v;", false);
vertexShader.Deindent();
vertexShader.AddShaderChunk("}", false);
GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, node, node is IMasterNode);
var shaderProperties = new PropertyCollector();
GenerateSurfaceDescription(
node,
surfaceDescriptionFunction,
shaderFunctionVisitor,
shaderProperties,
requirements,
mode,
node is IMasterNode);
var finalShader = new ShaderGenerator();
finalShader.AddShaderChunk(string.Format(@"Shader ""{0}""", name), false);

34
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractShaderProperty.cs


namespace UnityEngine.MaterialGraph
{
[Serializable]
public abstract class AbstractShaderProperty<T> : ISerializationCallbackReceiver, IShaderProperty
public abstract class AbstractShaderProperty<T> : IShaderProperty
[SerializeField]
private string m_Description;
[NonSerialized]
private Guid m_Guid;
private string m_GuidSerialized;
private bool m_GeneratePropertyBlock = true;
private bool m_GeneratePropertyBlock = true;
protected AbstractShaderProperty()
{
m_Guid = Guid.NewGuid();
}
private SerializableGuid m_Guid = new SerializableGuid();
public T value
{

get
{
if (string.IsNullOrEmpty(m_Name))
return m_Guid.ToString();
return guid.ToString();
return m_Name;
}
set { m_Name = value; }

public Guid guid
{
get { return m_Guid; }
get { return m_Guid.guid; }
}
public bool generatePropertyBlock

}
public abstract PreviewProperty GetPreviewMaterialProperty();
public virtual void OnBeforeSerialize()
{
m_GuidSerialized = m_Guid.ToString();
}
public virtual void OnAfterDeserialize()
{
if (!string.IsNullOrEmpty(m_GuidSerialized))
m_Guid = new Guid(m_GuidSerialized);
else
m_Guid = Guid.NewGuid();
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialGraph.cs


namespace UnityEngine.MaterialGraph
{
[Serializable]
public class MaterialGraph : AbstractMaterialGraph
public class MaterialGraph : AbstractMaterialGraph, IShaderGraph
{
public IMasterNode masterNode
{

PreviewMode pmode;
return GetShader(masterNode as AbstractMaterialNode, mode, name, out configuredTextures, out pmode);
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
}
}
}

655
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs


namespace UnityEngine.MaterialGraph
{
public interface IMaterialSlotHasVaule<T>
{
T defaultValue { get; }
T value { get; }
}
public class MaterialSlot : SerializableSlot
public class Vector1MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<float>
SlotValueType m_ValueType;
private float m_Value;
Vector4 m_DefaultValue;
private float m_DefaultValue;
public Vector1MaterialSlot()
{
}
public Vector1MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
float value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_DefaultValue = value;
m_Value = value;
}
public float defaultValue { get { return m_DefaultValue; } }
public float value
{
get { return m_Value; }
set { m_Value = value; }
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return value.ToString();
}
public override SlotValueType valueType { get { return SlotValueType.Vector1; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector1; } }
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty
{
m_Name = name,
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType),
m_Vector4 = new Vector4(value, value, value, value),
m_Float = value,
m_Color = new Vector4(value, value, value, value),
};
return pp;
}
}
[Serializable]
public class Vector2MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector2>
{
Vector4 m_CurrentValue;
private Vector2 m_Value;
ConcreteSlotValueType m_ConcreteValueType;
private Vector2 m_DefaultValue;
public Vector2MaterialSlot()
{
}
public Vector2MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
Vector2 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_Value = value;
}
public Vector2 defaultValue { get { return m_DefaultValue; } }
public Vector2 value
{
get { return m_Value; }
set { m_Value = value; }
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "2 (" + value.x + "," + value.y + ")";
}
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty
{
m_Name = name,
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType),
m_Vector4 = new Vector4(value.x, value.y, 0, 0),
m_Float = value.x,
m_Color = new Vector4(value.x, value.x, 0, 0),
};
return pp;
}
public override SlotValueType valueType { get { return SlotValueType.Vector2; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector2; } }
}
[Serializable]
public class Vector3MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector3>
{
string m_ShaderOutputName;
private Vector3 m_Value;
ShaderStage m_ShaderStage;
private Vector3 m_DefaultValue;
public Vector3MaterialSlot()
{
}
public Vector3MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
Vector3 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_Value = value;
}
public Vector3 defaultValue { get { return m_DefaultValue; } }
public Vector3 value
{
get { return m_Value; }
set { m_Value = value; }
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "3 (" + value.x + "," + value.y + "," + value.z + ")";
}
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty
{
m_Name = name,
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType),
m_Vector4 = new Vector4(value.x, value.y, value.z, 0),
m_Float = value.x,
m_Color = new Vector4(value.x, value.x, value.z, 0),
};
return pp;
}
public override SlotValueType valueType { get { return SlotValueType.Vector3; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector3; } }
}
[Serializable]
public class Vector4MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector4>
{
[SerializeField]
private Vector4 m_Value;
[SerializeField]
private Vector4 m_DefaultValue;
public Vector4MaterialSlot()
{
}
public Vector4MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_Value = value;
}
public Vector4 defaultValue { get { return m_DefaultValue; } }
public Vector4 value
{
get { return m_Value; }
set { m_Value = value; }
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")";
}
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty
{
m_Name = name,
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType),
m_Vector4 = new Vector4(value.x, value.y, value.z, value.w),
m_Float = value.x,
m_Color = new Vector4(value.x, value.x, value.z, value.w),
};
return pp;
}
public override SlotValueType valueType { get { return SlotValueType.Vector4; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector4; } }
}
[Serializable]
public class Matrix2MaterialSlot : MaterialSlot
{
public Matrix2MaterialSlot()
{
}
public Matrix2MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "2x2 (1,0,0,1)";
}
public override SlotValueType valueType { get { return SlotValueType.Matrix2; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix2; } }
}
[Serializable]
public class Matrix3MaterialSlot : MaterialSlot
{
public Matrix3MaterialSlot()
{
}
public Matrix3MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "3x3 (1,0,0,0,1,0,0,0,1)";
}
public override SlotValueType valueType { get { return SlotValueType.Matrix3; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix3; } }
}
[Serializable]
public class Matrix4MaterialSlot : MaterialSlot
{
public Matrix4MaterialSlot()
{
}
public Matrix4MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "4x4 (1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)";
}
public override SlotValueType valueType { get { return SlotValueType.Matrix4; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix4; } }
}
[Serializable]
public class Texture2DMaterialSlot : MaterialSlot
{
public Texture2DMaterialSlot()
{
}
public Texture2DMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
public MaterialSlot() { }
public override SlotValueType valueType { get { return SlotValueType.Texture2D; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Texture2D; } }
}
[Serializable]
public class SamplerStateMaterialSlot : MaterialSlot
{
public SamplerStateMaterialSlot()
{
}
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, slotType, hidden)
public SamplerStateMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
SharedInitialize(shaderOutputName, valueType, defaultValue, shaderStage);
void SharedInitialize(string inShaderOutputName, SlotValueType inValueType, Vector4 inDefaultValue, ShaderStage shaderStage)
public override SlotValueType valueType { get { return SlotValueType.SamplerState; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.SamplerState; } }
}
[Serializable]
public class DynamicVectorMaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector4>
{
[SerializeField]
private Vector4 m_Value;
[SerializeField]
private Vector4 m_DefaultValue;
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4;
public DynamicVectorMaterialSlot()
m_ShaderOutputName = inShaderOutputName;
valueType = inValueType;
m_DefaultValue = inDefaultValue;
m_CurrentValue = inDefaultValue;
}
public DynamicVectorMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_Value = value;
}
public Vector4 defaultValue { get { return m_DefaultValue; } }
public Vector4 value
{
get { return m_Value; }
set { m_Value = value; }
}
public override SlotValueType valueType { get { return SlotValueType.Dynamic; } }
public override ConcreteSlotValueType concreteValueType
{
get { return m_ConcreteValueType; }
}
public void SetConcreteType(ConcreteSlotValueType valueType)
{
m_ConcreteValueType = valueType;
}
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty
{
m_Name = name,
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType),
m_Vector4 = new Vector4(value.x, value.y, value.z, value.w),
m_Float = value.x,
m_Color = new Vector4(value.x, value.x, value.z, value.w),
};
return pp;
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")";
}
}
[Serializable]
public abstract class MaterialSlot : SerializableSlot
{
[SerializeField]
string m_ShaderOutputName;
[SerializeField]
ShaderStage m_ShaderStage;
private bool m_HasError;
protected MaterialSlot() { }
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, slotType, hidden)
{
m_ShaderOutputName = shaderOutputName;
this.shaderStage = shaderStage;
}

set { base.displayName = value; }
}
public Vector4 defaultValue
public string RawDisplayName()
get { return m_DefaultValue; }
set { m_DefaultValue = value; }
return displayName;
public SlotValueType valueType
public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
get { return m_ValueType; }
set
switch (type)
switch (value)
{
case SlotValueType.Vector1:
concreteValueType = ConcreteSlotValueType.Vector1;
break;
case SlotValueType.Vector2:
concreteValueType = ConcreteSlotValueType.Vector2;
break;
case SlotValueType.Vector3:
concreteValueType = ConcreteSlotValueType.Vector3;
break;
case SlotValueType.Matrix2:
concreteValueType = ConcreteSlotValueType.Matrix2;
break;
case SlotValueType.Matrix3:
concreteValueType = ConcreteSlotValueType.Matrix3;
break;
case SlotValueType.Matrix4:
concreteValueType = ConcreteSlotValueType.Matrix4;
break;
case SlotValueType.Texture2D:
concreteValueType = ConcreteSlotValueType.Texture2D;
break;
case SlotValueType.SamplerState:
concreteValueType = ConcreteSlotValueType.SamplerState;
break;
default:
concreteValueType = ConcreteSlotValueType.Vector4;
break;
}
m_ValueType = value;
case SlotValueType.SamplerState:
return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Matrix4:
return new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Matrix3:
return new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Matrix2:
return new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Texture2D:
return new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Dynamic:
return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector4:
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector3:
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector2:
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector1:
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden);
}
public Vector4 currentValue
{
get { return m_CurrentValue; }
set { m_CurrentValue = value; }
throw new ArgumentOutOfRangeException("type", type, null);
public ConcreteSlotValueType concreteValueType
{
get { return m_ConcreteValueType; }
set { m_ConcreteValueType = value; }
}
public abstract SlotValueType valueType { get; }
public abstract ConcreteSlotValueType concreteValueType { get; }
public string shaderOutputName
{

set { m_ShaderStage = value; }
}
public bool IsCompatibleWithInputSlotType(SlotValueType inputType)
public bool hasError
switch (valueType)
get { return m_HasError; }
set { m_HasError = value; }
}
public bool IsCompatibleWithInputSlotType(ConcreteSlotValueType inputType)
{
switch (concreteValueType)
case SlotValueType.SamplerState:
return inputType == SlotValueType.SamplerState;
case SlotValueType.Matrix4:
return inputType == SlotValueType.Matrix4
|| inputType == SlotValueType.Matrix3
|| inputType == SlotValueType.Matrix2;
case SlotValueType.Matrix3:
return inputType == SlotValueType.Matrix3
|| inputType == SlotValueType.Matrix2;
case SlotValueType.Matrix2:
return inputType == SlotValueType.Matrix2;
case SlotValueType.Texture2D:
return inputType == SlotValueType.Texture2D;
case SlotValueType.Vector4:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Vector3:
return inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Vector2:
return inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Dynamic:
case SlotValueType.Vector1:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case ConcreteSlotValueType.SamplerState:
return inputType == ConcreteSlotValueType.SamplerState;
case ConcreteSlotValueType.Matrix4:
return inputType == ConcreteSlotValueType.Matrix4
|| inputType == ConcreteSlotValueType.Matrix3
|| inputType == ConcreteSlotValueType.Matrix2;
case ConcreteSlotValueType.Matrix3:
return inputType == ConcreteSlotValueType.Matrix3
|| inputType == ConcreteSlotValueType.Matrix2;
case ConcreteSlotValueType.Matrix2:
return inputType == ConcreteSlotValueType.Matrix2;
case ConcreteSlotValueType.Texture2D:
return inputType == ConcreteSlotValueType.Texture2D;
case ConcreteSlotValueType.Vector4:
return inputType == ConcreteSlotValueType.Vector4
|| inputType == ConcreteSlotValueType.Vector3
|| inputType == ConcreteSlotValueType.Vector2
|| inputType == ConcreteSlotValueType.Vector1;
case ConcreteSlotValueType.Vector3:
return inputType == ConcreteSlotValueType.Vector3
|| inputType == ConcreteSlotValueType.Vector2
|| inputType == ConcreteSlotValueType.Vector1;
case ConcreteSlotValueType.Vector2:
return inputType == ConcreteSlotValueType.Vector2
|| inputType == ConcreteSlotValueType.Vector1;
case ConcreteSlotValueType.Vector1:
return inputType == ConcreteSlotValueType.Vector4
|| inputType == ConcreteSlotValueType.Vector3
|| inputType == ConcreteSlotValueType.Vector2
|| inputType == ConcreteSlotValueType.Vector1;
public string GetDefaultValue(GenerationMode generationMode)
public virtual string GetDefaultValue(GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)

return DefaultTextureName;
return Texture2DMaterialSlot.DefaultTextureName;
switch (concreteValueType)
{
case ConcreteSlotValueType.Vector1:
return m_CurrentValue.x.ToString();
case ConcreteSlotValueType.Vector2:
return matOwner.precision + "2 (" + m_CurrentValue.x + "," + m_CurrentValue.y + ")";
case ConcreteSlotValueType.Vector3:
return matOwner.precision + "3 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + ")";
case ConcreteSlotValueType.Vector4:
return matOwner.precision + "4 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + "," + m_CurrentValue.w + ")";
case ConcreteSlotValueType.Matrix2:
return matOwner.precision + "2x2 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ")";
case ConcreteSlotValueType.Matrix3:
return matOwner.precision + "3x3 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ")";
case ConcreteSlotValueType.Matrix4:
return matOwner.precision + "4x4 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ")";
default:
return "error";
}
return ConcreteSlotValueAsVariable(matOwner.precision);
}
protected virtual string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return "error";
}
public void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

{
var prop = new TextureShaderProperty();
prop.overrideReferenceName = DefaultTextureName;
prop.overrideReferenceName = Texture2DMaterialSlot.DefaultTextureName;
prop.modifiable = false;
prop.generatePropertyBlock = true;
properties.AddShaderProperty(prop);

property.generatePropertyBlock = false;
properties.AddShaderProperty(property);
}
protected static PropertyType ConvertConcreteSlotValueTypeToPropertyType(ConcreteSlotValueType slotValue)
{
switch (slotValue)
{
case ConcreteSlotValueType.Texture2D:
return PropertyType.Texture;
case ConcreteSlotValueType.Vector1:
return PropertyType.Float;
case ConcreteSlotValueType.Vector2:
return PropertyType.Vector2;
case ConcreteSlotValueType.Vector3:
return PropertyType.Vector3;
case ConcreteSlotValueType.Vector4:
return PropertyType.Vector4;
case ConcreteSlotValueType.Matrix2:
return PropertyType.Matrix2;
case ConcreteSlotValueType.Matrix3:
return PropertyType.Matrix3;
case ConcreteSlotValueType.Matrix4:
return PropertyType.Matrix4;
case ConcreteSlotValueType.SamplerState:
return PropertyType.SamplerState;
default:
return PropertyType.Vector4;
}
}
public virtual PreviewProperty GetPreviewProperty(string name)
{
return null;
}
}
}

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/MaterialGraphChange.cs


public Guid guid { get; private set; }
}
public class LayerAdded : GraphChange
{
public LayerAdded(LayeredShaderGraph.Layer layer)
{
this.layer = layer;
}
public LayeredShaderGraph.Layer layer { get; private set; }
}
public class LayerRemoved : GraphChange
{
public LayerRemoved(Guid id)
{
this.id = id;
}
public Guid id { get; private set; }
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightMetallicMasterNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, new Vector4(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, new Vector4(0,0,1), ShaderStage.Fragment));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one, ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector4(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0,0,1), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input,0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 0, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightSpecularMasterNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, new Vector4(0.5f, 0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, new Vector4(0,0,1), ShaderStage.Fragment));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one, ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector3(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0,0,1), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input,0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightUnlitMasterNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 0, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

172
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


get { return true; }
}
public virtual bool allowedInMainGraph
{
get { return true; }
}
public virtual bool allowedInLayerGraph
{
get { return true; }
}
public override bool hasError
{
get { return m_HasError; }

return inputSlot.GetDefaultValue(generationMode);
}
private ConcreteSlotValueType FindCommonChannelType(ConcreteSlotValueType from, ConcreteSlotValueType to)
{
if (ImplicitConversionExists(from, to))
return to;
return ConcreteSlotValueType.Error;
}
private static ConcreteSlotValueType ToConcreteType(SlotValueType svt)
{
switch (svt)
{
case SlotValueType.Vector1:
return ConcreteSlotValueType.Vector1;
case SlotValueType.Vector2:
return ConcreteSlotValueType.Vector2;
case SlotValueType.Vector3:
return ConcreteSlotValueType.Vector3;
case SlotValueType.Vector4:
return ConcreteSlotValueType.Vector4;
case SlotValueType.Texture2D:
return ConcreteSlotValueType.Texture2D;
case SlotValueType.Matrix2:
return ConcreteSlotValueType.Matrix2;
case SlotValueType.Matrix3:
return ConcreteSlotValueType.Matrix3;
case SlotValueType.Matrix4:
return ConcreteSlotValueType.Matrix4;
case SlotValueType.SamplerState:
return ConcreteSlotValueType.SamplerState;
}
return ConcreteSlotValueType.Error;
}
private static bool ImplicitConversionExists(ConcreteSlotValueType from, ConcreteSlotValueType to)
{
if (from == to)

private ConcreteSlotValueType ConvertDynamicInputTypeToConcrete(IEnumerable<ConcreteSlotValueType> inputTypes)
{
var concreteSlotValueTypes = inputTypes as IList<ConcreteSlotValueType> ?? inputTypes.ToList();
if (concreteSlotValueTypes.Any(x => x == ConcreteSlotValueType.Error))
return ConcreteSlotValueType.Error;
var inputTypesDistinct = concreteSlotValueTypes.Distinct().ToList();
switch (inputTypesDistinct.Count)
{

return ordered.FirstOrDefault();
break;
}
return ConcreteSlotValueType.Error;
return ConcreteSlotValueType.Vector1;
var isInError = false;
var isInError = false;
inputSlot.hasError = false;
foreach (var edge in edges)
foreach (var edge in edges)
{
var fromSocketRef = edge.outputSlot;
var outputNode = owner.GetNodeFromGuid(fromSocketRef.nodeGuid);

}
}
var dynamicInputSlotsToCompare = DictionaryPool<MaterialSlot, ConcreteSlotValueType>.Get();
var skippedDynamicSlots = ListPool<MaterialSlot>.Get();
var dynamicInputSlotsToCompare = DictionaryPool<DynamicVectorMaterialSlot, ConcreteSlotValueType>.Get();
var skippedDynamicSlots = ListPool<DynamicVectorMaterialSlot>.Get();
var inputType = inputSlot.valueType;
if (inputType != SlotValueType.Dynamic)
inputSlot.concreteValueType = ToConcreteType(inputType);
else
skippedDynamicSlots.Add(inputSlot);
if (inputSlot is DynamicVectorMaterialSlot)
skippedDynamicSlots.Add(inputSlot as DynamicVectorMaterialSlot);
continue;
}

if (outputSlot == null)
continue;
var outputConcreteType = outputSlot.concreteValueType;
// if we have a standard connection... just check the types work!
if (inputType != SlotValueType.Dynamic)
if (outputSlot.hasError)
var inputConcreteType = ToConcreteType(inputType);
inputSlot.concreteValueType = FindCommonChannelType(outputConcreteType, inputConcreteType);
inputSlot.hasError = true;
var outputConcreteType = outputSlot.concreteValueType;
dynamicInputSlotsToCompare.Add(inputSlot, outputConcreteType);
if (inputSlot is DynamicVectorMaterialSlot)
{
dynamicInputSlotsToCompare.Add((DynamicVectorMaterialSlot) inputSlot, outputConcreteType);
continue;
}
// if we have a standard connection... just check the types work!
if (!ImplicitConversionExists(outputConcreteType, inputSlot.concreteValueType))
inputSlot.hasError = true;
}
// we can now figure out the dynamic slotType

dynamicKvP.Key.concreteValueType = dynamicType;
dynamicKvP.Key.SetConcreteType(dynamicType);
skippedSlot.concreteValueType = dynamicType;
skippedSlot.SetConcreteType(dynamicType);
var inputError = GetInputSlots<MaterialSlot>().Any(x => x.concreteValueType == ConcreteSlotValueType.Error);
var inputError = GetInputSlots<MaterialSlot>().Any(x => x.hasError);
// configure the output slots now
// their slotType will either be the default output slotType

{
outputSlot.hasError = false;
outputSlot.concreteValueType = ConcreteSlotValueType.Error;
outputSlot.hasError = true;
if (outputSlot.valueType == SlotValueType.Dynamic)
if (outputSlot is DynamicVectorMaterialSlot)
outputSlot.concreteValueType = dynamicType;
(outputSlot as DynamicVectorMaterialSlot).SetConcreteType(dynamicType);
outputSlot.concreteValueType = ToConcreteType(outputSlot.valueType);
isInError |= GetOutputSlots<MaterialSlot>().Any(x => x.concreteValueType == ConcreteSlotValueType.Error);
isInError |= GetOutputSlots<MaterialSlot>().Any(x => x.hasError);
isInError |= CalculateNodeHasError();
hasError = isInError;

}
ListPool<MaterialSlot>.Release(skippedDynamicSlots);
DictionaryPool<MaterialSlot, ConcreteSlotValueType>.Release(dynamicInputSlotsToCompare);
ListPool<DynamicVectorMaterialSlot>.Release(skippedDynamicSlots);
DictionaryPool<DynamicVectorMaterialSlot, ConcreteSlotValueType>.Release(dynamicInputSlotsToCompare);
}

{
return false;
}
[Obsolete("Call new override", false)]
public static string ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType slotValue)
public static string GetSlotDimension(ConcreteSlotValueType slotValue)
{
switch (slotValue)
{

return "3";
case ConcreteSlotValueType.Vector4:
return "4";
case ConcreteSlotValueType.Texture2D:
return "Texture2D";
case ConcreteSlotValueType.Matrix2:
return "2x2";
case ConcreteSlotValueType.Matrix3:

case ConcreteSlotValueType.SamplerState:
return "SamplerState";
default:
return "Error";
}

}
}
public static PropertyType ConvertConcreteSlotValueTypeToPropertyType(ConcreteSlotValueType slotValue)
{
switch (slotValue)
{
case ConcreteSlotValueType.Texture2D:
return PropertyType.Texture;
case ConcreteSlotValueType.Vector1:
return PropertyType.Float;
case ConcreteSlotValueType.Vector2:
return PropertyType.Vector2;
case ConcreteSlotValueType.Vector3:
return PropertyType.Vector3;
case ConcreteSlotValueType.Vector4:
return PropertyType.Vector4;
case ConcreteSlotValueType.Matrix2:
return PropertyType.Matrix2;
case ConcreteSlotValueType.Matrix3:
return PropertyType.Matrix3;
case ConcreteSlotValueType.Matrix4:
return PropertyType.Matrix4;
case ConcreteSlotValueType.SamplerState:
return PropertyType.SamplerState;
default:
return PropertyType.Vector4;
}
}
public virtual void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
var validSlots = GetInputSlots<MaterialSlot>().ToArray();

if (edges.Any())
continue;
var pp = new PreviewProperty
{
m_Name = GetVariableNameForSlot(s.id),
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(s.concreteValueType),
m_Vector4 = s.currentValue,
m_Float = s.currentValue.x,
m_Color = s.currentValue
};
properties.Add(pp);
var item = s.GetPreviewProperty(GetVariableNameForSlot(s.id));
if (item == null)
continue;
properties.Add(item);
}
}

if (foundSlot == null)
return;
// preserve the old current value.
addingSlot.currentValue = foundSlot.currentValue;
// now copy over values :)
if (addingSlot is DynamicVectorMaterialSlot && foundSlot is DynamicVectorMaterialSlot)
(addingSlot as DynamicVectorMaterialSlot).value = (foundSlot as DynamicVectorMaterialSlot).value;
if (addingSlot is Vector1MaterialSlot && foundSlot is Vector1MaterialSlot)
(addingSlot as Vector1MaterialSlot).value = (foundSlot as Vector1MaterialSlot).value;
if (addingSlot is Vector2MaterialSlot && foundSlot is Vector2MaterialSlot)
(addingSlot as Vector2MaterialSlot).value = (foundSlot as Vector2MaterialSlot).value;
if (addingSlot is Vector3MaterialSlot && foundSlot is Vector3MaterialSlot)
(addingSlot as Vector3MaterialSlot).value = (foundSlot as Vector3MaterialSlot).value;
if (addingSlot is Vector4MaterialSlot && foundSlot is Vector4MaterialSlot)
(addingSlot as Vector4MaterialSlot).value = (foundSlot as Vector4MaterialSlot).value;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Art/Adjustments/LevelsNode.cs


[Title("Art/Adjustments/Levels")]
public class LevelsNode : CodeFunctionNode
{
[SerializeField]
private float m_InputMin = 0.0f;
[SerializeField]
private float m_InputMax = 1.0f;
[SerializeField]
private float m_InputGamma = 1.0f;
[SerializeField]
private float m_OutputMin = 0.0f;
[SerializeField]
private float m_OutputMax = 1.0f;
public LevelsNode()
{
name = "Levels";

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SplitNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(s_ValidSlots);
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/HLSLNode.cs


{
var attribute = GetSlotAttribute(par);
slots.Add(new MaterialSlot(attribute.slotId, par.Name, par.Name, par.IsOut ? SlotType.Output : SlotType.Input,
ConvertTypeToSlotValueType(par), attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden));
slots.Add(MaterialSlot.CreateMaterialSlot(ConvertTypeToSlotValueType(par), attribute.slotId, par.Name, par.Name, par.IsOut ? SlotType.Output : SlotType.Input,
attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden));
m_Slots.Add(attribute);
}

foreach (var slot in GetSlots<MaterialSlot>())
{
var toReplace = string.Format("{{slot{0}dimension}}", slot.id);
var replacement = ConvertConcreteSlotValueTypeToString(slot.concreteValueType);
var replacement = GetSlotDimension(slot.concreteValueType);
result = result.Replace(toReplace, replacement);
}
return result;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/BitangentNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, new Vector4(0, 0, 1, 1)));
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/NormalNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, new Vector4(0, 0, 1, 1)));
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/PositionNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero, ShaderStage.Vertex));
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero, ShaderStage.Vertex));
RemoveSlotsNameNotMatching(validSlots);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs


public override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector2.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/VertexColorNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.one));
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.one));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ViewDirectionNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(
AddSlot(new Vector3MaterialSlot(
SlotValueType.Vector3,
Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/WorldSpacePositionNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(
AddSlot(new Vector3MaterialSlot(
SlotValueType.Vector3,
Vector4.zero));
Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/WorldSpaceTangentNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, new Vector4(0, 0, 1, 1)));
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs


}
void SetRow(ref Vector2 row, Vector2 value)
{
{
return;
return;
if (onModified != null)
if (onModified != null)
onModified(this, ModificationScope.Graph);
}

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix2, Vector2.zero));
AddSlot(new Matrix2MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs


[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row1
{
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}

if (value == row)
return;
row = value;
if (onModified != null)
if (onModified != null)
onModified(this, ModificationScope.Graph);
}

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix3, Vector3.zero));
AddSlot(new Matrix3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero));
AddSlot(new Matrix4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/MatrixCommonNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero));
AddSlot(new Matrix4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/CameraDirNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/CameraPosNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/SceneData/ScreenPosNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, SlotValueType.Vector3, Vector3.zero));
AddSlot(new Vector4MaterialSlot(kOutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(kOutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlot1Id, kOutputSlot2Id });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time/SinTimeNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.one));
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.one));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time/TimeNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, 0));
RemoveSlotsNameNotMatching(validSlots);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector1Node.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output,0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector2Node.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new Vector2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector3Node.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Vector/Vector4Node.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

29
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs


protected MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
return new Matrix4MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero);
return new Vector4MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, Vector4.zero);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector4, Vector4.zero);
return new Vector4MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, Vector4.zero);
}
protected virtual string GetInputSlot1Name()

protected string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
return string.Format("inline {0} {1} ({2} {3}, {4} {5})", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetFunctionName(), ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType), arg1Name, ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), arg2Name);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetVariableNameForSlot(OutputSlotId), GetFunctionCallBody(input1Value, input2Value)), true);
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
return string.Format("{0} ({1}, {2})", GetFunctionName(), input1Value, input2Value);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

27
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyNode.cs


protected MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
return new Matrix4MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
return new Matrix4MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
return new Matrix4MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output);
}
protected virtual string GetInputSlot1Name()

protected string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
return string.Format("inline {0} {1} ({2} {3}, {4} {5})", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetFunctionName(), ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType), arg1Name, ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), arg2Name);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetVariableNameForSlot(OutputSlotId), GetFunctionCallBody(input1Value, input2Value)), true);
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Property Node")]
public class PropertyNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
public class PropertyNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV, IOnAssetEnabled
{
private Guid m_PropertyGuid;

if (property is FloatShaderProperty)
{
AddSlot(new MaterialSlot(OutputSlotId, "float", "float", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotId, "float", "float", SlotType.Output, 0));
AddSlot(new MaterialSlot(OutputSlotId, "V2", "V2", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new Vector2MaterialSlot(OutputSlotId, "V2", "V2", SlotType.Output, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, "V3", "V3", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, "V3", "V3", SlotType.Output, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, "V4", "V4", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, "V4", "V4", SlotType.Output, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, "Color", "Color", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, "Color", "Color", SlotType.Output, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, "RGBA", "RGBA", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(ROutputSlotId, "R", "R", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(GOutputSlotId, "G", "G", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(BOutputSlotId, "B", "B", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AOutputSlotId, "A", "A", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(TOutputSlotId, "T", "T", SlotType.Output, SlotValueType.Texture2D, Vector4.zero));
AddSlot(new MaterialSlot(UVInput, "UV", "UV", SlotType.Input, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(new[] {OutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId, TOutputSlotId,UVInput});
AddSlot(new Vector4MaterialSlot(OutputSlotId, "RGBA", "RGBA", SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(ROutputSlotId, "R", "R", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(GOutputSlotId, "G", "G", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(BOutputSlotId, "B", "B", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(AOutputSlotId, "A", "A", SlotType.Output, 0));
AddSlot(new Texture2DMaterialSlot(TOutputSlotId, "T", "T", SlotType.Output));
AddSlot(new Vector2MaterialSlot(UVInput, "UV", "UV", SlotType.Input, Vector4.zero));
RemoveSlotsNameNotMatching(new[] {OutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId, TOutputSlotId, UVInput});
}
}

}
}
public sealed override void UpdateNodeAfterDeserialization()
{
base.UpdateNodeAfterDeserialization();
}
public override string GetVariableNameForSlot(int slotId)
{
if (slotId != TOutputSlotId)

base.OnAfterDeserialize();
if (!string.IsNullOrEmpty(m_PropertyGuidSerialized))
m_PropertyGuid = new Guid(m_PropertyGuidSerialized);
}
public void OnEnable()
{
UpdateNode();
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs


Vector4,
Vector3,
Vector2,
Vector1,
Error
Vector1
}
public static class SlotValueHelper

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/VertexInterpolatorNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(InputSlotId, k_InputSlotName, k_InputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero, ShaderStage.Vertex));
AddSlot(new MaterialSlot(OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero, ShaderStage.Fragment));
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, k_InputSlotName, k_InputSlotName, SlotType.Input, Vector4.zero, ShaderStage.Vertex));
AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.zero, ShaderStage.Fragment));
RemoveSlotsNameNotMatching(k_ValidSlots);
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph.meta


fileFormatVersion: 2
guid: 7e981d45b83422d4aa5407e9fe5c7ab5
guid: 605eb5c5a280c014fa0952cd022f2579
timeCreated: 1465559218
licenseType: Pro
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs


{
public abstract class AbstractSubGraphNode : AbstractMaterialNode
, IGeneratesFunction
, IOnAssetEnabled
, IMayRequireNormal
, IMayRequireTangent
, IMayRequireBitangent

get { return null; }
}
public virtual void OnEnable()
public virtual void UpdateSlots()
{
var validNames = new List<int>();
if (referencedGraph == null)

}
var id = prop.guid.GetHashCode();
AddSlot(new MaterialSlot(id, prop.displayName, prop.referenceName, SlotType.Input, slotType, prop.defaultValue));
AddSlot(MaterialSlot.CreateMaterialSlot(slotType, id, prop.displayName, prop.referenceName, SlotType.Input, prop.defaultValue));
validNames.Add(id);
}

foreach (var slot in subGraphOutputNode.GetInputSlots<MaterialSlot>())
{
AddSlot(new MaterialSlot(slot.id, slot.displayName, slot.shaderOutputName, SlotType.Output, slot.valueType, slot.defaultValue));
AddSlot(MaterialSlot.CreateMaterialSlot( slot.valueType,slot.id, slot.displayName, slot.shaderOutputName, SlotType.Output, Vector4.zero));
validNames.Add(slot.id);
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs


get { return m_MaterialOptions; }
}
public virtual PreviewMode previewMode
public override PreviewMode previewMode
{
get { return PreviewMode.Preview3D; }
}

var helper = new RemapGraphHelper();
helper.remapGraph = value;
m_SerializedRemapGraph = EditorJsonUtility.ToJson(helper, true);
OnEnable();
UpdateSlots();
if (onModified != null)
onModified(this, ModificationScope.Topological);

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs


var helper = new SubGraphHelper();
helper.subGraph = value;
m_SerializedSubGraph = EditorJsonUtility.ToJson(helper, true);
OnEnable();
UpdateSlots();
if (onModified != null)
onModified(this, ModificationScope.Topological);

//var validOutputSlots = NodeUtils.GetSlotsThatOutputToNodeRecurse(this, (graph as BaseMaterialGraph).masterNode);
foreach (var slot in GetOutputSlots<MaterialSlot>())
{
var outDimension = ConvertConcreteSlotValueTypeToString(slot.concreteValueType);
outputString.AddShaderChunk(
"float"
+ outDimension
+ " "
+ GetVariableNameForSlot(slot.id)
+ " = 0;", false);
var outDimension = ConvertConcreteSlotValueTypeToString(precision, slot.concreteValueType);
outputString.AddShaderChunk(string.Format("{0} {1} = 0;", outDimension, GetVariableNameForSlot(slot.id)), false);
}
// Step 2...

}
else if (inSlot.concreteValueType == ConcreteSlotValueType.Texture2D)
{
prop.overrideReferenceName = MaterialSlot.DefaultTextureName;
prop.overrideReferenceName = Texture2DMaterialSlot.DefaultTextureName;
}
else
{

66
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs


namespace UnityEngine.MaterialGraph
{
public class SubGraphOutputNode : AbstractSubGraphIONode
{
public SubGraphOutputNode()
{
name = "SubGraphOutputs";
}
[SubGraphOutputControl]
int controlDummy { get; set; }
public override int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;
AddSlot(new MaterialSlot(index, "Output " + index, "Output" + index, SlotType.Input, SlotValueType.Vector4, Vector4.zero));
return index;
}
public override void RemoveSlot()
{
var index = GetInputSlots<ISlot>().Count();
if (index == 0)
return;
RemoveSlot(index);
}
public override bool allowedInRemapGraph { get { return false; } }
}
if (!(node is AbstractSubGraphIONode))
if (!(node is SubGraphOutputNode))
return new SubGraphOutputControlView((AbstractSubGraphIONode)node);
return new SubGraphOutputControlView((SubGraphOutputNode)node);
AbstractSubGraphIONode m_Node;
SubGraphOutputNode m_Node;
public SubGraphOutputControlView(AbstractSubGraphIONode node)
public SubGraphOutputControlView(SubGraphOutputNode node)
{
m_Node = node;
Add(new Button(OnAdd) { text = "Add Slot" });

{
m_Node.RemoveSlot();
}
}
public class SubGraphOutputNode : AbstractMaterialNode
{
[SubGraphOutputControl]
int controlDummy { get; set; }
public SubGraphOutputNode()
{
name = "SubGraphOutputs";
}
public virtual int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;
AddSlot(new Vector4MaterialSlot(index, "Output " + index, "Output" + index, SlotType.Input, Vector4.zero));
return index;
}
public virtual void RemoveSlot()
{
var index = GetInputSlots<ISlot>().Count();
if (index == 0)
return;
RemoveSlot(index);
}
public override bool allowedInRemapGraph { get { return false; } }
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs.meta


fileFormatVersion: 2
guid: ec0207b061e270b4a96a01fbe11c18ca
timeCreated: 1465559219
licenseType: Pro
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs


using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing

}
}
public class LayeredGraphEditWindow : AbstractMaterialGraphEditWindow<LayeredShaderGraph>
{
public override AbstractMaterialGraph GetMaterialGraph()
{
return graphObject == null ? null : graphObject.graph as AbstractMaterialGraph;
}
}
public abstract class AbstractMaterialGraphEditWindow<TGraphType> : HelperMaterialGraphEditWindow where TGraphType : AbstractMaterialGraph
{
[SerializeField]

{
get { return m_GraphObject; }
set
{
{
if (m_GraphObject != null)
DestroyImmediate(m_GraphObject);
m_GraphObject = value;

if (typeof(TGraphType) == typeof(UnityEngine.MaterialGraph.MaterialGraph))
UpdateShaderGraphOnDisk(path);
if (typeof(TGraphType) == typeof(LayeredShaderGraph))
UpdateShaderGraphOnDisk(path);
if (typeof(TGraphType) == typeof(SubGraph))
UpdateAbstractSubgraphOnDisk<SubGraph>(path);

edge => edge.outputSlot,
edge => edge,
(key, edges) => new {slotRef = key, edges = edges.ToList()});
var inputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
var inputNode = new PropertyNode();
var sr = group.slotRef;
var fromNode = graphPresenter.graph.GetNodeFromGuid(sr.nodeGuid);
var fromSlot = fromNode.FindOutputSlot<MaterialSlot>(sr.slotId);

case ConcreteSlotValueType.Vector2:
break;
case ConcreteSlotValueType.Vector1:
break;
case ConcreteSlotValueType.Error:
break;
default:
throw new ArgumentOutOfRangeException();

private void UpdateShaderGraphOnDisk(string path)
{
var graph = graphObject.graph as UnityEngine.MaterialGraph.MaterialGraph;
var graph = graphObject.graph as IShaderGraph;
if (graph == null)
return;

87
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

int m_SelectionHash;
VisualElement m_PropertyItems;
VisualElement m_LayerItems;
VisualElement m_ContentContainer;
AbstractNodeEditorView m_EditorView;

AddStyleSheetPath("Styles/MaterialGraph");
var topContainer = new VisualElement { name = "top" };
var topContainer = new VisualElement {name = "top"};
var headerContainer = new VisualElement { name = "header" };
var headerContainer = new VisualElement {name = "header"};
headerContainer.Add(new VisualElement { name = "title", text = assetName });
headerContainer.Add(new VisualElement {name = "title", text = assetName});
m_ContentContainer = new VisualElement { name = "content" };
m_ContentContainer = new VisualElement {name = "content"};
var bottomContainer = new VisualElement { name = "bottom" };
var bottomContainer = new VisualElement {name = "bottom"};
var propertiesContainer = new VisualElement { name = "properties" };
var propertiesContainer = new VisualElement {name = "properties"};
var header = new VisualElement { name = "header" };
var header = new VisualElement {name = "header"};
var title = new VisualElement { name = "title", text = "Properties" };
var title = new VisualElement {name = "title", text = "Properties"};
var addPropertyButton = new Button(OnAddProperty) { text = "Add", name = "addButton" };
var addPropertyButton = new Button(OnAddProperty) {text = "Add", name = "addButton"};
m_PropertyItems = new VisualContainer { name = "items" };
m_PropertyItems = new VisualContainer {name = "items"};
m_Preview = new Image { name = "preview", image = Texture2D.blackTexture };
//if (m_Presenter.graph is LayeredShaderGraph)
{
var layersContainer = new VisualElement {name = "properties"};
{
var header = new VisualElement {name = "header"};
{
var title = new VisualElement {name = "title", text = "Layers"};
header.Add(title);
var addLayerButton = new Button(OnAddLayer) {text = "Add", name = "addButton"};
header.Add(addLayerButton);
}
propertiesContainer.Add(header);
m_LayerItems = new VisualContainer {name = "items"};
propertiesContainer.Add(m_LayerItems);
}
bottomContainer.Add(layersContainer);
}
m_Preview = new Image {name = "preview", image = Texture2D.blackTexture};
bottomContainer.Add(m_Preview);
}
Add(bottomContainer);

m_Graph.onChange += OnGraphChange;
var layerGraph = m_Graph as LayeredShaderGraph;
if (layerGraph != null)
foreach (var layer in layerGraph.layers)
m_LayerItems.Add(new ShaderLayerView(layerGraph, layer));
// Nodes missing custom editors:
// - PropertyNode

gm.ShowAsContext();
}
void OnAddLayer()
{
var layerGraph = m_Graph as LayeredShaderGraph;
if (layerGraph == null)
return;
layerGraph.AddLayer();
}
void AddProperty(IShaderProperty property)
{
m_Graph.owner.RegisterCompleteObjectUndo("Add Property");

m_SelectedNodes.Clear();
m_SelectedNodes.AddRange(nodes);
var selectionHash = UIUtilities.GetHashCode(m_SelectedNodes.Count, m_SelectedNodes != null ? m_SelectedNodes.FirstOrDefault() : null);
var selectionHash = UIUtilities.GetHashCode(m_SelectedNodes.Count,
m_SelectedNodes != null ? m_SelectedNodes.FirstOrDefault() : null);
if (selectionHash != m_SelectionHash)
{
m_SelectionHash = selectionHash;

var element = new VisualElement { name = "selectionCount", text = string.Format("{0} nodes selected.", m_SelectedNodes.Count) };
var element = new VisualElement
{
name = "selectionCount",
text = string.Format("{0} nodes selected.", m_SelectedNodes.Count)
};
var view = (AbstractNodeEditorView)Activator.CreateInstance(m_TypeMapper.MapType(node.GetType()));
var view = (AbstractNodeEditorView) Activator.CreateInstance(m_TypeMapper.MapType(node.GetType()));
view.node = node;
m_ContentContainer.Add(view);
}

var propertyView = m_PropertyItems.OfType<ShaderPropertyView>().FirstOrDefault(v => v.property.guid == propertyRemoved.guid);
if (propertyView != null)
m_PropertyItems.Remove(propertyView);
}
var layerGraph = m_Graph as LayeredShaderGraph;
if (layerGraph == null)
return;
var layerAdded = change as LayerAdded;
if (layerAdded != null)
m_LayerItems.Add(new ShaderLayerView(layerGraph, layerAdded.layer));
var layerRemoved = change as LayerRemoved;
if (layerRemoved != null)
{
var view = m_LayerItems.OfType<ShaderLayerView>().FirstOrDefault(v => v.layer.guid == layerRemoved.id);
if (view != null)
m_LayerItems.Remove(view);
}
}

56
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
var newValue = SlotField(m_Slot);
if (newValue != m_Slot.currentValue)
{
m_Slot.currentValue = newValue;
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
}
var modified = SlotField(m_Slot);
if (modified)
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
static Vector4 SlotField(MaterialSlot slot)
public static bool SlotField(MaterialSlot slot)
if (slot.concreteValueType == ConcreteSlotValueType.Vector1)
return new Vector4(EditorGUILayout.FloatField(slot.displayName, slot.currentValue.x), 0, 0, 0);
if (slot.concreteValueType == ConcreteSlotValueType.Vector2)
return EditorGUILayout.Vector2Field(slot.displayName, slot.currentValue);
if (slot.concreteValueType == ConcreteSlotValueType.Vector3)
return EditorGUILayout.Vector3Field(slot.displayName, slot.currentValue);
if (slot.concreteValueType == ConcreteSlotValueType.Vector4)
return EditorGUILayout.Vector4Field(slot.displayName, slot.currentValue);
return Vector4.zero;
EditorGUI.BeginChangeCheck();
if (slot is DynamicVectorMaterialSlot)
{
var dynSlot = slot as DynamicVectorMaterialSlot;
dynSlot.value = EditorGUILayout.Vector4Field(slot.displayName, dynSlot.value);
}
if (slot is Vector1MaterialSlot)
{
var dynSlot = slot as Vector1MaterialSlot;
dynSlot.value = EditorGUILayout.FloatField(slot.displayName, dynSlot.value);
}
if (slot is Vector2MaterialSlot)
{
var dynSlot = slot as Vector2MaterialSlot;
dynSlot.value = EditorGUILayout.Vector2Field(slot.displayName, dynSlot.value);
}
if (slot is Vector3MaterialSlot)
{
var dynSlot = slot as Vector3MaterialSlot;
dynSlot.value = EditorGUILayout.Vector3Field(slot.displayName, dynSlot.value);
}
if (slot is Vector4MaterialSlot)
{
var dynSlot = slot as Vector4MaterialSlot;
dynSlot.value = EditorGUILayout.Vector4Field(slot.displayName, dynSlot.value);
}
return EditorGUI.EndChangeCheck();
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs


private Material m_CheckerboardMaterial;
private static readonly Mesh[] s_Meshes = { null, null, null, null, null };
private static Mesh s_PlaneMesh;
private static readonly GUIContent[] s_MeshIcons = { null, null, null, null, null };
private static readonly GUIContent[] s_LightIcons = { null, null };
private static readonly GUIContent[] s_TimeIcons = { null, null };

Mesh quadMesh = Resources.GetBuiltinResource(typeof(Mesh), "Quad.fbx") as Mesh;
s_Meshes[4] = quadMesh;
s_PlaneMesh = quadMesh;
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs


using System.Linq;
using UnityEditor.MaterialGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

if (!slots.Any())
return ModificationScope.Nothing;
EditorGUI.BeginChangeCheck();
var modified = false;
slot.currentValue = EditorGUILayout.Vector4Field(slot.displayName, slot.currentValue);
modified |= IMGUISlotEditorView.SlotField(slot);
return EditorGUI.EndChangeCheck() ? ModificationScope.Node : ModificationScope.Nothing;
return modified ? ModificationScope.Node : ModificationScope.Nothing;
}
}
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs


{
EditorGUI.BeginChangeCheck();
var result = (UISlotValueType)EditorGUILayout.EnumPopup(ToUISlot(slot.valueType));
slot.valueType = ToSlotValueType(result);
var chantedTo = ToSlotValueType(result);
{
MaterialSlot.CreateMaterialSlot(chantedTo, slot.id, slot.RawDisplayName(), slot.shaderOutputName, slot.slotType, Vector4.zero);
}
}
GUILayout.Space(10);

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphAnchorPresenter.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEdgePresenter.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


if (startSlot == null)
return compatibleAnchors;
var goingBackwards = startSlot.isOutputSlot;
var startStage = startSlot.shaderStage;
if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);

continue;
if (candidateSlot.owner == startSlot.owner)
continue;
if (!startSlot.IsCompatibleWithInputSlotType(candidateSlot.valueType))
if (!startSlot.IsCompatibleWithInputSlotType(candidateSlot.concreteValueType))
continue;
if (startStage != ShaderStage.Dynamic)

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


}
else
{
List<PropertyCollector.TextureInfo> defaultTextures;
PreviewMode mode;
previewData.shaderString = m_Graph.GetPreviewShader(node, out mode);
previewData.previewMode = mode;

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.UIElements.GraphView;

using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Experimental.UIElements;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using MouseButton = UnityEngine.Experimental.UIElements.MouseButton;

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs


using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine.MaterialGraph;
using Debug = System.Diagnostics.Debug;
[CustomEditor(typeof(MasterRemapGraphImporter))]

}
}
private static void ShowGraphEditWindow(string path)
private static bool ShowGraphEditWindow(string path)
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
var asset = AssetDatabase.LoadAssetAtPath<Object>(path) as MasterRemapGraphAsset;
if (asset == null)
return false;
var windows = Resources.FindObjectsOfTypeAll<MasterReampGraphEditWindow>();
bool foundWindow = false;
foreach (var w in windows)

window.Show();
window.ChangeSelection(asset);
}
return true;
}
[OnOpenAsset]
static bool OnOpenAsset(int instanceID, int line)
{
var path = AssetDatabase.GetAssetPath(instanceID);
return ShowGraphEditWindow(path);
}
}

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs


using System.IO;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using UnityEngine.Events;
class ShaderGraphTextGenerator : ICustomShaderImporter
class ShaderGraphImporter : ICustomShaderImporter
public string GetShaderText(string path)
private static string GetShaderText<T>(string path) where T : IShaderGraph
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph);
var graph = JsonUtility.FromJson<T>(textGraph);
var name = Path.GetFileNameWithoutExtension(path);

return null;
}
public string GetShaderText(string path)
{
if (path.EndsWith("LayeredShaderGraph", StringComparison.InvariantCultureIgnoreCase))
return GetShaderText<LayeredShaderGraph>(path);
if (path.EndsWith("shaderGraph", StringComparison.InvariantCultureIgnoreCase))
return GetShaderText<MaterialGraph>(path);
return null;
}
try
{
var textGraph = File.ReadAllText(path, Encoding.UTF8);
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph);
return graph != null;
}
catch (Exception)
{
// ignored
}
return false;
return
path.EndsWith("LayeredShaderGraph", StringComparison.InvariantCultureIgnoreCase)
|| path.EndsWith("shaderGraph", StringComparison.InvariantCultureIgnoreCase);
}
public void OpenAsset(string path)

private static void ShowGraphEditWindow(string path)
internal static void ShowGraphEditWindow(string path)
{
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
var extension = Path.GetExtension(path);

else if (extension == ".LayeredShaderGraph")
windowType = typeof(LayeredGraphEditWindow);
else if (extension == ".ShaderRemapGraph")
windowType = typeof(MasterRemapGraph);
var windows = Resources.FindObjectsOfTypeAll(windowType);
bool foundWindow = false;
foreach (var w in windows.OfType<IMaterialGraphEditWindow>())

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderSubGraphImporterEditor.cs


using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine.MaterialGraph;
using Debug = System.Diagnostics.Debug;
[CustomEditor(typeof(ShaderSubGraphImporter))]

}
}
private static void ShowGraphEditWindow(string path)
private static bool ShowGraphEditWindow(string path)
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
var asset = AssetDatabase.LoadAssetAtPath<Object>(path) as MaterialSubGraphAsset;
if (asset == null)
return false;
var windows = Resources.FindObjectsOfTypeAll<SubGraphEditWindow>();
bool foundWindow = false;
foreach (var w in windows)

window.Show();
window.ChangeSelection(asset);
}
return true;
}
[OnOpenAsset]
static bool OnOpenAsset(int instanceID, int line)
{
var path = AssetDatabase.GetAssetPath(instanceID);
return ShowGraphEditWindow(path);
}
}

72
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add-Sub-Graph.ShaderSubGraph
文件差异内容过多而无法显示
查看文件

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add.ShaderGraph
文件差异内容过多而无法显示
查看文件

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add.ShaderGraph.meta


fileFormatVersion: 2
guid: 6b526455b2500458f9e378534990c26c
timeCreated: 1504702289
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/AddSubGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/AddSubGraph.ShaderGraph.meta


fileFormatVersion: 2
guid: f20399762b45e564fbe7b65ab460a5b6
timeCreated: 1504702299
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []

190
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph
文件差异内容过多而无法显示
查看文件

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph.meta


fileFormatVersion: 2
guid: a8cb0d181b460aa4bac2693ce3bfc1ad
timeCreated: 1504881039
licenseType: Pro
nonModifiableTextures:
- Texture2D_Texture2D_CF0DB0B2_Uniform: {fileID: 2800000, guid: 7296f51323ae9485a9c834c4e3d722ed,
type: 3}
- Texture2D_Texture2D_D8FD66BB_Uniform: {fileID: -931156776, guid: b69a7e88e13e24260acb38513f619ff2,
type: 3}
- Texture2D_Texture2D_DF8FC6BF_Uniform: {fileID: 2800000, guid: 9d64a9e7ca6864704ae6b8ca7afc9d85,
type: 3}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Multiply.ShaderGraph
文件差异内容过多而无法显示
查看文件

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Multiply.ShaderGraph.meta


fileFormatVersion: 2
guid: 3b1382b7bb78a4162b89a4f706240f08
timeCreated: 1504702329
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []

68
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph
文件差异内容过多而无法显示
查看文件

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph.meta


fileFormatVersion: 2
guid: 3782c62dd61732042aed83e579a22e5f
timeCreated: 1504702334
licenseType: Pro
- Texture2D_Texture2D_FCC444C7_Uniform: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7,
type: 3}
- Texture_BBB67AA7: {fileID: 2800000, guid: 618126695341ad844ac048b062fd2688, type: 3}
userData:
assetBundleName:
assetBundleVariant:

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/TextureSample.ShaderGraph
文件差异内容过多而无法显示
查看文件

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/TextureSample.ShaderGraph.meta


fileFormatVersion: 2
guid: 0bf1c65d8d6ab4c1f8476fb1cf9eb20a
timeCreated: 1504702365
licenseType: Pro
- Texture2D_Texture2D_ED131035_Uniform: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8,
type: 3}
- Texture_AD00096F: {fileID: 2800000, guid: 55fd692de65e703408cbda23b0eae8d0, type: 3}
userData:
assetBundleName:
assetBundleVariant:

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs


private class TestableMNode : AbstractMaterialNode
{}
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/DynamicSlotTests.cs


public DynamicNode()
{
AddSlot(new MaterialSlot(DynIn1, "DynIn1", "DynIn1", SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(DynIn2, "DynIn2", "DynIn2", SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(DynOut, "DynOut", "DynOut", SlotType.Output, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(DynIn1, "DynIn1", "DynIn1", SlotType.Input, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(DynIn2, "DynIn2", "DynIn2", SlotType.Input, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(DynOut, "DynOut", "DynOut", SlotType.Output, Vector4.zero));
}
}

public TestNode()
{
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector1MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, 0));
AddSlot(new Vector2MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, Vector4.zero));
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

18
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs


public TestNode()
{
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector1MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, 0));
AddSlot(new Vector2MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, Vector4.zero));
AddSlot(new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V2In, "V2In", "V2In", SlotType.Input, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector1MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, 0));
AddSlot(new Vector2MaterialSlot(V2In, "V2In", "V2In", SlotType.Input, Vector4.zero));
AddSlot(new Vector3MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, Vector4.zero));
AddSlot(new Vector4MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, Vector4.zero));
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs


[TestFixture]
public class MaterialGraphTests
{
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs


public TestNode()
{
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new Vector1MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, 0));
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

[Test]
public void ReplacingMaterialSlotPreservesTheOldCurrentValue()
{
m_NodeA.AddSlot(new MaterialSlot(TestNode.V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.one));
m_NodeA.AddSlot(new Vector1MaterialSlot(TestNode.V1In, "V1In", "V1In", SlotType.Input, 0));
var slot = m_NodeA.GetInputSlots<MaterialSlot>().FirstOrDefault();
var slot = m_NodeA.GetInputSlots<Vector1MaterialSlot>().FirstOrDefault();
Assert.AreEqual(Vector4.zero, slot.currentValue);
Assert.AreEqual(Vector4.zero, slot.value);
Assert.AreEqual(string.Empty, AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector1));
Assert.AreEqual("2", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector2));
Assert.AreEqual("3", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector3));
Assert.AreEqual("4", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Vector4));
Assert.AreEqual("Texture2D", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Texture2D));
Assert.AreEqual("2x2", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix2));
Assert.AreEqual("3x3", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix3));
Assert.AreEqual("4x4", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Matrix4));
Assert.AreEqual("SamplerState", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.SamplerState));
Assert.AreEqual("Error", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType.Error));
Assert.AreEqual(string.Empty, AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Vector1));
Assert.AreEqual("2", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Vector2));
Assert.AreEqual("3", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Vector3));
Assert.AreEqual("4", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Vector4));
Assert.AreEqual("Texture2D", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Texture2D));
Assert.AreEqual("2x2", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Matrix2));
Assert.AreEqual("3x3", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Matrix3));
Assert.AreEqual("4x4", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.Matrix4));
Assert.AreEqual("SamplerState", AbstractMaterialNode.GetSlotDimension(ConcreteSlotValueType.SamplerState));
}
[Test]

m_NodeA.CollectPreviewMaterialProperties(properties);
var slot = m_NodeA.GetInputSlots<MaterialSlot>().FirstOrDefault();
var slot = m_NodeA.GetInputSlots<Vector1MaterialSlot>().FirstOrDefault();
Assert.AreEqual(1, properties.Count);
var pp = properties.FirstOrDefault();

Assert.AreEqual(slot.currentValue, pp.m_Vector4);
Assert.AreEqual(slot.value, pp.m_Vector4);
}
[Test]

92
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs


using System;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

class TestNode : AbstractMaterialNode
{
public const int V1In = 1;
public const int V2In = 2;
public const int V3In = 3;
public const int V4In = 4;
public readonly MaterialSlot slot;
public readonly Vector1MaterialSlot slot1;
public readonly Vector2MaterialSlot slot2;
public readonly Vector3MaterialSlot slot3;
public readonly Vector4MaterialSlot slot4;
slot = new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero);
AddSlot(slot);
slot1 = new Vector1MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, 0);
AddSlot(slot1);
slot2 = new Vector2MaterialSlot(V2In, "V2In", "V2In", SlotType.Input, Vector2.zero);
AddSlot(slot2);
slot3 = new Vector3MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, Vector3.zero);
AddSlot(slot3);
slot4 = new Vector4MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, Vector4.zero);
AddSlot(slot4);
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

}
[Test]
public void CanUpdateMaterialSlotDisplayName()
public void SlotDisplayNameIsCorrect()
Assert.AreEqual(displayName + "(1)", m_NodeA.slot1.displayName);
var slot = m_NodeA.slot;
slot.displayName = displayName;
Assert.AreEqual(displayName + "(2)", m_NodeA.slot2.displayName);
slot.valueType = SlotValueType.Vector1;
Assert.AreEqual(displayName + "(1)", slot.displayName);
Assert.AreEqual(displayName + "(3)", m_NodeA.slot3.displayName);
slot.valueType = SlotValueType.Vector2;
Assert.AreEqual(displayName + "(2)", slot.displayName);
slot.valueType = SlotValueType.Vector3;
Assert.AreEqual(displayName + "(3)", slot.displayName);
slot.valueType = SlotValueType.Vector4;
Assert.AreEqual(displayName + "(4)", slot.displayName);
slot.valueType = SlotValueType.Dynamic;
Assert.AreEqual(displayName + "(4)", slot.displayName);
Assert.AreEqual(displayName + "(4)", m_NodeA.slot4.displayName);
var slot = m_NodeA.slot;
slot.defaultValue = Vector4.one;
var slot = m_NodeA.slot1;
slot.value = 1;
Assert.AreEqual(Vector4.one, slot.defaultValue);
}

var slot = m_NodeA.slot;
slot.currentValue = Vector4.one;
Assert.AreEqual(Vector4.one, slot.currentValue);
}
[Test]
public void CanUpdateMaterialSlotValueType()
{
var slot = m_NodeA.slot;
slot.valueType = SlotValueType.Vector3;
Assert.AreEqual(SlotValueType.Vector3, slot.valueType);
var slot = m_NodeA.slot1;
slot.value = 1;
Assert.AreEqual(Vector4.one, 1);
}
/* [Test]

public void MaterialSlotReturnsValidDefaultValue()
{
string expected = string.Format("{0}", m_NodeA.GetVariableNameForSlot(TestNode.V1In));
var slot = m_NodeA.slot;
var result = slot.GetDefaultValue(GenerationMode.Preview);
var result = m_NodeA.slot1.GetDefaultValue(GenerationMode.Preview);
slot.valueType = SlotValueType.Vector1;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.ForReals);
m_NodeA.slot1.value = 6;
result = m_NodeA.slot1.GetDefaultValue(GenerationMode.ForReals);
slot.valueType = SlotValueType.Vector2;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.ForReals);
m_NodeA.slot2.value = new Vector4(6, 6, 6, 1);
result = m_NodeA.slot1.GetDefaultValue(GenerationMode.ForReals);
slot.valueType = SlotValueType.Vector3;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.ForReals);
m_NodeA.slot3.value = new Vector4(6, 6, 6, 1);
result = m_NodeA.slot3.GetDefaultValue(GenerationMode.ForReals);
slot.valueType = SlotValueType.Vector4;
slot.currentValue = new Vector4(6, 6, 6, 1);
result = slot.GetDefaultValue(GenerationMode.ForReals);
m_NodeA.slot4.value = new Vector4(6, 6, 6, 1);
result = m_NodeA.slot3.GetDefaultValue(GenerationMode.ForReals);
Assert.AreEqual("half4 (6,6,6,1)", result);
}

83
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyGeneratorTests.cs


namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
public class PropertyGeneratorTests
{
[TestFixtureSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();
}
/*
[TestFixture]
public class PropertyGeneratorTests
{
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();
}
private const string kPropertyName = "ThePropertyName";
private const string kPropertyDescription = "ThePropertyDescription";
private const string kPropertyName = "ThePropertyName";
private const string kPropertyDescription = "ThePropertyDescription";
/* [Test]
public void TestCanAddPropertyChunkToPropertyGenerator()
{
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
[Test]
public void TestCanAddPropertyChunkToPropertyGenerator()
{
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
Assert.AreNotEqual(string.Empty, generator.GetPropertiesBlock(0));
}
Assert.AreNotEqual(string.Empty, generator.GetPropertiesBlock(0));
}
[Test]
public void TestCanGetShaderStringWithIndentWorks()
{
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
[Test]
public void TestCanGetShaderStringWithIndentWorks()
{
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
Assert.AreEqual(0, generator.GetPropertiesBlock(0).Count(x => x == '\t'));
Assert.AreEqual(1, generator.GetPropertiesBlock(1).Count(x => x == '\t'));
Assert.AreEqual(2, generator.GetPropertiesBlock(2).Count(x => x == '\t'));
}
Assert.AreEqual(0, generator.GetPropertiesBlock(0).Count(x => x == '\t'));
Assert.AreEqual(1, generator.GetPropertiesBlock(1).Count(x => x == '\t'));
Assert.AreEqual(2, generator.GetPropertiesBlock(2).Count(x => x == '\t'));
}
[Test]
public void TestCanGetConfiguredTextureInfos()
{
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Bump, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.Modifiable);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
[Test]
public void TestCanGetConfiguredTextureInfos()
{
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Bump, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.Modifiable);
var generator = new PropertyCollector();
generator.AddShaderProperty(chunk);
var infos = generator.GetConfiguredTexutres();
Assert.AreEqual(1, infos.Count);
Assert.AreEqual(kPropertyName, infos[0].name);
Assert.AreEqual(0, infos[0].textureId);
Assert.AreEqual(TexturePropertyChunk.ModifiableState.Modifiable, infos[0].modifiable);
}*/
}
var infos = generator.GetConfiguredTexutres();
Assert.AreEqual(1, infos.Count);
Assert.AreEqual(kPropertyName, infos[0].name);
Assert.AreEqual(0, infos[0].textureId);
Assert.AreEqual(TexturePropertyChunk.ModifiableState.Modifiable, infos[0].modifiable);
}
}*/
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs


[TestFixture]
public class ShaderGeneratorTests
{
[TestFixtureSetUp]
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Debug.unityLogger.logHandler = new ConsoleLogHandler();

public TestNode()
{
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Vector1MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, 0));
AddSlot(new Vector2MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, Vector4.zero));
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.Graphing.Util
{

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateLayeredShaderGraph.cs


using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph
{
public class CreateLayeredShaderGraph : EndNameEditAction
{
[MenuItem("Assets/Create/Layered Shader Graph", false, 208)]
public static void CreateLayeredGraph()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateLayeredShaderGraph>(),
"New Layerd Shader Graph.LayeredShaderGraph", null, null);
}
public override void Action(int instanceId, string pathName, string resourceFile)
{
var graph = new LayeredShaderGraph();
graph.AddNode(new LayerWeightsOutputNode());
File.WriteAllText(pathName, EditorJsonUtility.ToJson(graph));
AssetDatabase.Refresh();
}
}
}

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存