浏览代码

Starting to extract properties.

/main
Tim Cooper 7 年前
当前提交
f6fa3513
共有 31 个文件被更改,包括 642 次插入638 次删除
  1. 6
      MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs
  2. 19
      MaterialGraphProject/Assets/NewNodes/Keep/ConstantsNode.cs
  3. 4
      MaterialGraphProject/Assets/NewNodes/Kill/ToggleNode.cs
  4. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs
  5. 96
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs
  7. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
  8. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  9. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs
  10. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/CubemapNodePresenter.cs
  11. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureAssetNodePresenter.cs
  12. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureLODNodePresenter.cs
  13. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureSamplerNodePresenter.cs
  14. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  15. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
  16. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
  17. 293
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractMaterialGraph.cs
  18. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs
  19. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/CubemapNode.cs
  20. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureLODNode.cs
  21. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs
  22. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs
  23. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector3Node.cs
  24. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector4Node.cs
  25. 161
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
  26. 12
      MaterialGraphProject/Assets/NewNodes/Keep/Texture2DNode.cs.meta
  27. 137
      MaterialGraphProject/Assets/NewNodes/Keep/Texture2DNode.cs
  28. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs.meta
  29. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs.meta
  30. 104
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs
  31. 104
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs

6
MaterialGraphProject/Assets/NewNodes/Editor/ToggleNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
/>an class="p">* [Serializable]
class ToggleNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()

{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
*/
*
public override float GetHeight()
{
return 2 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;

instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}*/
}

19
MaterialGraphProject/Assets/NewNodes/Keep/ConstantsNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Constants")]
public class ConstantsNode : PropertyNode, IGeneratesBodyCode
public class ConstantsNode : AbstractMaterialNode, IGeneratesBodyCode
{
static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{

RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Float,
m_Float = m_constantList[constant]
};
}
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_constantList[constant] + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant] + ";", true);
}
}
}

4
MaterialGraphProject/Assets/NewNodes/Kill/ToggleNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Toggle")]
/* [Title("Input/Toggle")]
public class ToggleNode : PropertyNode, IGeneratesBodyCode
{
[SerializeField]

m_Float = value ? 1f : 0f
};
}
}
}*/
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs


int m_SelectionCount;
TypeMapper m_TypeMapper;
[SerializeField]
private int version;
public AbstractMaterialGraph graph { get; private set; }
public AbstractNodeEditorPresenter editor
{

get { return m_SelectionCount; }
set { m_SelectionCount = value; }
}
public void Dirty()
{
version++;
}
public void Initialize(string graphName)
public void Initialize(AbstractMaterialGraph igraph, string graphName)
graph = igraph;
m_Title = graphName;
m_TypeMapper = new TypeMapper(typeof(INode), typeof(AbstractNodeEditorPresenter), typeof(StandardNodeEditorPresenter))
{

96
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs


VisualElement m_Title;
VisualElement m_ContentContainer;
VisualElement m_MultipleSelectionsElement;
VisualElement m_PropertiesContainer;
TypeMapper m_TypeMapper;

headerContainer.Add(m_Title);
}
Add(headerContainer);
m_PropertiesContainer = new VisualElement()
{
new IMGUIContainer(OnGuiHandler)
};
m_PropertiesContainer.style.flexDirection = StyleValue<FlexDirection>.Create(FlexDirection.Column);
Add(m_PropertiesContainer);
m_ContentContainer = new VisualElement { name = "contentContainer" };
Add(m_ContentContainer);

};
}
private void OnGuiHandler()
{
if (m_Presenter == null)
return;
if (GUILayout.Button("Add Property"))
{
var gm = new GenericMenu();
gm.AddItem(new GUIContent("Float"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new FloatShaderProperty());
m_Presenter.Dirty();
});
gm.AddItem(new GUIContent("Vector2"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector2ShaderProperty());
presenter.Dirty();
});
gm.AddItem(new GUIContent("Vector3"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector3ShaderProperty());
m_Presenter.Dirty();
});
gm.AddItem(new GUIContent("Vector4"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector4ShaderProperty());
m_Presenter.Dirty();
});
gm.AddItem(new GUIContent("Color"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new ColorShaderProperty());
m_Presenter.Dirty();
});
gm.AddItem(new GUIContent("Texture"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new TextureShaderProperty());
m_Presenter.Dirty();
});
gm.ShowAsContext();
}
EditorGUI.BeginChangeCheck();
foreach (var property in m_Presenter.graph.properties.ToArray())
{
property.name = EditorGUILayout.DelayedTextField("Name", property.name);
property.description = EditorGUILayout.DelayedTextField("Description", property.description);
if (property is FloatShaderProperty)
{
var fProp = property as FloatShaderProperty;
fProp.value = EditorGUILayout.FloatField("Value", fProp.value);
}
else if (property is Vector2ShaderProperty)
{
var fProp = property as Vector2ShaderProperty;
fProp.value = EditorGUILayout.Vector2Field("Value", fProp.value);
}
else if (property is Vector3ShaderProperty)
{
var fProp = property as Vector3ShaderProperty;
fProp.value = EditorGUILayout.Vector3Field("Value", fProp.value);
}
else if (property is Vector4ShaderProperty)
{
var fProp = property as Vector4ShaderProperty;
fProp.value = EditorGUILayout.Vector4Field("Value", fProp.value);
}
else if (property is ColorShaderProperty)
{
var fProp = property as ColorShaderProperty;
fProp.value = EditorGUILayout.ColorField("Value", fProp.value);
}
else if (property is TextureShaderProperty)
{
var fProp = property as TextureShaderProperty;
fProp.value.texture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), fProp.value.texture, typeof(Texture), null) as Texture;
}
if (GUILayout.Button("Remove"))
{
m_Presenter.graph.RemoveShaderProperty(property.guid);
}
EditorGUILayout.Separator();
}
if(EditorGUI.EndChangeCheck())
m_Presenter.Dirty();
}
public override void OnDataChanged()
{
if (presenter == null)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs


EditorGUI.BeginChangeCheck();
//propertyNode.name = EditorGUILayout.TextField ("Name", propertyNode.name);
propertyNode.description = EditorGUILayout.TextField("Description", propertyNode.description);
//propertyNode.description = EditorGUILayout.TextField("Description", propertyNode.description);
if (EditorGUI.EndChangeCheck())
node.onModified(node, ModificationScope.Node);

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs


using UnityEditor.MaterialGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{

set { m_GraphInspectorPresenter = value; }
}
public void Initialize(IGraph graph, IMaterialGraphEditWindow container, string graphName)
public void Initialize(AbstractMaterialGraph graph, IMaterialGraphEditWindow container, string graphName)
m_GraphInspectorPresenter.Initialize(graphName);
m_GraphInspectorPresenter.Initialize(graph, graphName);
m_GraphPresenter = CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter.Initialize(graph, container);

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


//typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
//typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
//typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
// typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
// typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
// typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
// typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
typeMapper[typeof(PropertyNode)] = typeof(PropertyNodePresenter);
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(RadialShearNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphereWarpNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/ColorNodePresenter.cs


if (cNode == null)
return;
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
cNode.color = EditorGUILayout.ColorField(new GUIContent("Color"), cNode.color, true, true, cNode.HDR, new ColorPickerHDRConfig(0f, 8f, 0.125f, 3f));
cNode.HDR = EditorGUILayout.Toggle("HDR", cNode.HDR);
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/CubemapNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class CubeContolPresenter : GraphControlPresenter
/* class CubeContolPresenter : GraphControlPresenter
{
//private string[] m_TextureTypeNames;
//private string[] textureTypeNames

m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}*/
}*
public override void OnGUIHandler()
{

instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}*/
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureAssetNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class TextureAssetContolPresenter : GraphControlPresenter
/* class TextureAssetContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames

instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}*/
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureLODNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class TextureLODContolPresenter : GraphControlPresenter
/* class TextureLODContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames

instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}*/
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/TextureSamplerNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
/*
class TextureSamplerContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;

instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}*/
}

19
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;

{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.PropertyNode;
var tNode = node as PropertyNode;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
var graph = node.owner as AbstractMaterialGraph;
var currentGUID = tNode.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
var newIndex = EditorGUILayout.Popup("Property", currentSelectedIndex, properties.Select(x => x.name).ToArray());
if (newIndex != currentSelectedIndex)
tNode.propertyGuid = propertiesGUID[newIndex];
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2 + EditorGUIUtility.standardVerticalSpacing;
public abstract class PropertyNodePresenter : MaterialNodePresenter
public class PropertyNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs


namespace UnityEditor.MaterialGraph.IntegrationTests
{
[TestFixture]
/*[TestFixture]
public class PropertyNodeTests
{
private UnityEngine.MaterialGraph.MaterialGraph m_Graph;

m_TextureNode.GeneratePropertyUsages(generator, GenerationMode.ForReals);
Assert.AreEqual(expected, generator.GetShaderString(0));
}
}
}*/
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs


namespace UnityEditor.MaterialGraph.UnitTests
{
[TestFixture]
/* [TestFixture]
public class PropertyNodeTests
{
private class TestPropertyNode : PropertyNode

private Vector3Node m_Vector3Node;
private Vector4Node m_Vector4Node;
private ColorNode m_ColorNode;
private Texture2DNode m_TextureNode;
// private Texture2DNode m_TextureNode;
private TestPropertyNode m_PropertyNode;
private const string kPropertyName = "PropertyName";

m_Vector3Node = new Vector3Node();
m_Vector4Node = new Vector4Node();
m_ColorNode = new ColorNode();
m_TextureNode = new Texture2DNode();
// m_TextureNode = new Texture2DNode();
m_PropertyNode = new TestPropertyNode();
m_Graph.AddNode(m_Vector1Node);

m_Vector2Node.ValidateNode();
Assert.IsFalse(m_Vector1Node.hasError);
Assert.IsFalse(m_Vector2Node.hasError);
}*/
}*
[Test]
public void TestPropertyExposedOnSubgraphReturnsFalse()

m_ColorNode.GeneratePropertyUsages(generator, GenerationMode.ForReals);
Assert.AreEqual(expected, generator.GetShaderString(0));
}
}
}*/
}

293
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractMaterialGraph.cs


using System;
using System.Collections.Generic;
using UnityEditor;
public interface IAbstractShaderProperty
{
string name { get; set; }
string description { get; set; }
string propertyName { get; }
PropertyType propertyType { get; }
Guid guid { get; }
}
[Serializable]
public abstract class AbstractShaderProperty<T> : ISerializationCallbackReceiver, IAbstractShaderProperty
{
[SerializeField]
private T m_Value;
[SerializeField]
private string m_Description;
[SerializeField]
private string m_Name;
[NonSerialized]
private Guid m_Guid;
[SerializeField]
private string m_GuidSerialized;
protected AbstractShaderProperty()
{
m_Guid = Guid.NewGuid();
}
public T value
{
get { return m_Value; }
set { m_Value = value; }
}
public string name
{
get
{
if (string.IsNullOrEmpty(m_Name))
return m_Guid.ToString();
return m_Name;
}
set { m_Name = value; }
}
public string description
{
get
{
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
}
set { m_Description = value; }
}
public string propertyName
{
get
{
return string.Format("{0}_Uniform", name);
}
}
public abstract PropertyType propertyType { get; }
public Guid guid
{
get { return m_Guid; }
}
public virtual void OnBeforeSerialize()
{
m_GuidSerialized = m_Guid.ToString();
}
public virtual void OnAfterDeserialize()
{
if (!string.IsNullOrEmpty(m_GuidSerialized))
m_Guid = new Guid(m_GuidSerialized);
else
m_Guid = Guid.NewGuid();
}
}
[Serializable]
public class FloatShaderProperty : AbstractShaderProperty<float>
{
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
}
[Serializable]
public class Vector2ShaderProperty : AbstractShaderProperty<Vector2>
{
public override PropertyType propertyType
{
get { return PropertyType.Vector2; }
}
}
[Serializable]
public class Vector3ShaderProperty : AbstractShaderProperty<Vector3>
{
public override PropertyType propertyType
{
get { return PropertyType.Vector2; }
}
}
[Serializable]
public class Vector4ShaderProperty : AbstractShaderProperty<Vector4>
{
public override PropertyType propertyType
{
get { return PropertyType.Vector4; }
}
}
[Serializable]
public class ColorShaderProperty : AbstractShaderProperty<Color>
{
[SerializeField]
private bool m_HDR;
public bool HDR
{
get { return m_HDR; }
set
{
if (m_HDR == value)
return;
m_HDR = value;
}
}
public override PropertyType propertyType
{
get { return PropertyType.Color; }
}
public void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, value, m_HDR ? ColorPropertyChunk.ColorType.HDR : ColorPropertyChunk.ColorType.Default , PropertyChunk.HideState.Visible));
}
public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("float4 " + propertyName + ";", true);
}
public PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Color,
m_Color = value
};
}
}
[Serializable]
public class SerializableTexture
{
[SerializeField] private string m_SerializedTexture;
[Serializable]
private class TextureHelper
{
public Texture texture;
}
#if UNITY_EDITOR
public Texture texture
{
get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
}
set
{
if (texture == value)
return;
var tex = new TextureHelper();
tex.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
}
}
#else
public Texture defaultTexture {get; set; }
#endif
}
[Serializable]
public class TextureShaderProperty : AbstractShaderProperty<SerializableTexture>
{
[SerializeField]
private bool m_Modifiable;
public TextureShaderProperty()
{
value = new SerializableTexture();
}
public override PropertyType propertyType
{
get { return PropertyType.Texture; }
}
// Properties
public void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
value.texture, TextureType.Black,
PropertyChunk.HideState.Visible,
m_Modifiable ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("UNITY_DECLARE_TEX2D(" + propertyName + ");", true);
}
public PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = value.texture
};
}
}
[NonSerialized]
private List<IAbstractShaderProperty> m_Properties = new List<IAbstractShaderProperty>();
[SerializeField]
private List<SerializationHelper.JSONSerializedElement> m_SerializedProperties = new List<SerializationHelper.JSONSerializedElement>();
public IEnumerable<IAbstractShaderProperty> properties
{
get { return m_Properties; }
}
public override void AddNode(INode node)
{
if (node is AbstractMaterialNode)

}
}
public void AddShaderProperty(IAbstractShaderProperty property)
{
if (property == null)
return;
if (m_Properties.Contains(property))
return;
m_Properties.Add(property);
}
public void RemoveShaderProperty(Guid guid)
{
m_Properties.RemoveAll(x => x.guid == guid);
}
public override Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo> GetLegacyTypeRemapping()
{
var result = base.GetLegacyTypeRemapping();

return result;
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();
m_SerializedProperties = SerializationHelper.Serialize<IAbstractShaderProperty>(m_Properties);
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_Properties = SerializationHelper.Deserialize<IAbstractShaderProperty>(m_SerializedProperties, null);
}
}
}

38
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs


using System.Collections.Generic;
public class ColorNode : PropertyNode, IGeneratesBodyCode
public class ColorNode : AbstractMaterialNode, IGeneratesBodyCode
{
[SerializeField]
private bool m_HDR;

RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Color; }
}
public Color color
{
get { return m_Color; }

}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, color, m_HDR ? ColorPropertyChunk.ColorType.HDR : ColorPropertyChunk.ColorType.Default , PropertyChunk.HideState.Visible));
}
if (!generationMode.IsPreview())
return;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + ";", true);
// we only need to generate node code if we are using a constant... otherwise we can just refer to the property :)
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + color.r + ", " + color.g + ", " + color.b + ", " + color.a + ");", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + precision + "4 (" + color.r + ", " + color.g + ", " + color.b + ", " + color.a + ");", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
public override PreviewProperty GetPreviewProperty()
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
return new PreviewProperty
properties.Add(new PreviewProperty
m_Name = propertyName,
m_Name = GetVariableNameForNode(),
};
});
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/CubemapNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Cubemap")]
/* [Title("Input/Texture/Cubemap")]
public class CubemapNode : PropertyNode, IGeneratesBodyCode, IMayRequireViewDirection, IMayRequireNormal
{
protected const string kUVSlotName = "RefVector";

{
return true;
}
}
}*/
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureLODNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/TextureLOD")]
/>an class="p">* [Title("Input/Texture/TextureLOD")]
public class TextureLODNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "UV";

return false;
}
*/
*
public override PreviewProperty GetPreviewProperty()
{

var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}*/
}

53
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs


using System.Collections.Generic;
public class Vector1Node : PropertyNode, IGeneratesBodyCode
public class Vector1Node : AbstractMaterialNode, IGeneratesBodyCode
{
[SerializeField]
private float m_Value;

{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
public float value

}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
if (exposedState == ExposedState.Exposed)
{
switch (m_floatType)
{
case FloatPropertyChunk.FloatType.Float:
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.Toggle:
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, m_floatType, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.Range:
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, m_floatType, m_rangeValues, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.PowerSlider:
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, m_floatType, m_rangeValues, PropertyChunk.HideState.Visible));
break;
}
}
}
if (!generationMode.IsPreview())
return;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + " " + propertyName + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + ";", true);
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (generationMode.IsPreview())
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_Value + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
public override PreviewProperty GetPreviewProperty()
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
return new PreviewProperty
properties.Add(new PreviewProperty()
m_Name = propertyName,
m_Name = GetVariableNameForNode(),
};
});
}
}
}

47
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs


using System.Collections.Generic;
public class Vector2Node : PropertyNode, IGeneratesBodyCode
public class Vector2Node : AbstractMaterialNode, IGeneratesBodyCode
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Value";
public Vector2Node()
{
name = "Vector2";

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Vector2; }
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public Vector2 value

}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
if (!generationMode.IsPreview())
return;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForNode() + ";", true);
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
public override PreviewProperty GetPreviewProperty()
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
return new PreviewProperty
properties.Add(new PreviewProperty()
m_Name = propertyName,
m_Name = GetVariableNameForNode(),
};
});
}
}
}

47
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector3Node.cs


using System.Collections.Generic;
public class Vector3Node : PropertyNode, IGeneratesBodyCode
public class Vector3Node : AbstractMaterialNode, IGeneratesBodyCode
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Value";
public Vector3Node()
{
name = "Vector3";

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Vector3; }
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public Vector3 value

}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
if (!generationMode.IsPreview())
return;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "3 " + propertyName + ";", true);
visitor.AddShaderChunk(precision + "3 " + GetVariableNameForNode() + ";", true);
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (generationMode.IsPreview())
visitor.AddShaderChunk(precision + "3 " + propertyName + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
public override PreviewProperty GetPreviewProperty()
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
return new PreviewProperty
properties.Add(new PreviewProperty()
m_Name = propertyName,
m_Name = GetVariableNameForNode(),
};
});
}
}
}

43
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector4Node.cs


using System.Collections.Generic;
public class Vector4Node : PropertyNode, IGeneratesBodyCode
public class Vector4Node : AbstractMaterialNode, IGeneratesBodyCode
private const int kOutputSlotId = 0;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Value";
public Vector4Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Vector4; }
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public Vector4 value

}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
if (!generationMode.IsPreview())
return;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + ";", true);
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
if (generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
public override PreviewProperty GetPreviewProperty()
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
return new PreviewProperty
properties.Add(new PreviewProperty()
m_Name = propertyName,
m_Name = GetVariableNameForNode(),
};
});
}
}
}

161
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs


using System.Collections.Generic;
using System;
using System.Linq;
public abstract class PropertyNode : AbstractMaterialNode
[Title("Property Node")]
public class PropertyNode : AbstractMaterialNode
public enum ExposedState
{
Exposed,
NotExposed
}
private Guid m_PropertyGuid;
private string m_Description = string.Empty;
private string m_PropertyGuidSerialized;
public const int OutputSlotId = 0;
public const int ROutputSlotId = 1;
public const int GOutputSlotId = 2;
public const int BOutputSlotId = 3;
public const int AOutputSlotId = 4;
public const int TOutputSlotId = 5;
[SerializeField]
private ExposedState m_Exposed = ExposedState.NotExposed;
public PropertyNode()
{
name = "Property";
UpdateNodeAfterDeserialization();
}
public ExposedState exposedState
private void UpdateNode()
get
var graph = owner as AbstractMaterialGraph;
var property = graph.properties.FirstOrDefault(x => x.guid == propertyGuid);
if (property == null)
return;
if (property is FloatShaderProperty)
{
AddSlot(new MaterialSlot(OutputSlotId, "float", "float", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
else if (property is Vector2ShaderProperty)
if (owner is SubGraph)
return ExposedState.NotExposed;
return m_Exposed;
AddSlot(new MaterialSlot(OutputSlotId, "V2", "V2", SlotType.Output, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
set
else if (property is Vector3ShaderProperty)
if (m_Exposed == value)
return;
m_Exposed = value;
AddSlot(new MaterialSlot(OutputSlotId, "V3", "V3", SlotType.Output, SlotValueType.Vector3, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public string description
{
get
else if (property is Vector4ShaderProperty)
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
AddSlot(new MaterialSlot(OutputSlotId, "V4", "V4", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
else if (property is ColorShaderProperty)
{
AddSlot(new MaterialSlot(OutputSlotId, "Color", "Color", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
else if (property is TextureShaderProperty)
{
AddSlot(new MaterialSlot(OutputSlotId, "RGBA", "RGBA", SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(ROutputSlotId, "R", "R", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(GOutputSlotId, "G", "G", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(BOutputSlotId, "B", "B", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AOutputSlotId, "A", "A", SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(TOutputSlotId, "T", "T", SlotType.Output, SlotValueType.Texture2D, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId, TOutputSlotId});
set { m_Description = value; }
public string propertyName
public Guid propertyGuid
get
get { return m_PropertyGuid; }
set
return string.Format("{0}_{1}_Uniform", name, GetVariableNameForNode());
}
}
if (m_PropertyGuid == value)
return;
public abstract PropertyType propertyType { get; }
var graph = owner as AbstractMaterialGraph;
var property = graph.properties.FirstOrDefault(x => x.guid == value);
if (property == null)
return;
m_PropertyGuid = value;
public abstract PreviewProperty GetPreviewProperty();
UpdateNode();
public override string GetVariableNameForSlot(int slotId)
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
}
}
public sealed override void UpdateNodeAfterDeserialization()
return propertyName;
base.UpdateNodeAfterDeserialization();
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
public override string GetVariableNameForSlot(int slotId)
base.CollectPreviewMaterialProperties(properties);
properties.Add(GetPreviewProperty());
var graph = owner as AbstractMaterialGraph;
var property = graph.properties.FirstOrDefault(x => x.guid == guid);
return property.name;
if (exposedState == ExposedState.NotExposed)
return false;
var graph = owner as AbstractMaterialGraph;
var propNodes = owner.GetNodes<PropertyNode>();
foreach (var n in propNodes)
{
if (n == this || n.exposedState == ExposedState.NotExposed)
continue;
if (!graph.properties.Any(x => x.guid == guid))
return true;
if (n.propertyName == propertyName)
{
return true;
}
}
/*
public override float GetNodeUIHeight(float width)
public override void OnBeforeSerialize()
return 2 * EditorGUIUtility.singleLineHeight;
base.OnBeforeSerialize();
m_PropertyGuidSerialized = m_PropertyGuid.ToString();
public override bool OnGUI()
public override void OnAfterDeserialize()
EditorGUI.BeginChangeCheck();
m_Exposed = EditorGUILayout.Toggle("Exposed Property", m_Exposed);
if (m_Exposed)
m_PropertyName = EditorGUILayout.DelayedTextField("Property Name", m_PropertyName);
var modified = EditorGUI.EndChangeCheck();
if (modified)
{
owner.ValidateGraph();
}
if (m_Exposed)
m_Description = EditorGUILayout.TextField("Description", m_Description);
base.OnAfterDeserialize();
if (!string.IsNullOrEmpty(m_PropertyGuidSerialized))
m_PropertyGuid = new Guid(m_PropertyGuidSerialized);
}
modified |= base.OnGUI();
return modified;
}*/
}
}

12
MaterialGraphProject/Assets/NewNodes/Keep/Texture2DNode.cs.meta


fileFormatVersion: 2
guid: 9def76d530f56804b9f696a9b36eccfa
timeCreated: 1500545522
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

137
MaterialGraphProject/Assets/NewNodes/Keep/Texture2DNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Texture Asset")]
public class Texture2DNode : PropertyNode
{
protected const string textureName = "Texture";
public const int textureID = 0;
[SerializeField]
private string m_SerializedTexture;
[SerializeField]
private TextureType m_TextureType;
[Serializable]
private class TextureHelper
{
public Texture texture;
}
public override bool hasPreview { get { return false; } }
#if UNITY_EDITOR
public Texture defaultTexture
{
get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
}
set
{
if (defaultTexture == value)
return;
var tex = new TextureHelper();
tex.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
public Texture defaultTexture {get; set; }
#endif
public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public Texture2DNode()
{
name = "Texture2D";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(textureID, textureName, textureName, SlotType.Output, SlotValueType.Texture2D, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { textureID }; }
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
var slotTexture2D = FindOutputSlot<MaterialSlot>(0);
if (slotTexture2D != null)
{
visitor.AddShaderChunk("UNITY_DECLARE_TEX2D(" + propertyName + ");", true);
}
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs.meta


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs.meta


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

104
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Scene Data/Depth Texture")]
public class DepthTextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "UV";
protected const string kOutputSlotName = "Output";
public const int UvSlotId = 0;
public const int OutputSlotId = 1;
public override bool hasPreview { get { return true; } }
public Texture defaultTexture { get; set; }
public DepthTextureNode()
{
name = "DepthTexture";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, UvSlotId }; }
}
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
string body = "tex2D (_CameraDepthTexture, " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D _CameraDepthTexture;", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}

104
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Scene Data/Motion Vector Texture")]
public class MotionVectorTextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "UV";
protected const string kOutputSlotName = "Output";
public const int UvSlotId = 0;
public const int OutputSlotId = 1;
public override bool hasPreview { get { return true; } }
public Texture defaultTexture { get; set; }
public MotionVectorTextureNode()
{
name = "MotionVectorTexture";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, UvSlotId }; }
}
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
string body = "tex2D (_CameraMotionVectorTexture, " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D _CameraMotionVectorTexture;", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}
正在加载...
取消
保存