浏览代码

[Shader graph]Working on getting previews again.

/main
Tim Cooper 9 年前
当前提交
a2b27b3c
共有 9 个文件被更改,包括 61 次插入65 次删除
  1. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  3. 26
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Light/BaseLightFunction.cs
  4. 22
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  5. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function2Input.cs
  6. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  7. 37
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Slot.cs
  8. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs
  9. 21
      UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs

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


RemoveEdge(edge);
}
var newEdge = new Edge(new SlotReference(outputSlot.nodeGuid, outputSlot.name), new SlotReference(inputSlot.nodeGuid, inputSlot.name));
var newEdge = new Edge(new SlotReference(outputSlot.owner.guid, outputSlot.name), new SlotReference(inputSlot.owner.guid, inputSlot.name));
m_Edges.Add(newEdge);
Debug.Log("Connected edge: " + newEdge);

continue;
var typeName = GetTypeSerializableAsString(node.GetType());
var data = JsonUtility.ToJson(node);
var data = JsonUtility.ToJson(node, true);
if (string.IsNullOrEmpty(typeName) || string.IsNullOrEmpty(data))
continue;

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


return;
}
//TODO:DATA
/*
if (m_Node.hasPreview
&& m_Node.drawMode != DrawMode.Collapsed
&& m_PreviewArea.width > 0

GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}*/
}
base.Render(parentRect, canvas);
}

26
UnityProject/Assets/UnityShaderEditor/Editor/Source/Light/BaseLightFunction.cs


public override string GetSurfaceOutputStructureName() { return "SurfaceOutputStandard"; }
public override void DoSlotsForConfiguration(PixelShaderNode node)
{
node.AddSlot(new Slot(node.guid, kAlbedoSlotName, kAlbedoSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kNormalSlotName, kNormalSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kMetallicSlotName, kMetallicSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node.guid, kSmoothnessSlotName, kSmoothnessSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node.guid, kOcclusion, kOcclusion, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node.guid, kAlphaSlotName, kAlphaSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kAlbedoSlotName, kAlbedoSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kNormalSlotName, kNormalSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kMetallicSlotName, kMetallicSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kSmoothnessSlotName, kSmoothnessSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kOcclusion, kOcclusion, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kAlphaSlotName, kAlphaSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// clear out slot names that do not match the slots
// we support

public override string GetSurfaceOutputStructureName() { return "SurfaceOutputStandardSpecular"; }
public override void DoSlotsForConfiguration(PixelShaderNode node)
{
node.AddSlot(new Slot(node.guid, kAlbedoSlotName, kAlbedoSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kNormalSlotName, kNormalSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kSpecularSlotName, kSpecularSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kEmissionSlotName, kEmissionSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node.guid, kSmoothnessSlotName, kSmoothnessSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node.guid, kOcclusion, kOcclusion, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node.guid, kAlphaSlotName, kAlphaSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kAlbedoSlotName, kAlbedoSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kNormalSlotName, kNormalSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kSpecularSlotName, kSpecularSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kEmissionSlotName, kEmissionSlotName, Slot.SlotType.Input, SlotValueType.Vector3, Vector4.zero));
node.AddSlot(new Slot(node, kSmoothnessSlotName, kSmoothnessSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kOcclusion, kOcclusion, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
node.AddSlot(new Slot(node, kAlphaSlotName, kAlphaSlotName, Slot.SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// clear out slot names that do not match the slots
// we support

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


{
get
{
ValidateNode();
UpdatePreviewShader();
m_PreviewMaterial = new Material(m_PreviewShader) {hideFlags = HideFlags.HideInHierarchy};
m_PreviewMaterial.hideFlags = HideFlags.HideInHierarchy;
}

m_GUID = new Guid(m_GUIDSerialized);
else
m_GUID = Guid.NewGuid();
//patch up the slot owner reference
foreach (var slot in slots)
slot.owner = this;
}
public virtual float GetNodeUIHeight(float width)

if (!hasError)
{
//TODO:DATA
/* var valid = UpdatePreviewShader();
if (!valid)
hasError = true;*/
previewShaderNeedsUpdate = true;
public bool previewShaderNeedsUpdate { get; set; }
//True if error
protected virtual bool CalculateNodeHasError()
{

/// </summary>
public Texture RenderPreview(Rect targetSize)
{
if (hasError)
return null;
if (previewShaderNeedsUpdate)
{
UpdatePreviewShader();
previewShaderNeedsUpdate = false;
}
UpdatePreviewProperties();
if (s_Meshes[0] == null)

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


get { return true; }
}
public Function2Input(BaseMaterialGraph owner)
protected Function2Input(BaseMaterialGraph owner)
: base(owner)
{
AddSlot(GetInputSlot1());

protected virtual Slot GetInputSlot1()
{
return new Slot(guid, GetInputSlot1Name(), GetInputSlot1Name(), Slot.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new Slot(this, GetInputSlot1Name(), GetInputSlot1Name(), Slot.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new Slot(guid, GetInputSlot2Name(), GetInputSlot2Name(), Slot.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new Slot(this, GetInputSlot2Name(), GetInputSlot2Name(), Slot.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
return new Slot(guid, GetOutputSlotName(), GetOutputSlotName(), Slot.SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
return new Slot(this, GetOutputSlotName(), GetOutputSlotName(), Slot.SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlot1Name()

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


protected override bool UpdatePreviewShader()
{
// if (hasError)
if (hasError)
return false;
var shaderName = "Hidden/PreviewShader/" + name + "_" + guid;

37
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Slot.cs


namespace UnityEditor.MaterialGraph
{
[Serializable]
public class Slot : ISerializationCallbackReceiver
public class Slot
{
public enum SlotType
{

[SerializeField]
private Vector4 m_CurrentValue;
[SerializeField]
private string m_NodeGUIDSerialized;
private Guid m_NodeGUID;
private BaseMaterialNode m_Owner;
public Slot(Guid nodeGuid, string name, string displayName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue)
public Slot(BaseMaterialNode owner, string name, string displayName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue)
{
m_Name = name;
m_DisplayName = displayName;

m_CurrentValue = defaultValue;
m_NodeGUID = nodeGuid;
m_Owner = owner;
}
public bool isInputSlot

get { return m_DisplayName; }
}
public Guid nodeGuid
{
get { return m_NodeGUID; }
}
public Vector4 defaultValue
{
get { return m_DefaultValue; }

set { m_ConcreteValueType = value; }
}
public BaseMaterialNode owner
{
get { return m_Owner; }
set { m_Owner = value; }
}
public string GetInputName (BaseMaterialNode node)
{
return string.Format( "{0}_{1}", node.name, name);

break;
}
return EditorGUI.EndChangeCheck();
}
public virtual void OnBeforeSerialize()
{
m_NodeGUIDSerialized = m_NodeGUID.ToString();
}
public virtual void OnAfterDeserialize()
{
if (!string.IsNullOrEmpty(m_NodeGUIDSerialized))
m_NodeGUID = new Guid(m_NodeGUIDSerialized);
else
m_NodeGUID = Guid.NewGuid();
}
}
}

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


private void InternalValidate()
{
AddSlot(new Slot(guid, kOutputSlotName, kOutputSlotName, Slot.SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new Slot(this, kOutputSlotName, kOutputSlotName, Slot.SlotType.Output, SlotValueType.Vector4, Vector4.zero));
}
private const string kOutputSlotName = "Value";

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


private PixelShaderNode m_PixelMasterNode;
public PixelGraph(MaterialGraph owner) : base (owner)
{
m_PixelMasterNode = nodes.FirstOrDefault(x => x.GetType() == typeof(PixelShaderNode)) as PixelShaderNode;
if (m_PixelMasterNode == null)
{
m_PixelMasterNode = new PixelShaderNode(this);
AddNode(m_PixelMasterNode);
m_PixelMasterNode.position = new Rect(700, m_PixelMasterNode.position.y, m_PixelMasterNode.position.width, m_PixelMasterNode.position.height);
}
}
{}
// find existing node
if (m_PixelMasterNode == null)
m_PixelMasterNode = nodes.FirstOrDefault(x => x.GetType() == typeof(PixelShaderNode)) as PixelShaderNode;
// none exists, so create!
if (m_PixelMasterNode == null)
{
m_PixelMasterNode = new PixelShaderNode(this);
AddNode(m_PixelMasterNode);
m_PixelMasterNode.position = new Rect(700, m_PixelMasterNode.position.y, m_PixelMasterNode.position.width, m_PixelMasterNode.position.height);
}
return m_PixelMasterNode;
}
}

正在加载...
取消
保存