浏览代码

[Shader Graph]

Remove properties as they are not needed (will expose property setting per input node)
Add support for compact node UI view
Add Vector3 node
Update some example graphs
/main
Tim Cooper 9 年前
当前提交
28d3f4cc
共有 27 个文件被更改,包括 1283 次插入1394 次删除
  1. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 42
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  3. 1
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  4. 1
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs
  5. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/SimpleWidgets.cs
  6. 33
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs
  7. 40
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  8. 40
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
  9. 80
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs
  10. 44
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  11. 42
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs
  12. 43
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector2Node.cs
  13. 44
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs
  14. 20
      UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs
  15. 5
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
  16. 66
      UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph
  17. 27
      UnityProject/ProjectSettings/GraphicsSettings.asset
  18. 2
      UnityProject/ProjectSettings/ProjectVersion.txt
  19. 67
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector3Node.cs
  20. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector3Node.cs.meta
  21. 1001
      UnityProject/Assets/UnityShaderEditor/Graphs/onenode.ShaderGraph
  22. 8
      UnityProject/Assets/UnityShaderEditor/Graphs/onenode.ShaderGraph.meta
  23. 34
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/PropertyNodeEditor.cs
  24. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/PropertyNodeEditor.cs.meta
  25. 8
      UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph.meta
  26. 1001
      UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph

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


namespace UnityEditor.MaterialGraph
{
public interface IGenerateGraphProperties
{
void GenerateSharedProperties(PropertyGenerator shaderProperties, ShaderGenerator propertyUsages, GenerationMode generationMode);
IEnumerable<ShaderProperty> GetPropertiesForPropertyType(PropertyType propertyType);
}
public abstract class BaseMaterialGraph : Graph
{
private PreviewRenderUtility m_PreviewUtility;

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


namespace UnityEditor.MaterialGraph
{
public sealed class DrawableMaterialNode : MoveableBox
public sealed class DrawableMaterialNode : CanvasElement
private Type m_OutputType;
private string m_Title;
private bool m_Error;
: base(node.position.min, width)
translation = node.position.min;
scale = new Vector2(width, width);
m_OutputType = outputType;
error = node.hasError;
m_Error = node.hasError;
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);

pos.y = yStart;
foreach (var slot in node.outputSlots)
{
// don't show empty output slots in collapsed mode
if (node.drawMode == DrawMode.Collapsed && slot.edges.Count == 0)
continue;
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof (Vector4), slot, data, Direction.eOutput));
}

m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight);
pos.y += nodeUIHeight;
if (node.hasPreview)
if (node.hasPreview && node.drawMode != DrawMode.Collapsed)
pos.y += width - 20.0f;
pos.y += m_PreviewArea.height;
}
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f);

AddManipulator(new IMGUIContainer());
AddManipulator(new Draggable());
}
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)

public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
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);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, 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;
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
if (m_Node.NodeUI(m_NodeUIRect))
{
// if we were changed, we need to redraw all the

}
}
if (m_Node.hasPreview)
if (m_Node.hasPreview
&& m_Node.drawMode != DrawMode.Collapsed
&& m_PreviewArea.width > 0
&& m_PreviewArea.height > 0)
base.Render(parentRect, canvas);
}
public static void OnGUI(List<CanvasElement> selection)

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


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

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


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)

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


public class SimpleBox : CanvasElement
{
protected string m_Title = "simpleBox";
protected bool m_Expanded = true;
protected bool error = false;

EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), error ? Color.red : selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Title, EditorStyles.toolbarTextField);
base.Render(parentRect, canvas);
}
}

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


namespace UnityEditor.MaterialGraph
{
public class MaterialGraph : ScriptableObject, IGenerateGraphProperties
public class MaterialGraph : ScriptableObject
[SerializeField]
private MaterialProperties m_MaterialProperties;
[SerializeField]
private MaterialOptions m_MaterialOptions;

return -1;
//return m_Shader.GetInstanceID();
}
public MaterialProperties materialProperties { get { return m_MaterialProperties; } }
public void GenerateSharedProperties(PropertyGenerator shaderProperties, ShaderGenerator propertyUsages, GenerationMode generationMode)
{
m_MaterialProperties.GenerateSharedProperties(shaderProperties, propertyUsages, generationMode);
}
public IEnumerable<ShaderProperty> GetPropertiesForPropertyType(PropertyType propertyType)
{
return m_MaterialProperties.GetPropertiesForPropertyType(propertyType);
}
if (m_MaterialProperties == null)
{
m_MaterialProperties = CreateInstance<MaterialProperties>();
m_MaterialProperties.hideFlags = HideFlags.HideInHierarchy;
}
if (m_MaterialOptions == null)
{
m_MaterialOptions = CreateInstance<MaterialOptions>();

// if (m_MaterialProperties != null)
// m_MaterialProperties.OnChangePreviewState -= OnChangePreviewState;
}
void OnChangePreviewState(object sender, EventArgs eventArgs)
{
m_PixelGraph.previewState = (PreviewState)sender;
}
AssetDatabase.AddObjectToAsset(m_MaterialProperties, this);
AssetDatabase.AddObjectToAsset(m_MaterialOptions, this);
AssetDatabase.AddObjectToAsset(m_PixelGraph, this);
}

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


Fixed = 2,
}
public enum PropertyType
{
Color,
Texture2D,
Float,
Vector2,
Vector3,
Vector4
}
public class PreviewProperty
{
public string m_Name;

Preview3D
}
public enum DrawMode
{
Full,
Collapsed
}
[Serializable]
class SlotDefaultValueKVP
{

[SerializeField]
private List<SlotDefaultValueKVP> m_SlotDefaultValues;
[SerializeField]
private DrawMode m_DrawMode = DrawMode.Full;
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>();

public virtual bool hasPreview { get { return false; } }
public virtual PreviewMode previewMode { get { return PreviewMode.Preview2D; } }
public DrawMode drawMode
{
get { return m_DrawMode; }
set { m_DrawMode = value; }
}
public bool isSelected { get; set; }
// lookup custom slot properties

}
protected PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D;
private bool needsUpdate
{
get { return true; }
}
protected virtual int previewWidth
{
get { return kPreviewWidth; }

mat.SetColor(previewProperty.m_Name, previewProperty.m_Color);
break;
case PropertyType.Vector2:
mat.SetVector(previewProperty.m_Name, previewProperty.m_Vector4);
break;
case PropertyType.Vector3:
mat.SetVector(previewProperty.m_Name, previewProperty.m_Vector4);
break;
case PropertyType.Vector4:

public virtual void OnGUI()
{
EditorGUILayout.LabelField("Preview Mode: " + previewMode);
foreach (var slot in slots)
GUILayout.Label("Slot Defaults", EditorStyles.boldLabel);
foreach (var slot in slots.Where(x => x.isInputSlot && x.edges.Count == 0))
DoSlotUI(this, slot);
}

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


{
get { return PropertyType.Color; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{}
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();

{
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
if (exposed || generationMode.IsPreview())
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
if (HasBoundProperty() || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{

m_Color = EditorGUI.ColorField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), m_Color);
if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as ColorProperty;
if (boundProp != null)
boundProp.defaultColor = m_Color;
}
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var colorProp = property as ColorProperty;
if (colorProp)
{
m_Color = colorProp.defaultColor;
}
if (rebuildShaders)
RegeneratePreviewShaders();
return false;
}
public override PreviewProperty GetPreviewProperty()

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


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

[SerializeField]
private ShaderProperty m_BoundProperty;
public bool exposed
{
get { return m_BoundProperty != null; }
}
//[SerializeField]
//private string m_Name;
protected virtual bool HasBoundProperty() { return m_BoundProperty != null; }
public ShaderProperty boundProperty { get { return m_BoundProperty; } }
[SerializeField]
private string m_Description;
public virtual void BindProperty(ShaderProperty property, bool rebuildShaders)
{
m_BoundProperty = property;
}
[SerializeField]
private bool m_Exposed;
public virtual void RefreshBoundProperty(ShaderProperty toRefresh, bool rebuildShader)
public bool exposed
if (m_BoundProperty != null && m_BoundProperty == toRefresh)
{
BindProperty(toRefresh, rebuildShader);
}
get { return m_Exposed; }
public IEnumerable<ShaderProperty> FindValidPropertyBindings()
public string description
if (graph is IGenerateGraphProperties)
return (graph as IGenerateGraphProperties).GetPropertiesForPropertyType(propertyType);
return new ShaderProperty[0];
get { return m_Description; }
if (m_BoundProperty == null)
// var validExposedName = !string.IsNullOrEmpty(m_Name);
//if (!validExposedName)
return m_BoundProperty.name;
// return m_Name + "_Uniform";
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
base.CollectPreviewMaterialProperties(properties);
properties.Add(GetPreviewProperty());
return GetPropertyName();
public void UnbindProperty(ShaderProperty prop)
public override float GetNodeUIHeight(float width)
if (m_BoundProperty != null && m_BoundProperty == prop)
{
m_BoundProperty = null;
RegeneratePreviewShaders();
}
return 2 * EditorGUIUtility.singleLineHeight;
public override void OnGUI()
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
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);
}
base.CollectPreviewMaterialProperties(properties);
properties.Add(GetPreviewProperty());
}
}
}

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


private List<string> m_TextureTypeNames;
public override bool hasPreview { get { return false; } }
public override bool hasPreview { get { return true; } }
public override void OnCreate()
{

// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (HasBoundProperty())
return;
visitor.AddShaderProperty(new TexturePropertyChunk(GetPropertyName(), GetPropertyName(), m_DefaultTexture, m_TextureType, false, false));
visitor.AddShaderProperty(new TexturePropertyChunk(GetPropertyName(), GetPropertyName(), m_DefaultTexture, m_TextureType, false, exposed));
if (HasBoundProperty())
return;
return EditorGUIUtility.singleLineHeight + width - 20;
return EditorGUIUtility.singleLineHeight * 2;
}
public override bool NodeUI(Rect drawArea)

base.NodeUI(drawArea);
EditorGUI.BeginChangeCheck();
m_DefaultTexture = EditorGUI.ObjectField(new Rect(drawArea.x, drawArea.y, drawArea.width, drawArea.width), GUIContent.none, m_DefaultTexture, typeof (Texture2D), false) as Texture2D;
m_DefaultTexture = EditorGUI.MiniThumbnailObjectField( new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), new GUIContent("Texture"), m_DefaultTexture, typeof(Texture2D), null) as Texture2D;
drawArea.y += EditorGUIUtility.singleLineHeight;
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);
m_TextureType = (TextureType) EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), (int) m_TextureType, m_TextureTypeNames.ToArray(), EditorStyles.popup);
var typeChanged = EditorGUI.EndChangeCheck();
if (typeChanged)

}
if (texureChanged)
{
var boundProp = boundProperty as TextureProperty;
if (boundProp != null)
{
boundProp.defaultTexture = m_DefaultTexture;
boundProp.defaultTextureType = m_TextureType;
}
return true;
}
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var texProp = property as TextureProperty;
if (texProp)
{
m_DefaultTexture = texProp.defaultTexture;
m_TextureType = texProp.defaultTextureType;
}
if (rebuildShaders)
RegeneratePreviewShaders();
return texureChanged;
MaterialWindow.DebugMaterialGraph("Returning: " + GetPropertyName() + " " + m_DefaultTexture);
return new PreviewProperty
{
m_Name = GetPropertyName(),

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


{
get { return PropertyType.Float; }
}
{}
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
return GetPropertyName();
if (exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(GetPropertyName(), description, m_Value, false));
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderChunk("float " + GetPropertyName() + ";", true);
if (exposed || generationMode.IsPreview())
visitor.AddShaderChunk("float " + GetPropertyName() + ";", true);
if (HasBoundProperty() || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
public override float GetNodeUIHeight(float width)
{
return 2*EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);

if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as FloatProperty;
if (boundProp != null)
boundProp.defaultValue = m_Value;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var vectorProp = property as FloatProperty;
if (vectorProp)
{
m_Value = vectorProp.defaultValue;
}
if (rebuildShaders)
RegeneratePreviewShaders();
}
public override PreviewProperty GetPreviewProperty()

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


{
get { return PropertyType.Vector2; }
}
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();
}
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderChunk("float2 " + GetPropertyName() + ";", true);
if (exposed || generationMode.IsPreview())
visitor.AddShaderChunk("float2 " + GetPropertyName() + ";", true);
if (HasBoundProperty() || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
public override float GetNodeUIHeight(float width)
{
return 2*EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);

if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as VectorProperty;
if (boundProp != null)
{
boundProp.defaultVector = m_Value;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var vectorProp = property as VectorProperty;
if (vectorProp)
{
m_Value = vectorProp.defaultVector;
}
if (rebuildShaders)
RegeneratePreviewShaders();
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty

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


{
get { return PropertyType.Vector4; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{}
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();
}
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
if (exposed || generationMode.IsPreview())
visitor.AddShaderChunk("float4 " + GetPropertyName() + ";", true);
if (HasBoundProperty() || generationMode.IsPreview())
if (exposed || generationMode.IsPreview())
public override float GetNodeUIHeight(float width)
{
return 2*EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);

if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as VectorProperty;
if (boundProp != null)
{
boundProp.defaultVector = m_Value;
}
}
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var vectorProp = property as VectorProperty;
if (vectorProp)
{
m_Value = vectorProp.defaultVector;
}
if (rebuildShaders)
RegeneratePreviewShaders();
}
public override PreviewProperty GetPreviewProperty()

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


namespace UnityEditor.MaterialGraph
{
class PixelGraph : BaseMaterialGraph, IGenerateGraphProperties
class PixelGraph : BaseMaterialGraph
public PreviewState previewState { get; set; }
public PixelShaderNode pixelMasterNode
{
get

return m_ActiveNodes;
}
}
public void GenerateSharedProperties(PropertyGenerator shaderProperties, ShaderGenerator propertyUsages, GenerationMode generationMode)
{
owner.GenerateSharedProperties(shaderProperties, propertyUsages, generationMode);
}
public IEnumerable<ShaderProperty> GetPropertiesForPropertyType(PropertyType propertyType)
{
return owner.GetPropertiesForPropertyType(propertyType);
}
public MaterialGraph owner { get; set; }
public void GenerateSurfaceShader(

pixelMasterNode.GenerateSurfaceOutput(surfaceOutput);
var genMode = isPreview ? GenerationMode.Preview3D : GenerationMode.SurfaceShader;
owner.materialProperties.GenerateSharedProperties(shaderProperties, propertyUsages, genMode);
foreach (var node in activeNodes)
{
if (node is IGeneratesFunction) (node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, genMode);

5
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs


var textureInfo = new TextureInfo
{
name = prop.propertyName,
textureId = prop.defaultTexture.GetInstanceID(),
textureId = prop.defaultTexture != null ? prop.defaultTexture.GetInstanceID() : 0,
modifiable = prop.modifiable
};
result.Add(textureInfo);

var shaderName = "Hidden/PreviewShader/" + node.GetOutputVariableNameForSlot(node.outputSlots.First(), generationMode);
var activeNodeList = node.CollectChildNodesByExecutionOrder();
if (node.graph is IGenerateGraphProperties)
(node.graph as IGenerateGraphProperties).GenerateSharedProperties(shaderPropertiesVisitor, shaderPropertyUsagesVisitor, generationMode);
foreach (var activeNode in activeNodeList)
{

66
UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph


m_Dependencies:
- {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 6, guid: 0000000000000000f000000000000000, type: 0}
m_NonModifiableTextures: {}
m_ShaderIsBaked: 0
errors: []
m_DefaultTextures: {}

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 5a9889c008f4a588caf68a68cf97e6c7
Hash: 46ebc5795b09a23cf030498b1cb17fd9
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0:

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: cf3b6ee4c7109c36eb9b750947d2a0f0
Hash: 738f319c99d8aa8292d1f7520c8b922d
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0: []

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 5a9889c008f4a588caf68a68cf97e6c7
Hash: 46ebc5795b09a23cf030498b1cb17fd9
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0:

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 3256300b287076da8182f61f7e9b58f4
Hash: 08aad5a7f8e10c1de3313cd9da4d2add
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0: []

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 3256300b287076da8182f61f7e9b58f4
Hash: 08aad5a7f8e10c1de3313cd9da4d2add
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0:

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 3256300b287076da8182f61f7e9b58f4
Hash: 08aad5a7f8e10c1de3313cd9da4d2add
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0: []

m_TypesMask: 3
m_IncludesHash:
serializedVersion: 2
Hash: 4bb694398f4a8095e47a599d488d0706
Hash: 64144d10dc2e79470b160642e134f1b5
m_IsGLSL: 0
m_FromOther: 1
m_VariantsUser0: []

m_Script: {fileID: 11500000, guid: ef5b9f0785847b04983f907c7f016a36, type: 3}
m_Name: LayeredTarp
m_EditorClassIdentifier:
m_MaterialProperties: {fileID: 11487156}
m_MaterialOptions: {fileID: 11406038}
m_PixelGraph: {fileID: 11479744}
m_Expanded: 0

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: UV
m_Node: {fileID: 11400992}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_DefaultTexture: {fileID: 2800000, guid: 1734aefbb51846643ae250665f33f6ca, type: 3}
m_TextureType: 3
--- !u!114 &11406038

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Alpha
m_Node: {fileID: 11416828}
m_DrawMode: 0
m_PrecisionNames:
- half
m_LightFunctionClassName: UnityEditor.MaterialGraph.PBRSpecularLightFunction

style: node
position:
serializedVersion: 2
x: 291.73352
y: 151.97438
width: 730.2665
height: -26.974396
x: 341.73352
y: 107.97438
width: 680.2665
height: 17.025604
showEmptySlots: 1
m_SlotDefaultValues:
- slotName: Input1

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11429502}
m_DrawMode: 0
m_PrecisionNames:
- half
m_DefaultValue: 0

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11443630}
m_DrawMode: 0
m_PrecisionNames:
- half
--- !u!114 &11448176

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: UV
m_Node: {fileID: 11448176}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_DefaultTexture: {fileID: 2800000, guid: 7a898a3a5ba9f8642b21c27bcc225d3e, type: 3}
m_TextureType: 0
--- !u!114 &11452850

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: UV
m_Node: {fileID: 11452850}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_DefaultTexture: {fileID: 2800000, guid: 06ca5507e7192eb4a8011dc7cdb6db95, type: 3}
m_TextureType: 0
--- !u!114 &11454916

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11454916}
m_DrawMode: 0
m_PrecisionNames:
- half
--- !u!114 &11455774

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11455774}
m_DrawMode: 0
m_PrecisionNames:
- half
--- !u!114 &11456574

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Value
m_Node: {fileID: 11456574}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_Value: {x: 2, y: 2, z: 2, w: 2}
--- !u!114 &11457338
MonoBehaviour:

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: UV
m_Node: {fileID: 11457338}
m_DrawMode: 0
m_PrecisionNames:
- half
--- !u!114 &11479744

- {fileID: 11443630}
- {fileID: 11456574}
edges:
- m_FromNode: {fileID: 11429502}
m_ToNode: {fileID: 11416828}
m_FromSlotName: Output
m_ToSlotName: Albedo
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11443630}
m_ToNode: {fileID: 11496282}
m_FromSlotName: Output

m_ToNode: {fileID: 11429502}
m_FromSlotName: RGBA
m_ToSlotName: Input2
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11429502}
m_ToNode: {fileID: 11416828}
m_FromSlotName: Output
m_ToSlotName: Albedo
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400992}
m_ToNode: {fileID: 11416828}

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Color
m_Node: {fileID: 11486954}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_Color: {r: 1, g: 0.68275857, b: 0, a: 0}
--- !u!114 &11487156
MonoBehaviour:

m_Name:
m_EditorClassIdentifier:
m_ShaderProperties:
- {fileID: 114000013639360892}
- {fileID: -842150451}
m_Expanded: 0
--- !u!114 &11489308
MonoBehaviour:

m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: UV
m_Node: {fileID: 11496282}
m_DrawMode: 0
m_BoundProperty: {fileID: 0}
m_Description:
m_Exposed: 0
m_DefaultTexture: {fileID: 2800000, guid: ca7ba913502c8bb44a66350131805326, type: 3}
m_TextureType: 0
--- !u!114 &114000013639360892

27
UnityProject/ProjectSettings/GraphicsSettings.asset


--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 4
serializedVersion: 6
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}

m_ScreenSpaceShadows:
m_Mode: 1
m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
m_LegacyDeferred:
m_Mode: 1
m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}

- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_ShaderSettings:
useScreenSpaceShadows: 1
m_ShaderSettings_Tier1:
useCascadedShadowMaps: 1
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_ShaderSettings_Tier2:
useCascadedShadowMaps: 1
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_ShaderSettings_Tier3:
useCascadedShadowMaps: 1
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_ShaderSettings_Tier4:
useCascadedShadowMaps: 1
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_BuildTargetShaderSettings: []
m_LightmapStripping: 0
m_FogStripping: 0

2
UnityProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 5.3.0b6
m_EditorVersion: 5.4.0b3
m_StandardAssetsVersion: 0

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


using System;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
[Title("Generate/Vector 3 Node")]
class Vector3Node : PropertyNode, IGeneratesBodyCode
{
private const string kOutputSlotName = "Value";
[SerializeField]
private Vector3 m_Value;
public override void OnCreate()
{
base.OnCreate();
name = "V3Node";
}
public override void OnEnable()
{
base.OnEnable();
AddSlot(new MaterialGraphSlot(new Slot(SlotType.OutputSlot, kOutputSlotName), SlotValueType.Vector3));
}
public override PropertyType propertyType
{
get { return PropertyType.Vector3; }
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType)
{
if (exposed || generationMode.IsPreview())
visitor.AddShaderChunk("float3 " + GetPropertyName() + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "3 " + GetPropertyName() + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true);
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
EditorGUI.BeginChangeCheck();
m_Value = EditorGUI.Vector3Field(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value);
if (EditorGUI.EndChangeCheck())
return true;
return false;
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_PropType = PropertyType.Vector3,
m_Vector4 = m_Value
};
}
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector3Node.cs.meta


fileFormatVersion: 2
guid: 1350e4a38ff5ae44a9d8627d33b48de8
timeCreated: 1453378777
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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

8
UnityProject/Assets/UnityShaderEditor/Graphs/onenode.ShaderGraph.meta


fileFormatVersion: 2
guid: 12258f82ca70f6847b551eaf28207d88
timeCreated: 1450784498
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

34
UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/PropertyNodeEditor.cs


using System.Collections.Generic;
using System.Linq;
namespace UnityEditor.MaterialGraph
{
[CustomEditor(typeof(PropertyNode), true)]
class PropertyNodeEditor : Editor
{
public override void OnInspectorGUI()
{
var propertyNode = target as PropertyNode;
if (propertyNode == null)
return;
// find available properties
var allowedBindings = propertyNode.FindValidPropertyBindings().ToList();
var names = new List<string> {"none"};
names.AddRange(allowedBindings.Select(x => x.name));
var currentIndex = names.IndexOf(propertyNode.boundProperty == null ? "none" : propertyNode.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];
propertyNode.BindProperty(selected, true);
}
}
}
}

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


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

8
UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph.meta


fileFormatVersion: 2
guid: 9686b8ceda059fd43af5a7a3f5e61f10
timeCreated: 1444117524
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

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

正在加载...
取消
保存