浏览代码

[shader graph]Reenable node UI. Not amazingly laid out yet, but it will get there.

/main
Tim Cooper 9 年前
当前提交
4b137787
共有 17 个文件被更改,包括 177 次插入74 次删除
  1. 38
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  2. 17
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  3. 24
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs
  4. 10
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  5. 16
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs
  6. 16
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
  7. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorizeNode.cs
  8. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/CombineNode.cs
  9. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/FunctionMultiInput.cs
  10. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/KaleidoscopeNode.cs
  11. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MandelbrotNode.cs
  12. 11
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PerlinNode.cs
  13. 14
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  14. 20
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs
  15. 23
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SwizzleNode.cs
  16. 31
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  17. 13
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs

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


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

public BaseMaterialNode m_Node;
private Rect m_PreviewArea;
private Rect m_NodeUIRect;
public DrawableMaterialNode(BaseMaterialNode node, float width, Type outputType, MaterialGraphDataSource data)
: base(node.position.min, width)

m_OutputType = outputType;
m_Data = data;
Vector3 pos = new Vector3(5.0f, 10.0f, 0.0f);
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);
Vector3 pos = vector3;
// input slots
foreach (var slot in node.inputSlots)

}
var inputYMax = pos.y;
pos.y = yStart;
pos.y += 22;
pos.y = Mathf.Max(pos.y, inputYMax) + 22.0f;
var nodeUIHeight = m_Node.GetNodeUIHeight(width);
m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight);
pos.y += nodeUIHeight;
if (node.hasPreview)
{

scale = new Vector3(pos.x, pos.y, 0.0f);
scale = new Vector3(pos.x, pos.y + 22.0f, 0.0f);
AddManipulator(new IMGUIContainer());
}
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)

public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
if (m_Node.NodeUI(m_NodeUIRect))
{
// if we were changed, we need to redraw all the
// dependent nodes.
var dependentNodes = m_Node.CollectDependentNodes();
foreach (var node in dependentNodes)
{
foreach (var drawNode in m_Data.lastGeneratedNodes)
{
if (drawNode.m_Node == node)
drawNode.Invalidate();
}
}
}
if (m_Node.hasPreview)
{
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);

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


{
public class MaterialGraphDataSource : ICanvasDataSource
{
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>();
public ICollection<DrawableMaterialNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
var drawableNodes = new List<DrawableMaterialNode>();
m_DrawableNodes.Clear();
Debug.Log("trying to convert");
var pixelGraph = graph.currentGraph;
foreach (var node in pixelGraph.nodes)

drawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this));
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this));
foreach (var drawableMaterialNode in drawableNodes)
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.outputSlots)

foreach (var edge in slot.edges)
{
var targetNode = drawableNodes.FirstOrDefault(x => x.m_Node == edge.toSlot.node);
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(drawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
Debug.LogFormat("REturning {0} nodes", toReturn.Count);

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


namespace UnityEditor.MaterialGraph
{
[Title("Math/Add Node")]
class AddNode : FunctionMultiInput, IGeneratesFunction
public class AddNode : FunctionMultiInput, IGeneratesFunction
[SerializeField]
private float m_DefaultValue = 0.0f;
[SerializeField] private float m_DefaultValue = 0.0f;
public override void Init()
{

protected override string GetFunctionName() {return "unity_add_" + precision; }
protected override string GetFunctionName()
{
return "unity_add_" + precision;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override Vector4 GetNewSlotDefaultValue()
public override float GetNodeUIHeight(float width)
return Vector4.zero;
return EditorGUIUtility.singleLineHeight;
public override void NodeUI()
public override bool NodeUI(Rect drawArea)
base.NodeUI();
base.NodeUI(drawArea);
m_DefaultValue = EditorGUILayout.FloatField("", m_DefaultValue, GUILayout.Width(64));
m_DefaultValue = EditorGUI.FloatField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), m_DefaultValue);
{
return true;
}
return false;
}
}
}

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


}
}
public virtual void NodeUI()
public virtual float GetNodeUIHeight(float width)
if (hasPreview)
OnPreviewGUI();
return 0;
public virtual bool NodeUI(Rect drawArea)
{
return false;
}
protected virtual void OnPreviewGUI()
{
if (!ShaderUtil.hardwareSupportsRectRenderTexture)

16
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs


visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override float GetNodeUIHeight(float width)
{
return 2.0f * EditorGUIUtility.singleLineHeight;
}
public override void NodeUI()
public override bool NodeUI(Rect drawArea)
base.NodeUI();
base.NodeUI(drawArea);
m_Blend = GUILayout.HorizontalSlider(m_Blend, 0f, 1f, GUILayout.Width(64));
m_Operation = (Operation)EditorGUILayout.EnumPopup(m_Operation);
m_Blend = GUI.HorizontalSlider(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), m_Blend, 0f, 1f);
m_Operation = (Operation) EditorGUI.EnumPopup(new Rect(drawArea.x, drawArea.y + EditorGUIUtility.singleLineHeight, drawArea.width, EditorGUIUtility.singleLineHeight), m_Operation);
{
return true;
}
return false;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

16
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs


visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);
}
public override void NodeUI()
public override float GetNodeUIHeight(float width)
base.NodeUI();
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
m_Color = EditorGUILayout.ColorField(m_Color);
m_Color = EditorGUI.ColorField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), m_Color);
{
}
return true;
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorizeNode.cs


return value;
}
public override void NodeUI()
/*public override void NodeUI()
{
base.NodeUI();

m_Contrast = Slider("Contrast", m_Contrast, 0.3f, 4f);
if (EditorGUI.EndChangeCheck())
RegeneratePreviewShaders();
}
}*/
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/CombineNode.cs


visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override void NodeUI()
/* public override void NodeUI()
{
base.NodeUI();

RegeneratePreviewShaders();
}
}*/
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{

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


namespace UnityEditor.MaterialGraph
{
abstract class FunctionMultiInput : BaseMaterialNode, IGeneratesBodyCode
public abstract class FunctionMultiInput : BaseMaterialNode, IGeneratesBodyCode
{
private const string kOutputSlotName = "Output";
private const string kBaseInputSlotName = "Input";

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/KaleidoscopeNode.cs


return value;
}
public override void NodeUI()
/*public override void NodeUI()
{
base.NodeUI();

RegeneratePreviewShaders();
}
}*/
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MandelbrotNode.cs


return value;
}
public override void NodeUI()
/*public override void NodeUI()
{
base.NodeUI();

RegeneratePreviewShaders();
}
}*/
}
}

11
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PerlinNode.cs


GUILayout.EndHorizontal();
return value;
}
/*
public override float GetNodeUIHeight()
{
return EditorGUIUtility.singleLineHeight;
}
public override void NodeUI(GraphGUI host)
public override bool NodeUI(Rect drawArea)
base.NodeUI();
base.NodeUI(drawArea);
EditorGUI.BeginChangeCheck();
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 8);

RegeneratePreviewShaders();
}
}*/
}
}

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


return GetOutputVariableNameForNode();
}
public override void NodeUI(GraphGUI host)
public override float GetNodeUIHeight(float width)
base.NodeUI();
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
var lightFunctions = GetLightFunctions();
var lightFunction = GetLightFunction();

EditorGUI.BeginChangeCheck();
lightFuncIndex = EditorGUILayout.Popup(lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName()).ToArray(), EditorStyles.popup);
lightFuncIndex = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName()).ToArray(), EditorStyles.popup);
{
return true;
}
return false;
}
public override bool hasPreview

20
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs


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

}
}
public override void NodeUI(GraphGUI host)
public override float GetNodeUIHeight(float width)
base.NodeUI();
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
m_SwizzleChannel = EditorGUILayout.Popup("Channel", m_SwizzleChannel, values);
m_SwizzleChannel = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Channel", m_SwizzleChannel, values);
{
return true;
}
return false;
}
protected override string GetFunctionName()

23
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SwizzleNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor.Graphs;
using UnityEngine;

name = "SwizzleNode";
}
public override void NodeUI(GraphGUI host)
public override float GetNodeUIHeight(float width)
base.NodeUI();
string[] channelNames = { "X", "Y", "Z", "W" };
string[] values = { "0", "1", "Input1.x", "Input1.y", "Input1.z", "Input1.w", "Input2.x", "Input2.y", "Input2.z", "Input2.w" };
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
string[] channelNames = {"X", "Y", "Z", "W"};
string[] values = {"0", "1", "Input1.x", "Input1.y", "Input1.z", "Input1.w", "Input2.x", "Input2.y", "Input2.z", "Input2.w"};
m_SwizzleChannel[n] = EditorGUILayout.Popup(channelNames[n] + "=", m_SwizzleChannel[n], values);
m_SwizzleChannel[n] = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), channelNames[n] + "=", m_SwizzleChannel[n], values);
{
return true;
}
return false;
}
protected override string GetFunctionName()

31
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs


visitor.AddShaderChunk("sampler2D " + GetPropertyName() + ";", true);
}
// UI Shizz
public override void NodeUI(GraphGUI host)
public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight + width - 20;
}
public override bool NodeUI(Rect drawArea)
base.NodeUI();
base.NodeUI(drawArea);
m_DefaultTexture = EditorGUILayout.ObjectField(GUIContent.none, m_DefaultTexture, typeof(Texture2D), false) as Texture2D;
m_TextureType = (TextureType)EditorGUILayout.Popup((int)m_TextureType, m_TextureTypeNames.ToArray(), EditorStyles.popup);
if (EditorGUI.EndChangeCheck())
m_DefaultTexture = EditorGUI.ObjectField(new Rect(drawArea.x, drawArea.y, drawArea.width, drawArea.width), GUIContent.none, m_DefaultTexture, typeof (Texture2D), false) as Texture2D;
var texureChanged = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
m_TextureType = (TextureType) EditorGUI.Popup(new Rect(drawArea.x, drawArea.y + drawArea.width, drawArea.width, EditorGUIUtility.singleLineHeight), (int) m_TextureType, m_TextureTypeNames.ToArray(), EditorStyles.popup);
var typeChanged = EditorGUI.EndChangeCheck();
if (typeChanged)
{
RegeneratePreviewShaders();
return true;
}
if (texureChanged)
{
var boundProp = boundProperty as TextureProperty;
if (boundProp != null)

}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
return true;
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)

m_Texture = m_DefaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
}
}

13
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs


visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
public override void NodeUI()
public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
base.NodeUI();
base.NodeUI(drawArea);
m_Value = EditorGUILayout.Vector4Field("Value", m_Value, GUILayout.Width(170));
m_Value = EditorGUI.Vector4Field(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value);
if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as VectorProperty;

}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
return true;
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)

正在加载...
取消
保存