浏览代码

[shader graph]

*Fix exposition of vector properties
*Change validation (graph wholeistic)
*Add view layer callback for when nodes change internally (need repaint)
*Add missing pool classes
/main
Tim Cooper 9 年前
当前提交
abcc9002
共有 24 个文件被更改,包括 331 次插入174 次删除
  1. 47
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 39
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  3. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  4. 3
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs
  5. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/MaterialGraphEditor.cs
  6. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraph.cs
  7. 16
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs
  8. 123
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  9. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs
  10. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
  11. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  12. 78
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs
  13. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphNode.cs
  14. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SwizzleNode.cs
  15. 14
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  16. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs
  17. 11
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector2Node.cs
  18. 14
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector3Node.cs
  19. 14
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs
  20. 15
      UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs
  21. 20
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ListPool.cs
  22. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ListPool.cs.meta
  23. 49
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ObjectPool.cs
  24. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ObjectPool.cs.meta

47
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs


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

{
get { return isAwake && nodes.Any(x => x is IRequiresTime); }
}
protected abstract void RecacheActiveNodes();
public override void RemoveEdge(Edge e)
{
base.RemoveEdge(e);

return;
RecacheActiveNodes();
InvalidateAllNodes();
toNode.RegeneratePreviewShaders();
RevalidateGraph();
}
public override Edge Connect(Slot fromSlot, Slot toSlot)

if (fromNode == null || toNode == null)
return newEdge;
RecacheActiveNodes();
InvalidateAllNodes();
toNode.RegeneratePreviewShaders();
RevalidateGraph();
protected virtual void InvalidateAllNodes()
public virtual void RevalidateGraph()
foreach (var node in bmns)
{
node.ValidateNode();
}
}
public override void AddNode(Node node)

var bmn = node as BaseMaterialNode;
if (bmn != null && bmn.hasPreview)
bmn.UpdatePreviewMaterial();
RevalidateGraph();
}
public void GeneratePreviewShaders()
{
// 2 passes...
// 1 create the shaders
foreach (var node in nodes)
{
var bmn = node as BaseMaterialNode;
if (bmn != null && bmn.hasPreview)
bmn.UpdatePreviewMaterial();
}
// 2 set the properties
foreach (var node in nodes)
{
var pNode = node as BaseMaterialNode;
if (pNode != null && pNode.hasPreview)
pNode.UpdatePreviewProperties();
}
}
}
}

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


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

public sealed class DrawableMaterialNode : CanvasElement
{
private string m_Title;
private bool m_Error;
public DrawableMaterialNode(BaseMaterialNode node, float width, Type outputType, MaterialGraphDataSource data)
public DrawableMaterialNode(BaseMaterialNode node, float width, MaterialGraphDataSource data)
m_Title = node.name;
m_Error = node.hasError;
m_Node.onNeedsRepaint += Invalidate;
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);

{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), m_Error ? Color.red : selected ? selectedColor : backgroundColor);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), m_Node.hasError ? Color.red : selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, EditorStyles.toolbarTextField);
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField);
if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+"))
{
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full;

{
// 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();
}
}
RepaintDependentNodes(m_Node);
}
if (m_Node.hasPreview

base.Render(parentRect, canvas);
}
private static void RepaintDependentNodes(BaseMaterialNode bmn)
{
var dependentNodes = bmn.CollectDependentNodes();
foreach (var node in dependentNodes)
node.onNeedsRepaint();
}
foreach (var selected in selection.Where(x => x is DrawableMaterialNode).Cast<DrawableMaterialNode>())
var drawableMaterialNode = selection.Where(x => x is DrawableMaterialNode).Cast<DrawableMaterialNode>().FirstOrDefault();
if (drawableMaterialNode != null && drawableMaterialNode.m_Node.OnGUI())
selected.m_Node.OnGUI();
break;
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(drawableMaterialNode.m_Node);
}
}
}

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


{
// add the nodes
var bmn = node as BaseMaterialNode;
m_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, this));
}
// Add the edges now

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


if (selection != m_MaterialGraph)
{
m_MaterialGraph = selection;
m_MaterialGraph.currentGraph.GeneratePreviewShaders();
}
}

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))))
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(BaseMaterialNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))

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


public override bool HasPreviewGUI()
{
return true;
return false;
}
private void Init()

6
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialSubGraph.cs


public SubGraphInputsNode inputsNode { get { return m_InputsNode; } }
public SubGraphOutputsNode outputsNode { get { return m_OutputsNode; } }
protected override void RecacheActiveNodes()
{
}
public new void OnEnable()
{
base.OnEnable();

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


[Title("Math/Add Node")]
public class AddNode : Function2Input, IGeneratesFunction
{
[SerializeField] private float m_DefaultValue;
public override void OnCreate()
{
name = "AddNode";

public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
EditorGUI.BeginChangeCheck();
m_DefaultValue = EditorGUI.FloatField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), m_DefaultValue);
if (EditorGUI.EndChangeCheck())
{
RegeneratePreviewShaders();
return true;
}
return false;
}
}
}

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.Graphs;
using UnityEditorInternal;
using UnityEngine;

public abstract class BaseMaterialNode : Node, IGenerateProperties
{
#region Fields
private const int kPreviewWidth = 64;
private const int kPreviewHeight = 64;

[SerializeField]
private DrawMode m_DrawMode = DrawMode.Full;
public delegate void NeedsRepaint();
public NeedsRepaint onNeedsRepaint;
public void ExecuteRepaint()
{
if (onNeedsRepaint != null)
onNeedsRepaint();
}
private readonly Dictionary<string, SlotValueType> m_SlotValueTypes = new Dictionary<string, SlotValueType>();
private readonly Dictionary<string, ConcreteSlotValueType> m_ConcreteInputSlotValueTypes = new Dictionary<string, ConcreteSlotValueType>();
private readonly Dictionary<string, ConcreteSlotValueType> m_ConcreteOutputSlotValueTypes = new Dictionary<string, ConcreteSlotValueType>();

{
get
{
BuildValidateNode();
ValidateNode();
if (m_Material == null)
{
m_Material = new Material(defaultPreviewShader) {hideFlags = HideFlags.DontSave};

}
[NonSerialized]
private bool m_NodeInValidState;
public bool nodeInValidState
private bool m_NodeNeedsValidation= true;
public bool nodeNeedsValidation
get { return m_NodeInValidState; }
get { return m_NodeNeedsValidation; }
m_NodeInValidState = false;
m_NodeNeedsValidation = true;
}
[NonSerialized]

get
{
if (!nodeInValidState)
BuildValidateNode();
if (nodeNeedsValidation)
ValidateNode();
protected set
{
if (m_HasError != value)
{
m_HasError = value;
ExecuteRepaint();
}
}
}
public Dictionary<string, ConcreteSlotValueType> concreteInputSlotValueTypes

if (!nodeInValidState)
BuildValidateNode();
if (nodeNeedsValidation)
ValidateNode();
return m_ConcreteInputSlotValueTypes;
}
}

get
{
if (!nodeInValidState)
BuildValidateNode();
if (nodeNeedsValidation)
ValidateNode();
return m_ConcreteOutputSlotValueTypes;
}
}

#endregion
#region Previews
public virtual bool UpdatePreviewMaterial()
protected virtual bool UpdatePreviewMaterial()
InternalUpdatePreviewShader(resultShader);
return true;
return InternalUpdatePreviewShader(resultShader);
protected void InternalUpdatePreviewShader(string resultShader)
protected bool InternalUpdatePreviewShader(string resultShader)
{
MaterialWindow.DebugMaterialGraph("RecreateShaderAndMaterial : " + name + "_" + GetInstanceID() + "\n" + resultShader);
if (previewMaterial.shader != defaultPreviewShader)

var hasErrorsCall = typeof(ShaderUtil).GetMethod("GetShaderErrorCount", BindingFlags.Static | BindingFlags.NonPublic);
var result = hasErrorsCall.Invoke(null, new object[] {previewMaterial.shader});
return (int)result == 0;
}
private static Mesh[] s_Meshes = { null, null, null, null };

}
ListPool<Slot>.Release(validSlots);
}
// this function looks at all the nodes that have a
// dependency on this node. They will then have their
// preview regenerated.
public void RegeneratePreviewShaders()
{
var dependentNodesWithPreview = CollectDependentNodes().Where(x => x.hasPreview);
foreach (var dependentNode in dependentNodesWithPreview)
dependentNode.UpdatePreviewMaterial();
}
public static void UpdateMaterialProperties(BaseMaterialNode target, Material material)

}
}
public struct OutputSlotVariable
{
public string name;
public ConcreteSlotValueType slotType;
}
public virtual string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
if (s.isInputSlot) Debug.LogError("Attempting to use input slot (" + s + ") for output!");

return ConcreteSlotValueType.Error;
}
public void BuildValidateNode()
private static int fcuckingtest = 0;
public void ValidateNode()
if (nodeInValidState)
fcuckingtest++;
if (fcuckingtest == 100)
{
Debug.Log("stack");
}
if (!nodeNeedsValidation)
bool isInError = false;
// all children nodes needs to be updated first
// so do that here

{
var outputSlot = edge.fromSlot;
var outputNode = (BaseMaterialNode) outputSlot.node;
outputNode.BuildValidateNode();
outputNode.ValidateNode();
if (outputNode.hasError)
isInError |= true;
}
}

m_ConcreteOutputSlotValueTypes.Add(outputSlot.name, ToConcreteType(m_SlotValueTypes[outputSlot.name]));
}
isInError |= inputError;
isInError |= m_ConcreteOutputSlotValueTypes.Values.Any(x => x == ConcreteSlotValueType.Error);
isInError |= CalculateNodeHasError();
m_NodeNeedsValidation = false;
hasError = isInError;
m_HasError = inputError || m_ConcreteOutputSlotValueTypes.Values.Any(x => x == ConcreteSlotValueType.Error);
m_NodeInValidState = true;
if (!hasError)
{
bool valid = UpdatePreviewMaterial();
if (!valid)
hasError = true;
}
}
//True if error
protected virtual bool CalculateNodeHasError()
{
return false;
}
public static string ConvertConcreteSlotValueTypeToString(ConcreteSlotValueType slotValue)

}
}
public virtual void OnGUI()
public virtual bool OnGUI()
bool modified = false;
DoSlotUI(this, slot);
modified |= DoSlotUI(this, slot);
return modified;
private static void DoSlotUI(BaseMaterialNode node, Slot slot)
private static bool DoSlotUI(BaseMaterialNode node, Slot slot)
{
GUILayout.BeginHorizontal(/*EditorStyles.inspectorBig*/);
GUILayout.BeginVertical();

GUILayout.EndVertical();
GUILayout.EndHorizontal();
DoMaterialSlotUIBody(node, slot);
return DoMaterialSlotUIBody(node, slot);
private static void DoMaterialSlotUIBody(BaseMaterialNode node, Slot slot)
private static bool DoMaterialSlotUIBody(BaseMaterialNode node, Slot slot)
return;
return false;
def.OnGUI();
return def.OnGUI();
}
}

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


m_Operation = (Operation) EditorGUI.EnumPopup(new Rect(drawArea.x, drawArea.y + EditorGUIUtility.singleLineHeight, drawArea.width, EditorGUIUtility.singleLineHeight), m_Operation);
if (EditorGUI.EndChangeCheck())
{
RegeneratePreviewShaders();
pixelGraph.RevalidateGraph();
return true;
}
return false;

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


public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();
return propertyName;
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("float4 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

return;
visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);
}

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Color,
m_Color = m_Color
};

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


m_LightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString();
if (EditorGUI.EndChangeCheck())
{
RegeneratePreviewShaders();
pixelGraph.RevalidateGraph();
return true;
}
return false;

get { return true; }
}
public override bool UpdatePreviewMaterial()
protected override bool UpdatePreviewMaterial()
{
if (hasError)
return false;

var resultShader = ShaderGenerator.GenerateSurfaceShader(pixelGraph.owner, shaderName, true, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;
InternalUpdatePreviewShader(resultShader);
hasError = !InternalUpdatePreviewShader(resultShader);
return true;
}
}

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


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

{
//[SerializeField]
//private string m_Name;
[SerializeField]
private string m_PropertyName;
[SerializeField]
private string m_Description;

public string description
{
get { return m_Description; }
get
{
if (string.IsNullOrEmpty(m_Description))
return propertyName;
return m_Description;
}
set { m_Description = value; }
public virtual string GetPropertyName()
public virtual string propertyName
// var validExposedName = !string.IsNullOrEmpty(m_Name);
//if (!validExposedName)
return string.Format("{0}_{1}_Uniform", name, Math.Abs(GetInstanceID()));
get
{
if (!exposed || string.IsNullOrEmpty(m_PropertyName))
return string.Format("{0}_{1}_Uniform", name, Math.Abs(GetInstanceID()));
// return m_Name + "_Uniform";
return m_PropertyName + "_Uniform";
}
set { m_PropertyName = value; }
}
public abstract PropertyType propertyType { get; }

public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();
return propertyName;
}
public override float GetNodeUIHeight(float width)

properties.Add(GetPreviewProperty());
}
public override void OnGUI()
private static int fcuckingtest = 0;
protected override bool CalculateNodeHasError()
fcuckingtest++;
if (fcuckingtest == 100)
{
Debug.Log("stack");
}
if (!exposed)
return false;
var allNodes = pixelGraph.nodes;
foreach (var n in allNodes.OfType<PropertyNode>())
{
if (n == this)
continue;;
if (n.propertyName == propertyName)
{
return true;
}
}
return false;
}
public override bool OnGUI()
{
EditorGUI.BeginChangeCheck();
base.OnGUI();
if (m_Exposed)
m_PropertyName = EditorGUILayout.DelayedTextField("Property Name", m_PropertyName);
var modified = EditorGUI.EndChangeCheck();
if (modified)
{
var bmg = (graph as BaseMaterialGraph);
if (bmg == null)
return false;
bmg.RevalidateGraph();
}
if (m_Exposed)
m_Description = EditorGUILayout.TextField("Description", m_Description);
modified |= base.OnGUI();
return modified;
}
}
}

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


{
RefreshSlots(SlotType.InputSlot, inputSlots.ToList(), sender.inputsNode.slots, (s) => true);
RefreshSlots(SlotType.OutputSlot, outputSlots.ToList(), sender.outputsNode.slots, sender.OutputInternallyWired);
RegeneratePreviewShaders();
pixelGraph.RevalidateGraph();
}
private void RefreshSlots(SlotType type, IEnumerable<Slot> current, IEnumerable<Slot> updated, Func<string, bool> slotFilter)

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


m_SwizzleChannel[n] = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), channelNames[n] + "=", m_SwizzleChannel[n], values);
if (EditorGUI.EndChangeCheck())
{
RegeneratePreviewShaders();
pixelGraph.RevalidateGraph();
return true;
}
return false;

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


if (uvSlot == null)
return;
var uvName = "IN.meshUV0";
var uvName = "IN.meshUV0.xy";
if ()
string body = "tex2D (" + GetPropertyName() + ", " + uvName + ".xy)";
string body = "tex2D (" + propertyName + ", " + uvName + ".xy)";
if (m_TextureType == TextureType.Bump)
body = precision + "4(UnpackNormal(" + body + "), 0)";
visitor.AddShaderChunk("float4 " + GetOutputVariableNameForNode() + " = " + body + ";", true);

// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(new TexturePropertyChunk(GetPropertyName(), GetPropertyName(), m_DefaultTexture, m_TextureType, false, exposed));
visitor.AddShaderProperty(new TexturePropertyChunk(propertyName, description, m_DefaultTexture, m_TextureType, false, exposed));
visitor.AddShaderChunk("sampler2D " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
}
public override float GetNodeUIHeight(float width)

if (typeChanged)
{
RegeneratePreviewShaders();
pixelGraph.RevalidateGraph();
return true;
}

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = m_DefaultTexture
};

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs


public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(GetPropertyName(), description, m_Value, false));
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, false));
visitor.AddShaderChunk("float " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("float " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

visitor.AddShaderChunk(precision + " " + GetPropertyName() + " = " + m_Value + ";", true);
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_Value + ";", true);
}
public override bool NodeUI(Rect drawArea)

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Float,
m_Float = m_Value
};

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


}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{}
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
}
visitor.AddShaderChunk("float2 " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("float2 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

visitor.AddShaderChunk(precision + "2 " + GetPropertyName() + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
}
public override bool NodeUI(Rect drawArea)

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};

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


{
get { return PropertyType.Vector3; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
}
visitor.AddShaderChunk("float3 " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("float3 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

visitor.AddShaderChunk(precision + "3 " + GetPropertyName() + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true);
visitor.AddShaderChunk(precision + "3 " + propertyName + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true);
}
public override bool NodeUI(Rect drawArea)

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Vector3,
m_Vector4 = m_Value
};

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


{
get { return PropertyType.Vector4; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false));
}
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
visitor.AddShaderChunk("float4 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
public override bool NodeUI(Rect drawArea)

{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};

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


}
}
private List<BaseMaterialNode> m_ActiveNodes;
private List<BaseMaterialNode> m_ActiveNodes = new List<BaseMaterialNode>();
if (m_ActiveNodes == null)
{
m_ActiveNodes = new List<BaseMaterialNode>();
pixelMasterNode.CollectChildNodesByExecutionOrder(m_ActiveNodes);
}
m_ActiveNodes.Clear();
pixelMasterNode.CollectChildNodesByExecutionOrder(m_ActiveNodes);
return m_ActiveNodes;
}
}

}
pixelMasterNode.GenerateNodeCode(shaderBody, genMode);
}
protected override void RecacheActiveNodes()
{
m_ActiveNodes.Clear();
pixelMasterNode.CollectChildNodesByExecutionOrder(m_ActiveNodes);
}
public Material GetMaterial()

20
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ListPool.cs


using System.Collections.Generic;
namespace UnityEditor.MaterialGraph
{
internal static class ListPool<T>
{
// Object pool to avoid allocations.
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(null, l => l.Clear());
public static List<T> Get()
{
return s_ListPool.Get();
}
public static void Release(List<T> toRelease)
{
s_ListPool.Release(toRelease);
}
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ListPool.cs.meta


fileFormatVersion: 2
guid: 10e666e06d86d864d9d607de2f213fdc
timeCreated: 1453393151
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

49
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ObjectPool.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace UnityEditor.MaterialGraph
{
internal class ObjectPool<T> where T : new()
{
private readonly Stack<T> m_Stack = new Stack<T>();
private readonly UnityAction<T> m_ActionOnGet;
private readonly UnityAction<T> m_ActionOnRelease;
public int countAll { get; private set; }
public int countActive { get { return countAll - countInactive; } }
public int countInactive { get { return m_Stack.Count; } }
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
{
m_ActionOnGet = actionOnGet;
m_ActionOnRelease = actionOnRelease;
}
public T Get()
{
T element;
if (m_Stack.Count == 0)
{
element = new T();
countAll++;
}
else
{
element = m_Stack.Pop();
}
if (m_ActionOnGet != null)
m_ActionOnGet(element);
return element;
}
public void Release(T element)
{
if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
if (m_ActionOnRelease != null)
m_ActionOnRelease(element);
m_Stack.Push(element);
}
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ObjectPool.cs.meta


fileFormatVersion: 2
guid: a47156f8a364c344d9a2cc4bd904afc8
timeCreated: 1453393151
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存