浏览代码

[shader graph]Start adding UI to the graph view.

/main
Tim Cooper 9 年前
当前提交
4d5ee48d
共有 27 个文件被更改,包括 229 次插入1985 次删除
  1. 10
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  2. 174
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  3. 23
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs
  4. 13
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/SimpleWidgets.cs
  5. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/MaterialGraphEditor.cs
  6. 38
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs
  7. 25
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialOptions.cs
  8. 55
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  9. 5
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  10. 24
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs
  11. 1
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SlotValue.cs
  12. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphInputsNode.cs
  13. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphOutputsNode.cs
  14. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs
  15. 73
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/MaterialProperties.cs
  16. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs.meta
  17. 82
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs
  18. 86
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraphGUI.cs
  19. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraphGUI.cs.meta
  20. 55
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraphGUI.cs
  21. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraphGUI.cs.meta
  22. 34
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraphGUI.cs
  23. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraphGUI.cs.meta
  24. 1001
      UnityProject/Assets/UnityShaderEditor/Graphs/FresnelFromSGraph.ShaderGraph
  25. 6
      UnityProject/Assets/UnityShaderEditor/Graphs/FresnelFromSGraph.ShaderGraph.meta
  26. 461
      UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph
  27. 4
      UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph.meta

10
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;

GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}
}
public static void OnGUI(List<CanvasElement> selection)
{
foreach (var selected in selection.Where(x => x is DrawableMaterialNode).Cast<DrawableMaterialNode>())
{
selected.m_Node.OnGUI();
break;
}
}
}

174
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class MaterialGraphDataSource : ICanvasDataSource
{
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>();
public MaterialGraph graph { get; set; }
public ICollection<DrawableMaterialNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
Debug.Log("trying to convert");
var pixelGraph = graph.currentGraph;
foreach (var node in pixelGraph.nodes)
{
// add the nodes
var bmn = node as BaseMaterialNode;
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this));
}
// Add the edges now
var drawableEdges = new List<Edge<NodeAnchor>>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.outputSlots)
{
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot);
foreach (var edge in slot.edges)
{
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == edge.toSlot.node);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == edge.toSlot);
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor));
}
}
}
var toReturn = new List<CanvasElement>();
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
Debug.LogFormat("REturning {0} nodes", toReturn.Count);
return toReturn.ToArray();
}
public void DeleteElement(CanvasElement e)
{
Debug.Log("Trying to delete " + e);
if (e is Edge<NodeAnchor>)
{
//find the edge
var localEdge = (Edge<NodeAnchor>) e;
var edge = graph.currentGraph.edges.FirstOrDefault(x => x.fromSlot == localEdge.Left.m_Slot && x.toSlot == localEdge.Right.m_Slot);
Debug.Log("Deleting edge " + edge + " " + ((DrawableMaterialNode) e).m_Node);
graph.currentGraph.RemoveEdge(edge);
}
else if (e is DrawableMaterialNode)
{
Debug.Log("Deleting node " + e + " " + ((DrawableMaterialNode) e).m_Node);
graph.currentGraph.RemoveNode(((DrawableMaterialNode) e).m_Node);
}
e.ParentCanvas().ReloadData();
e.ParentCanvas().Repaint();
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
var pixelGraph = graph.currentGraph;
pixelGraph.Connect(a.m_Slot, b.m_Slot);
}
}
}
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class MaterialGraphDataSource : ICanvasDataSource
{
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>();
public MaterialGraph graph { get; set; }
public ICollection<DrawableMaterialNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
Debug.Log("trying to convert");
var pixelGraph = graph.currentGraph;
foreach (var node in pixelGraph.nodes)
{
// add the nodes
var bmn = node as BaseMaterialNode;
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this));
}
// Add the edges now
var drawableEdges = new List<Edge<NodeAnchor>>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.outputSlots)
{
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot);
foreach (var edge in slot.edges)
{
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == edge.toSlot.node);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == edge.toSlot);
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor));
}
}
}
var toReturn = new List<CanvasElement>();
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
Debug.LogFormat("REturning {0} nodes", toReturn.Count);
return toReturn.ToArray();
}
public void DeleteElement(CanvasElement e)
{
Debug.Log("Trying to delete " + e);
if (e is Edge<NodeAnchor>)
{
//find the edge
var localEdge = (Edge<NodeAnchor>) e;
var edge = graph.currentGraph.edges.FirstOrDefault(x => x.fromSlot == localEdge.Left.m_Slot && x.toSlot == localEdge.Right.m_Slot);
Debug.Log("Deleting edge " + edge);
graph.currentGraph.RemoveEdge(edge);
}
else if (e is DrawableMaterialNode)
{
Debug.Log("Deleting node " + e + " " + ((DrawableMaterialNode) e).m_Node);
graph.currentGraph.RemoveNode(((DrawableMaterialNode) e).m_Node);
}
e.ParentCanvas().ReloadData();
e.ParentCanvas().Repaint();
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
var pixelGraph = graph.currentGraph;
pixelGraph.Connect(a.m_Slot, b.m_Slot);
}
}
}

23
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs


private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private MaterialGraphDataSource m_DataSource;
private Vector2 m_ScrollPos;
private bool m_NodeExpanded;
private bool shouldRepaint
{

}
//m_Canvas.dataSource = m_ActiveGraph;
m_Canvas.OnGUI(this, new Rect(0, 0, position.width, position.height));
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height));
RenderOptions(m_MaterialGraph);
}
public void RenderOptions(MaterialGraph graph)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, EditorStyles.textArea, GUILayout.Width(250), GUILayout.ExpandHeight(true));
graph.materialOptions.DoGUI();
EditorGUILayout.Separator();
graph.materialProperties.DoGUI(graph.currentGraph.nodes);
m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded);
if (m_NodeExpanded)
DrawableMaterialNode.OnGUI(m_Canvas.Selection);
GUILayout.EndScrollView();
EditorGUILayout.EndHorizontal();
}
public static void DebugMaterialGraph(string s)

13
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/SimpleWidgets.cs


base.Render(parentRect, canvas);
}
}
public class MoveableBox : SimpleBox
{
public MoveableBox(Vector2 position, float width)

AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}
internal class ResizableBox : SimpleBox

m_Title = "Resize me!";
AddManipulator(new Resizable());
AddManipulator(new Draggable());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/MaterialGraphEditor.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditorInternal;
using UnityEngine;

if (materialGraph == null)
return;
UnityEngine.Material mat = materialGraph.GetMaterial();
Material mat = materialGraph.GetMaterial();
m_PreviewUtility.m_Camera.transform.position = -Vector3.forward * 5;
m_PreviewUtility.m_Camera.transform.rotation = Quaternion.identity;
m_PreviewUtility.m_Light[0].intensity = 1.0f;

38
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs


private PixelGraph m_PixelGraph;
[SerializeField]
private Shader m_Shader;
private bool m_Expanded;
return m_Shader.GetInstanceID();
return -1;
//return m_Shader.GetInstanceID();
}
public MaterialProperties materialProperties { get { return m_MaterialProperties; } }

m_PixelGraph.previewState = (PreviewState)sender;
}
public void UpdateShaderSource(string src, Dictionary<string, Texture> defaultTexutres)
{
ShaderUtil.UpdateShaderAsset(m_Shader, src);
EditorMaterialUtility.SetShaderDefaults(m_Shader, defaultTexutres.Keys.ToArray(), defaultTexutres.Values.ToArray());
}
}
if (m_Shader == null)
{
const string shaderSource = "Shader \"Graphs/Dummy\" {" +
"Properties { _Color (\"Main Color\", Color) = (1,1,1,0) }" +
"SubShader {" +
" Tags { \"Queue\" = \"Transparent\" }" +
" Pass {" +
" Blend One One ZWrite Off ColorMask RGB" +
" Material { Diffuse [_Color] Ambient [_Color] }" +
" Lighting On" +
" SetTexture [_Dummy] { combine primary double, primary }" +
" }" +
"}" +
"}";
m_Shader = ShaderUtil.CreateShaderAsset(shaderSource);
m_Shader.name = name;
m_Shader.hideFlags = HideFlags.HideInHierarchy;
}
AssetDatabase.AddObjectToAsset(m_Shader, this);
}
private Material m_Material;
return m_PixelGraph.GetMaterial();
}
}

25
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialOptions.cs


using System;
using UnityEngine;
namespace UnityEditor.MaterialGraph

[SerializeField]
private bool m_HalfAsView;
[SerializeField]
private bool m_Expanded;
public void Init()
{
srcBlend = BlendMode.One;

private Vector2 m_ScrollPos;
public void DoGUI()
{
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos);
m_Expanded = MaterialGraphStyles.Header("Options", m_Expanded);
srcBlend = (BlendMode)EditorGUILayout.EnumPopup("Src Blend", srcBlend);
dstBlend = (BlendMode)EditorGUILayout.EnumPopup("Dst Blend", dstBlend);
cullMode = (CullMode)EditorGUILayout.EnumPopup("Cull Mode", cullMode);
zTest = (ZTest)EditorGUILayout.EnumPopup("Z Test", zTest);
zWrite = (ZWrite)EditorGUILayout.EnumPopup("Z Write", zWrite);
renderQueue = (RenderQueue)EditorGUILayout.EnumPopup("Render Queue", renderQueue);
renderType = (RenderType)EditorGUILayout.EnumPopup("Render Type", renderType);
if (m_Expanded)
{
srcBlend = (BlendMode) EditorGUILayout.EnumPopup("Src Blend", srcBlend);
dstBlend = (BlendMode) EditorGUILayout.EnumPopup("Dst Blend", dstBlend);
cullMode = (CullMode) EditorGUILayout.EnumPopup("Cull Mode", cullMode);
zTest = (ZTest) EditorGUILayout.EnumPopup("Z Test", zTest);
zWrite = (ZWrite) EditorGUILayout.EnumPopup("Z Write", zWrite);
renderQueue = (RenderQueue) EditorGUILayout.EnumPopup("Render Queue", renderQueue);
renderType = (RenderType) EditorGUILayout.EnumPopup("Render Type", renderType);
}
GUILayout.EndScrollView();
}
public BlendMode srcBlend { get { return m_SrcBlend; } set { m_SrcBlend = value; } }

55
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


m_Material = new Material(defaultPreviewShader) {hideFlags = HideFlags.DontSave};
UpdatePreviewMaterial();
}
return m_Material;
}
}

dependentNode.UpdatePreviewMaterial();
}
public void UpdatePreviewProperties()
public static void UpdateMaterialProperties(BaseMaterialNode target, Material material)
if (!hasPreview)
return;
var childrenNodes = CollectChildNodesByExecutionOrder();
var childrenNodes = target.CollectChildNodesByExecutionOrder();
SetPreviewMaterialProperty (prop, previewMaterial);
SetPreviewMaterialProperty(prop, material);
}
public void UpdatePreviewProperties()
{
if (!hasPreview)
return;
UpdateMaterialProperties(this, previewMaterial);
}
#endregion

return "Error";
}
}
public virtual void OnGUI()
{
EditorGUILayout.LabelField("Preview Mode: " + previewMode);
foreach (var slot in slots)
DoSlotUI(this, slot);
}
private static void DoSlotUI(BaseMaterialNode node, Slot slot)
{
GUILayout.BeginHorizontal(/*EditorStyles.inspectorBig*/);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Slot " + slot.title, EditorStyles.largeLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
DoMaterialSlotUIBody(node, slot);
}
private static void DoMaterialSlotUIBody(BaseMaterialNode node, Slot slot)
{
SlotValue value = node.GetSlotDefaultValue(slot.name);
if (value == null)
return;
var def = node.GetSlotDefaultValue(slot.name);
if (def != null && def.OnGUI())
{
node.UpdatePreviewProperties();
node.ForwardPreviewMaterialPropertyUpdate();
}
}
}

5
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs


var resultShader = ShaderGenerator.GenerateSurfaceShader(pixelGraph.owner, shaderName, true, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;
InternalUpdatePreviewShader(resultShader);
//For the pixel shader node we also want to update the shader that uses it:
defaultTextures.Clear();
var shader = ShaderGenerator.GenerateSurfaceShader(pixelGraph.owner, pixelGraph.owner.name, false, out defaultTextures);
pixelGraph.owner.UpdateShaderSource(shader, defaultTextures);
return true;
}
}

24
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.MaterialGraph

{
m_BoundProperty = null;
RegeneratePreviewShaders();
}
}
public override void OnGUI()
{
base.OnGUI();
// find available properties
var allowedBindings = FindValidPropertyBindings().ToList();
var names = new List<string> { "none" };
names.AddRange(allowedBindings.Select(x => x.name));
var currentIndex = names.IndexOf(boundProperty == null ? "none" : boundProperty.name);
EditorGUI.BeginChangeCheck();
currentIndex = EditorGUILayout.Popup("Bound Property", currentIndex, names.ToArray());
if (EditorGUI.EndChangeCheck())
{
ShaderProperty selected = null;
if (currentIndex > 0)
selected = allowedBindings[currentIndex - 1];
BindProperty(selected, true);
}
}
}

1
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SlotValue.cs


default:
return "error";
}
return inputName;
}
public bool OnGUI()

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphInputsNode.cs


{
name = "SubGraphInputs";
title = "Inputs";
position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 4, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
// position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 4, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
base.OnCreate();
}

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphOutputsNode.cs


base.OnCreate();
name = "SubGraphOutputs";
title = "Outputs";
position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 8, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
//position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 8, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
}
public override void AddSlot()

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs


if (pixelMasterNode == null)
return null;
return pixelMasterNode.previewMaterial;
var material = pixelMasterNode.previewMaterial;
BaseMaterialNode.UpdateMaterialProperties(pixelMasterNode, material);
return material;
}
}
}

73
UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/MaterialProperties.cs


[SerializeField]
List<ShaderProperty> m_ShaderProperties = new List<ShaderProperty>();
public int previewState;
//static GUIContent[] previewOptions;
public event EventHandler OnChangePreviewState;
/*static MaterialProperties ()
{
previewOptions = Enum.GetNames (typeof (PreviewState)).Select (x => new GUIContent (x)).ToArray ();
}*/
public void OnEnable()
{
if (OnChangePreviewState != null)
OnChangePreviewState((PreviewState)previewState, null);
}
private bool m_Expanded;
//m_ScrollPos1 = BeginArea ("Options", m_ScrollPos1);
/*GUILayout.BeginHorizontal ();
GUILayout.Label ("Preview", EditorStyles.largeLabel);
EditorGUI.BeginChangeCheck ();
previewState = EditorGUILayout.CycleButton (previewState, previewOptions, EditorStyles.miniButton);
if (EditorGUI.EndChangeCheck () && OnChangePreviewState != null)
OnChangePreviewState ((PreviewState)previewState, null);
GUILayout.EndHorizontal ();*/
m_Expanded = MaterialGraphStyles.Header("Properties", m_Expanded);
//EndArea ();
m_ScrollPos = BeginArea("Exposed Properties", m_ScrollPos);
if (GUILayout.Button("Add Property"))
AddProperty();
if (!m_Expanded)
return;
var propsToRemove = new List<ShaderProperty>();
foreach (var property in m_ShaderProperties)

if (nameChanged || valuesChanged)
{
foreach (var node in nodes.Where(x => x is PropertyNode).Cast<PropertyNode>())
{
}
{
}
EndArea();
{
}
if (GUILayout.Button("Add"))
AddProperty();
}
private void AddProperty()

createdProperty.hideFlags = HideFlags.HideInHierarchy;
m_ShaderProperties.Add(createdProperty);
AssetDatabase.AddObjectToAsset(createdProperty, this);
}
static Vector2 BeginArea(string title, Vector2 scrollPos)
{
DoHeader(title);
scrollPos = GUILayout.BeginScrollView(scrollPos);
GUILayout.BeginVertical();
return scrollPos;
}
static void EndArea()
{
GUILayout.EndVertical();
GUILayout.EndScrollView();
}
static void DoHeader(string title)
{
GUILayout.BeginHorizontal(/*EditorStyles.inspectorBig*/);
GUILayout.BeginVertical();
GUILayout.Label(title, EditorStyles.largeLabel);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
public IEnumerable<ShaderProperty> GetPropertiesForPropertyType(PropertyType propertyType)

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs.meta


fileFormatVersion: 2
guid: d1e060684b84ebf4aa8b96b424def1ab
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

82
UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs


using System;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
[CustomEditor(typeof(BaseMaterialNode), true)]
class BaseMaterialNodeEditor : Editor
{
public override void OnInspectorGUI()
{
var node = target as BaseMaterialNode;
if (node == null)
return;
var slots = node.slots.ToArray();
EditorGUILayout.LabelField("Preview Mode: " + node.previewMode);
foreach (var slot in slots)
DoSlotUI(node, slot);
}
/*private bool DoDefaultInspectorUI ()
{
EditorGUIUtility.LookLikeInspector();
EditorGUI.BeginChangeCheck ();
serializedObject.Update();
bool materialSlotsFound = serializedObject.FindProperty("m_SlotDefaultValues") != null;
SerializedProperty property = serializedObject.GetIterator ();
bool expanded = true;
while (property.NextVisible (expanded))
{
expanded = false;
if (materialSlotsFound && (property.type == "Slot" || property.name == "m_SlotPropertiesIndexes" || property.name == "m_SlotProperties"))
continue;
EditorGUILayout.PropertyField (property, true);
}
serializedObject.ApplyModifiedProperties ();
EditorGUI.EndChangeCheck ();
return materialSlotsFound;
}
*/
private void DoSlotUI(BaseMaterialNode node, Slot slot)
{
GUILayout.BeginHorizontal(/*EditorStyles.inspectorBig*/);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Slot " + slot.title, EditorStyles.largeLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
DoMaterialSlotUIBody(node, slot);
}
private static void DoMaterialSlotUIBody(BaseMaterialNode node, Slot slot)
{
SlotValue value = node.GetSlotDefaultValue(slot.name);
if (value == null)
return;
var def = node.GetSlotDefaultValue(slot.name);
if (def != null && def.OnGUI())
{
node.UpdatePreviewProperties();
node.ForwardPreviewMaterialPropertyUpdate();
}
}
private static void RemoveSlot(BaseMaterialNode node, Slot slot)
{
node.RemoveSlot(slot);
}
}
}

86
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraphGUI.cs


using System;
using UnityEngine;
using System.Reflection;
using UnityEditor.Graphs;
namespace UnityEditor.MaterialGraph
{
abstract class BaseMaterialGraphGUI : EditorWindow
{
internal const int kDefaultNodeWidth = 50;
internal const int kDefaultNodeHeight = 80;
/* public override void OnGraphGUI()
{
m_Host.BeginWindows();
// Process all nodes in the graph
foreach (var n in graph.nodes)
{
var n2 = n;
bool isSelected = selection.Contains(n2);
n.position = GUILayout.Window(n.GetInstanceID(), n.position, delegate { NodeGUI(n2); }, n.title, Styles.GetNodeStyle(n.style, n.color, isSelected), GUILayout.Width(kDefaultNodeWidth), GUILayout.Height(kDefaultNodeHeight));
if (n2 is BaseMaterialNode)
((BaseMaterialNode)n2).isSelected = isSelected;
}
m_Host.EndWindows();
edgeGUI.DoEdges();
edgeGUI.DoDraggedEdge();
DragSelection(new Rect(-5000, -5000, 10000, 10000));
HandleMenuEvents();
Event evt = Event.current;
if (evt.type == EventType.MouseDown)
{
if (evt.button == 1)
{
DoAddNodeMenu(Event.current.mousePosition);
evt.Use();
}
}
}
*/
private class AddNodeCreationObject : object
{
public Vector2 m_Pos;
public readonly Type m_Type;
public AddNodeCreationObject(Type t, Vector2 p) { m_Type = t; m_Pos = p; }
};
private void AddNode(object obj)
{
var posObj = obj as AddNodeCreationObject;
if (posObj == null)
return;
var node = (BaseMaterialNode)CreateInstance(posObj.m_Type);
node.OnCreate();
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height);
// graph.AddNode(node);
}
public virtual bool CanAddToNodeMenu(Type type) { return true; }
protected void DoAddNodeMenu(Vector2 pos)
{
var gm = new GenericMenu();
foreach (Type type in Assembly.GetAssembly(typeof(BaseMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(BaseMaterialNode)) || type.IsSubclassOf(typeof(PropertyNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))
{
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, pos));
}
}
}
gm.ShowAsContext();
}
}
}

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraphGUI.cs.meta


fileFormatVersion: 2
guid: ac8e8db31ba040a479c767257822927a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

55
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraphGUI.cs


using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System.Linq;
namespace UnityEditor.MaterialGraph
{
class MaterialGraphGUI : BaseMaterialGraphGUI
{
enum SelectedOptions
{
properties,
options
}
private PixelGraph GetGraph() {return null; }
public MaterialGraph materialGraph;
private SelectedOptions m_SelectedGUI = SelectedOptions.properties;
private static void DrawSpacer()
{
var spacerLine = GUILayoutUtility.GetRect(GUIContent.none,
GUIStyle.none,
GUILayout.ExpandWidth(true),
GUILayout.Height(1));
var oldBgColor = GUI.backgroundColor;
if (EditorGUIUtility.isProSkin)
GUI.backgroundColor = oldBgColor * 0.7058f;
else
GUI.backgroundColor = Color.black;
//if (Event.current.type == EventType.Repaint)
// EditorGUIUtility.whiteTextureStyle.Draw(spacerLine, GUIContent.none, false, false, false, false);
GUI.backgroundColor = oldBgColor;
}
public void RenderOptions(Rect rect, MaterialGraph graph)
{
GUILayout.BeginArea(rect);
m_SelectedGUI = (SelectedOptions)EditorGUILayout.EnumPopup("Options?", m_SelectedGUI);
DrawSpacer();
if (m_SelectedGUI == SelectedOptions.properties)
graph.materialProperties.DoGUI(GetGraph().nodes);
else if (m_SelectedGUI == SelectedOptions.options)
graph.materialOptions.DoGUI();
GUILayout.EndArea();
}
}
}

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraphGUI.cs.meta


fileFormatVersion: 2
guid: b8ed425deb1eed44fb9b594561203b1a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

34
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraphGUI.cs


using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System.Reflection;
using UnityEditor.Graphs;
namespace UnityEditor.MaterialGraph
{
/*
class MaterialSubGraphGUI : BaseMaterialGraphGUI
{
public override void NodeGUI(Node n)
{
// Handle node selection
SelectNode(n);
// Make node minimize, etc. buttons
// Make default input slots
foreach (Slot s in n.inputSlots)
LayoutSlot(s, s.title, false, true, false, Styles.varPinIn);
// Make custom node UI
n.NodeUI(this);
// Make default output slots
foreach (Slot s in n.outputSlots)
LayoutSlot(s, s.title, true, false, true, Styles.varPinOut);
var subnode = n as SubGraphIOBaseNode;
if (subnode != null)
subnode.FooterUI(this);
DragNodes();
}
}*/
}

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraphGUI.cs.meta


fileFormatVersion: 2
guid: 996990fe8c018a74aa83cd7a1f90141e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

1001
UnityProject/Assets/UnityShaderEditor/Graphs/FresnelFromSGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

6
UnityProject/Assets/UnityShaderEditor/Graphs/FresnelFromSGraph.ShaderGraph.meta


fileFormatVersion: 2
guid: 22fdc7dad83e95848868d4503582a5a1
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

461
UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4b00854e54a3ed940813fa47dec62d38, type: 3}
m_Name: FresnelSubGraph
m_EditorClassIdentifier:
nodes:
- {fileID: 11400002}
- {fileID: 11400004}
- {fileID: 11400006}
- {fileID: 11400008}
- {fileID: 11400010}
- {fileID: 11400012}
- {fileID: 11400014}
- {fileID: 11400018}
edges:
- m_FromNode: {fileID: 11400006}
m_ToNode: {fileID: 11400010}
m_FromSlotName: ViewDirection
m_ToSlotName: Input1
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400010}
m_ToNode: {fileID: 11400014}
m_FromSlotName: Output
m_ToSlotName: Input1
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400014}
m_ToNode: {fileID: 11400012}
m_FromSlotName: Output
m_ToSlotName: Input1
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400008}
m_ToNode: {fileID: 11400010}
m_FromSlotName: Normal
m_ToSlotName: Input2
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400012}
m_ToNode: {fileID: 11400004}
m_FromSlotName: Output
m_ToSlotName: I00
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400018}
m_ToNode: {fileID: 11400014}
m_FromSlotName: Output
m_ToSlotName: Input2
color: {r: 1, g: 1, b: 1, a: 1}
m_InvalidEdges: []
m_InputsNode: {fileID: 11400002}
m_OutputsNode: {fileID: 11400004}
--- !u!114 &11400002
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: af738716871e4a345ac8edc429a3b665, type: 3}
m_Name: SubGraphInputs
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Color
m_Name: O00
m_DataTypeString:
- type: 1
m_Title: Power
m_Name: O01
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 48
y: 228
width: 50
height: 80
showEmptySlots: 1
m_SlotDefaultValues:
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
m_PrecisionNames:
- half
--- !u!114 &11400004
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12f42b98cfc8a394ca51a63cdd53d2cb, type: 3}
m_Name: SubGraphOutputs
m_EditorClassIdentifier:
m_Slots:
- type: 0
m_Title: I00
m_Name: I00
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 864
y: 384
width: 50
height: 80
showEmptySlots: 1
m_SlotDefaultValues:
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
m_PrecisionNames:
- half
--- !u!114 &11400006
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 30cf94a5e32cd254eb6eadf45e5cdfe3, type: 3}
m_Name: View Direction
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: View Direction
m_Name: ViewDirection
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 204
y: 324
width: 84
height: 105
showEmptySlots: 1
m_SlotDefaultValues:
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName: ViewDirection
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: ViewDirection
m_Node: {fileID: 11400006}
m_PrecisionNames:
- half
--- !u!114 &11400008
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b34601661908b3499c4c5e2ecd61f75, type: 3}
m_Name: Normal
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Normal
m_Name: Normal
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 204
y: 444
width: 74
height: 105
showEmptySlots: 1
m_SlotDefaultValues:
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName: Normal
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Normal
m_Node: {fileID: 11400008}
m_PrecisionNames:
- half
--- !u!114 &11400010
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 06ab35c1dfe05414787df3ea2772d507, type: 3}
m_Name: FresnelNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input 1
m_Name: Input1
m_DataTypeString:
- type: 0
m_Title: Input 2
m_Name: Input2
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 396
y: 384
width: 74
height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400010}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400010}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400010}
m_PrecisionNames:
- half
--- !u!114 &11400012
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 088fb5bde3ece0f4190136b3ab43f7c4, type: 3}
m_Name: MultiplyNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input 1
m_Name: Input1
m_DataTypeString:
- type: 0
m_Title: Input 2
m_Name: Input2
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 744
y: 300
width: 74
height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400012}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400012}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400012}
m_PrecisionNames:
- half
--- !u!114 &11400014
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b2957c4e08e061444a7444a1a03fb584, type: 3}
m_Name: PowerNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input 1
m_Name: Input1
m_DataTypeString:
- type: 0
m_Title: Input 2
m_Name: Input2
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 612
y: 384
width: 74
height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400014}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400014}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400014}
m_PrecisionNames:
- half
--- !u!114 &11400016
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c740b99e5a743e84d8030d697cc6d0a1, type: 3}
m_Name: SplatNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input
m_Name: Input
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 144
y: 600
width: 213
height: 137
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11400016}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input
m_Node: {fileID: 11400016}
m_PrecisionNames:
- half
m_SwizzleChannel: 0
--- !u!114 &11400018
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4b496ffd32c22d94bb525897d152da05, type: 3}
m_Name: AbsoluteNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input
m_Name: Input
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 420
y: 612
width: 74
height: 117
showEmptySlots: 1
m_SlotDefaultValues:
- slotName: Input
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input
m_Node: {fileID: 11400018}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400018}
m_PrecisionNames:
- half

4
UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph.meta


fileFormatVersion: 2
guid: a003744971255eb418c9d90ad6a41b21
NativeFormatImporter:
userData:
正在加载...
取消
保存