浏览代码

Preliminary vertex shader support

/main
Peter Bay Bastian 7 年前
当前提交
ed185a44
共有 22 个文件被更改,包括 358 次插入232 次删除
  1. 34
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
  2. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs
  3. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphAnchorPresenter.cs
  5. 110
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  6. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  7. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  8. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  9. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph
  10. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Cracks.ShaderGraph.meta
  11. 79
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSlot.cs
  12. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs
  13. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/MetallicMasterNode.cs
  14. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs
  15. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs.meta
  16. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/PositionNode.cs
  17. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ShaderStage.cs
  18. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ShaderStage.cs.meta
  19. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexInterpolatorNode.cs
  20. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexInterpolatorNode.cs.meta
  21. 64
      MaterialGraphProject/Assets/NewNodes/Kill/VertexPositionNode.cs
  22. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/PositionNode.cs.meta

34
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs


if (includeSelf == IncludeSelf.Include)
nodeList.Add(node);
}
public static ShaderStage FindEffectiveShaderStage(INode initialNode, bool goingBackwards)
{
var shaderStage = ShaderStage.Dynamic;
var nodeStack = new Stack<INode>();
nodeStack.Push(initialNode);
while (nodeStack.Any() && shaderStage == ShaderStage.Dynamic)
{
var node = nodeStack.Pop();
foreach (var slot in goingBackwards ? node.GetInputSlots<MaterialSlot>() : node.GetOutputSlots<MaterialSlot>())
{
if (shaderStage != ShaderStage.Dynamic)
break;
if (slot.shaderStage == ShaderStage.Dynamic)
{
foreach (var edge in node.owner.GetEdges(slot.slotReference))
{
var connectedNode = node.owner.GetNodeFromGuid(goingBackwards ? edge.outputSlot.nodeGuid : edge.inputSlot.nodeGuid);
var connectedSlot = goingBackwards ? connectedNode.FindOutputSlot<MaterialSlot>(edge.outputSlot.slotId) : connectedNode.FindInputSlot<MaterialSlot>(edge.inputSlot.slotId);
if (connectedSlot.shaderStage == ShaderStage.Dynamic)
nodeStack.Push(connectedNode);
else
{
shaderStage = connectedSlot.shaderStage;
break;
}
}
}
else
shaderStage = slot.shaderStage;
}
}
return shaderStage;
}
}
}

18
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs


{
public class StandardNodeEditorView : AbstractNodeEditorView
{
VisualElement m_EditorTitle;
NodeEditorHeaderView m_HeaderView;
VisualElement m_SlotsContainer;
VisualElement m_DefaultSlotValuesSection;

{
AddToClassList("nodeEditor");
var headerContainer = new VisualElement();
headerContainer.AddToClassList("header");
{
m_EditorTitle = new VisualElement();
m_EditorTitle.AddToClassList("title");
headerContainer.Add(m_EditorTitle);
var headerType = new VisualElement { text = "(node)" };
headerType.AddToClassList("type");
headerContainer.Add(headerType);
}
Add(headerContainer);
m_HeaderView = new NodeEditorHeaderView() { type = "node" };
Add(m_HeaderView);
m_DefaultSlotValuesSection = new VisualElement();
m_DefaultSlotValuesSection.AddToClassList("section");

if (presenter == null)
return;
m_EditorTitle.text = presenter.node.name;
m_HeaderView.title = presenter.node.name;
m_SlotsContainer.Clear();
foreach (var slotEditorPresenter in presenter.slotEditorPresenters)

22
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs


{
public class SurfaceMasterNodeEditorView : AbstractNodeEditorView
{
VisualElement m_EditorTitle;
NodeEditorHeaderView m_HeaderView;
get { return (SurfaceMasterNodeEditorPresenter) base.presenter; }
get { return (SurfaceMasterNodeEditorPresenter)base.presenter; }
}
public SurfaceMasterNodeEditorView()

var headerContainer = new VisualElement();
headerContainer.AddToClassList("header");
{
m_EditorTitle = new VisualElement() {text = ""};
m_EditorTitle.AddToClassList("title");
headerContainer.Add(m_EditorTitle);
var headerType = new VisualElement { text = "(node)" };
headerType.AddToClassList("type");
headerContainer.Add(headerType);
}
Add(headerContainer);
m_HeaderView = new NodeEditorHeaderView { type = "node" };
Add(m_HeaderView);
var optionsSection = new VisualElement() {name = "surfaceOptions"};
var optionsSection = new VisualElement() { name = "surfaceOptions" };
optionsSection.AddToClassList("section");
{
optionsSection.Add(new IMGUIContainer(OnGUIHandler));

if (presenter == null)
return;
m_EditorTitle.text = presenter.node.name;
m_HeaderView.title = presenter.node.name;
}
}
}

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


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

m_Direction = slot.isInputSlot ? Direction.Input : Direction.Output;
}
private Direction m_Direction;
Direction m_Direction;
}
ShaderStage m_ShaderStage;
public ShaderStage shaderStage
{
get { return m_ShaderStage; }
set { m_ShaderStage = value; }
}
}
}

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


{
Dictionary<Guid, MaterialNodePresenter> m_TimeDependentPresenters = new Dictionary<Guid, MaterialNodePresenter>();
public bool hasTimeDependentNodes { get { return m_TimeDependentPresenters.Any(); }}
public bool hasTimeDependentNodes
{
get { return m_TimeDependentPresenters.Any(); }
}
protected GraphTypeMapper typeMapper { get; set; }

typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
// typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
//typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
//typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);

typeMapper[typeof(AACheckerboardNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter*/
typeMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
// typeMapper[typeof(RemapMasterNode)] = typeof(RemapMasterNodePresenter);
// typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);

//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);

return allChildren.OfType<NodeAnchorPresenter>()
.Where(nap =>
nap.IsConnectable()
&& nap.orientation == startAnchor.orientation
&& nap.direction != startAnchor.direction
&& nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null && startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot
&& ((GraphAnchorPresenter)startAnchor).slot.owner != ((GraphAnchorPresenter)nap).slot.owner
&& ((MaterialSlot)((GraphAnchorPresenter)startAnchor).slot).IsCompatibleWithInputSlotType(((MaterialSlot)((GraphAnchorPresenter)nap).slot).valueType))
.ToList();
var compatibleAnchors = new List<NodeAnchorPresenter>();
var startAnchorPresenter = startAnchor as GraphAnchorPresenter;
if (startAnchorPresenter == null)
return compatibleAnchors;
var startSlot = startAnchorPresenter.slot as MaterialSlot;
if (startSlot == null)
return compatibleAnchors;
var goingBackwards = startSlot.isOutputSlot;
var startStage = startSlot.shaderStage;
if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);
foreach (var candidateAnchorPresenter in allChildren.OfType<GraphAnchorPresenter>())
{
if (!candidateAnchorPresenter.IsConnectable())
continue;
if (candidateAnchorPresenter.orientation != startAnchor.orientation)
continue;
if (candidateAnchorPresenter.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchorPresenter.source, startAnchor.source) == null)
continue;
var candidateSlot = candidateAnchorPresenter.slot as MaterialSlot;
if (candidateSlot == null)
continue;
if (candidateSlot.owner == startSlot.owner)
continue;
if (!startSlot.IsCompatibleWithInputSlotType(candidateSlot.valueType))
continue;
if (startStage != ShaderStage.Dynamic)
{
var candidateStage = candidateSlot.shaderStage;
if (candidateStage == ShaderStage.Dynamic)
candidateStage = NodeUtils.FindEffectiveShaderStage(candidateSlot.owner, !startSlot.isOutputSlot);
if (candidateStage != ShaderStage.Dynamic && candidateStage != startStage)
continue;
}
compatibleAnchors.Add(candidateAnchorPresenter);
}
return compatibleAnchors;
}
void OnNodeChanged(INode inNode, ModificationScope scope)

var toNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(nd => nd.node.guid == toNodeGuid);
if (toNodePresenter != null)
// Make the input node (i.e. right side of the connection) re-render
OnNodeChanged(toNodePresenter.node, ModificationScope.Graph);

m_Elements.AddRange(edgePresenters.OfType<GraphElementPresenter>());
// Calculate which nodes require updates each frame (i.e. are time-dependent).
// Let the node set contain all the nodes that are directly time-dependent.

// The wavefront contains time-dependent nodes from which we wish to propagate time-dependency into the
// nodes that it feeds into.
var wavefront = new Stack<MaterialNodePresenter>(m_TimeDependentPresenters.Values);
while (wavefront.Count > 0)
var presenter = wavefront.Pop();
// Loop through all nodes that the node feeds into.
foreach (var slot in presenter.node.GetOutputSlots<ISlot>())
var wavefront = new Stack<MaterialNodePresenter>(m_TimeDependentPresenters.Values);
while (wavefront.Count > 0)
foreach (var edge in graph.GetEdges(slot.slotReference))
var presenter = wavefront.Pop();
// Loop through all nodes that the node feeds into.
foreach (var slot in presenter.node.GetOutputSlots<ISlot>())
// We look at each node we feed into.
var inputNodeGuid = edge.inputSlot.nodeGuid;
foreach (var edge in graph.GetEdges(slot.slotReference))
{
// We look at each node we feed into.
var inputNodeGuid = edge.inputSlot.nodeGuid;
// If the input node is already in the set of time-dependent nodes, we don't need to process it.
if (m_TimeDependentPresenters.ContainsKey(inputNodeGuid))
continue;
// If the input node is already in the set of time-dependent nodes, we don't need to process it.
if (m_TimeDependentPresenters.ContainsKey(inputNodeGuid))
continue;
// Find the matching presenter.
var inputPresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(p => p.node.guid == inputNodeGuid);
if (inputPresenter == null)
{
Debug.LogErrorFormat("A presenter could not be found for the node with guid `{0}`", inputNodeGuid);
continue;
}
// Find the matching presenter.
var inputPresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(p => p.node.guid == inputNodeGuid);
if (inputPresenter == null)
{
Debug.LogErrorFormat("A presenter could not be found for the node with guid `{0}`", inputNodeGuid);
continue;
// Add the node to the set of time-dependent nodes, and to the wavefront such that we can process the nodes that it feeds into.
m_TimeDependentPresenters.Add(inputPresenter.node.guid, inputPresenter);
wavefront.Push(inputPresenter);
// Add the node to the set of time-dependent nodes, and to the wavefront such that we can process the nodes that it feeds into.
m_TimeDependentPresenters.Add(inputPresenter.node.guid, inputPresenter);
wavefront.Push(inputPresenter);
}
}
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


{
if (scope >= ModificationScope.Graph)
{
var stage = NodeUtils.FindEffectiveShaderStage(m_Node, true);
if (!(m_Node is AbstractSurfaceMasterNode) && stage == ShaderStage.Vertex)
{
// Debug.Log(m_Node.name + ":" + stage);
m_Texture = null;
return;
}
// TODO: Handle shader regeneration error
var status = UpdatePreviewShader();
}

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


{
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
VisualElement m_PreviewContainer;
Image m_PreviewImage;
bool m_IsScheduled;

leftContainer.Add(m_ControlsContainer);
m_CurrentControls = new List<GraphControlPresenter>();
m_PreviewImage = new Image
m_PreviewContainer = new VisualElement { name = "preview" };
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
m_PreviewImage.AddToClassList("inactive");
leftContainer.Add(m_PreviewImage);
m_PreviewImage = new Image
{
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
}
leftContainer.Add(m_PreviewContainer);
}
void UpdatePreviewTexture(NodePreviewPresenter preview)

if (preview == null || preview.texture == null)
{
m_PreviewImage.AddToClassList("inactive");
// Debug.Log(GetPresenter<MaterialNodePresenter>().node.name);
m_PreviewContainer.Clear();
m_PreviewImage.RemoveFromClassList("inactive");
if (m_PreviewContainer.childCount == 0)
m_PreviewContainer.Add(m_PreviewImage);
Dirty(ChangeType.Repaint);
// Dirty(ChangeType.Layout);
}
void UpdateControls(MaterialNodePresenter nodeData)

{
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
m_PreviewImage.AddToClassList("inactive");
m_PreviewContainer.Clear();
UpdatePreviewTexture(null);
return;
}

if (node.expanded)
m_PreviewImage.RemoveFromClassList("hidden");
{
UpdatePreviewTexture(node.preview);
}
m_PreviewImage.AddToClassList("hidden");
m_PreviewContainer.Clear();
}
}
}

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


width: 400;
}
.MaterialNode #preview {
.MaterialNode #preview Image {
height: 200;
width: 200;
}

padding-top: 10;
}
.nodeEditor > .header {
NodeEditorHeaderView {
padding-left: 16;
padding-right: 16;
padding-bottom: 10;

.nodeEditor > .header > .type {
NodeEditorHeaderView > #preType {
margin-left: 10;
}
NodeEditorHeaderView > #preType,
NodeEditorHeaderView > #postType,
NodeEditorHeaderView > #type {
margin-left: 10;
.nodeEditor > .header > .title {
NodeEditorHeaderView > #title {
text-color: rgb(180, 180, 180);
font-style: bold;
}

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

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


fileFormatVersion: 2
guid: a8cb0d181b460aa4bac2693ce3bfc1ad
timeCreated: 1504702312
timeCreated: 1504881039
licenseType: Pro
ShaderImporter:
externalObjects: {}

79
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSlot.cs


public class MaterialSlot : SerializableSlot
{
[SerializeField]
private SlotValueType m_ValueType;
SlotValueType m_ValueType;
private Vector4 m_DefaultValue;
Vector4 m_DefaultValue;
private Vector4 m_CurrentValue;
Vector4 m_CurrentValue;
private ConcreteSlotValueType m_ConcreteValueType;
ConcreteSlotValueType m_ConcreteValueType;
private string m_ShaderOutputName;
string m_ShaderOutputName;
[SerializeField]
ShaderStage m_ShaderStage;
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, bool hidden = false)
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
SharedInitialize(shaderOutputName, valueType, defaultValue);
SharedInitialize(shaderOutputName, valueType, defaultValue, shaderStage);
private void SharedInitialize(string inShaderOutputName, SlotValueType inValueType, Vector4 inDefaultValue)
void SharedInitialize(string inShaderOutputName, SlotValueType inValueType, Vector4 inDefaultValue, ShaderStage shaderStage)
this.shaderStage = shaderStage;
private static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
{
switch (type)
{

private set { m_ShaderOutputName = value; }
}
public ShaderStage shaderStage
{
get { return m_ShaderStage; }
set { m_ShaderStage = value; }
}
public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (!generationMode.IsPreview())

return "error";
}
}
/*
public override bool OnGUI()
{
EditorGUI.BeginChangeCheck();
m_CurrentValue = EditorGUILayout.Vector4Field("Value", m_CurrentValue);
return EditorGUI.EndChangeCheck();
}
public bool OnGUI(Rect rect, ConcreteSlotValueType inputSlotType)
{
EditorGUI.BeginChangeCheck();
var rectXmax = rect.xMax;
switch (inputSlotType)
{
case ConcreteSlotValueType.Vector1:
rect.x = rectXmax - 50;
rect.width = 50;
EditorGUIUtility.labelWidth = 15;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
m_CurrentValue.x = EditorGUI.FloatField(rect, "X", m_CurrentValue.x);
break;
case ConcreteSlotValueType.Vector2:
rect.x = rectXmax - 90;
rect.width = 90;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
var result2 = new Vector4(m_CurrentValue.x, m_CurrentValue.y);
result2 = EditorGUI.Vector2Field(rect, GUIContent.none, result2);
m_CurrentValue.x = result2.x;
m_CurrentValue.y = result2.y;
break;
case ConcreteSlotValueType.Vector3:
rect.x = rectXmax - 140;
rect.width = 140;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
var result3 = new Vector3(m_CurrentValue.x, m_CurrentValue.y, m_CurrentValue.z);
result3 = EditorGUI.Vector3Field(rect, GUIContent.none, result3);
m_CurrentValue.x = result3.x;
m_CurrentValue.y = result3.y;
m_CurrentValue.z = result3.z;
break;
default:
rect.x = rectXmax - 190;
rect.width = 190;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
m_CurrentValue = EditorGUI.Vector4Field(rect, GUIContent.none, m_CurrentValue);
break;
}
return EditorGUI.EndChangeCheck();
}*/
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/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, attribute.hidden));
ConvertTypeToSlotValueType(par), attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden));
m_Slots.Add(attribute);

16
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/MetallicMasterNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Vertex));
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, 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.zero, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs


using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class NodeEditorHeaderView : VisualElement
{
VisualElement m_Title;
VisualElement m_Type;
public NodeEditorHeaderView()
{
m_Title = new VisualElement { name = "title", text = "" };
Add(m_Title);
Add(new VisualElement { name = "preType", text = "(" });
m_Type = new VisualElement { name = "type", text = "" };
Add(m_Type);
Add(new VisualElement { name = "postType", text = ")" });
}
public string title
{
get { return m_Title.text; }
set { m_Title.text = value; }
}
public string type
{
get { return m_Type.text; }
set { m_Type.text = value; }
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs.meta


fileFormatVersion: 2
guid: 157f3e805d124f169cf20967d94036b3
timeCreated: 1504857315

34
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/PositionNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Geometry/Position")]
public class PositionNode : AbstractMaterialNode
{
const string kOutputSlotName = "XYZW";
public const int OutputSlotId = 0;
public PositionNode()
{
name = "Position";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero, ShaderStage.Vertex));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId }; }
}
public override string GetVariableNameForSlot(int slotId)
{
return "v.vertex";
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ShaderStage.cs


using System;
namespace UnityEngine.MaterialGraph
{
public enum ShaderStage
{
Dynamic,
Vertex,
Fragment
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ShaderStage.cs.meta


fileFormatVersion: 2
guid: 02d8af4c3fb9404ba3d6689c815c18d2
timeCreated: 1504863207

29
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexInterpolatorNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Vertex Interpolation")]
public class VertexInterpolatorNode : AbstractMaterialNode
{
const string k_InputSlotName = "In";
const string k_OutputSlotName = "Out";
public const int InputSlotId = 0;
public const int OutputSlotId = 1;
public VertexInterpolatorNode()
{
name = "Position";
UpdateNodeAfterDeserialization();
}
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));
RemoveSlotsNameNotMatching(k_ValidSlots);
}
static readonly int[] k_ValidSlots = { InputSlotId, OutputSlotId };
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexInterpolatorNode.cs.meta


fileFormatVersion: 2
guid: bcb2926c7b8d4a61bc8773121674ad57
timeCreated: 1504275680

64
MaterialGraphProject/Assets/NewNodes/Kill/VertexPositionNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Geometry/Vertex Position")]
public class VertexPositionNode : AbstractMaterialNode
{
private const string kOutputSlotName = "XYZW";
private const string kOutputSlotNameXYZ = "XYZ";
private const string kOutputSlotNameX = "X";
private const string kOutputSlotNameY = "Y";
private const string kOutputSlotNameZ = "Z";
private const string kOutputSlotNameW = "W";
public const int OutputSlotId = 0;
public const int OutputSlotIdXYZ = 1;
public const int OutputSlotIdX = 2;
public const int OutputSlotIdY = 3;
public const int OutputSlotIdZ = 4;
public const int OutputSlotIdW = 5;
public VertexPositionNode()
{
name = "VertexPostion";
UpdateNodeAfterDeserialization();
}
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));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlotIdXYZ , OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotIdW }; }
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlotIdXYZ:
return "v.vertex.xyz";
case OutputSlotIdX:
return "v.vertex.x";
case OutputSlotIdY:
return "v.vertex.y";
case OutputSlotIdZ:
return "v.vertex.z";
case OutputSlotIdW:
return "v.vertex.w";
default:
return "v.vertex";
}
}
}
}

/MaterialGraphProject/Assets/NewNodes/Kill/VertexPositionNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/PositionNode.cs.meta

正在加载...
取消
保存