浏览代码

Adding constants node and corresponding presenter Adding Negate Node Adding UVPanner Node

/main
Eduardo Chaves 8 年前
当前提交
dd8a892c
共有 12 个文件被更改,包括 293 次插入0 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 11
      MaterialGraphProject/Assets/Eduardo/ConstantType.cs
  3. 12
      MaterialGraphProject/Assets/Eduardo/ConstantType.cs.meta
  4. 73
      MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs
  5. 12
      MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs.meta
  6. 51
      MaterialGraphProject/Assets/Eduardo/ConstantsNodePresenter.cs
  7. 12
      MaterialGraphProject/Assets/Eduardo/ConstantsNodePresenter.cs.meta
  8. 29
      MaterialGraphProject/Assets/Eduardo/NegateNode.cs
  9. 12
      MaterialGraphProject/Assets/Eduardo/NegateNode.cs.meta
  10. 68
      MaterialGraphProject/Assets/Eduardo/PannerNode.cs
  11. 12
      MaterialGraphProject/Assets/Eduardo/PannerNode.cs.meta

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


typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterPresenter);
typeMapper[typeof(LevelNode)] = typeof(LevelNodePresenter);
typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
}
}
}

11
MaterialGraphProject/Assets/Eduardo/ConstantType.cs


namespace UnityEngine.MaterialGraph
{
public enum ConstantType
{
PI,
TAU,
PHI,
E,
SQRT2
};
}

12
MaterialGraphProject/Assets/Eduardo/ConstantType.cs.meta


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

73
MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs


using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Constants")]
public class ConstantsNode : PropertyNode, IGeneratesBodyCode
{
static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},
{ConstantType.SQRT2, 1.414214f},
};
[SerializeField]
private ConstantType m_constant = ConstantType.PI;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Constant";
public ConstantType constant
{
get { return m_constant; }
set
{
if (m_constant == value)
return;
m_constant = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public ConstantsNode()
{
name = "MathConstant";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero, false));
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]
};
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_constantList[constant] + ";", true);
}
}
}

12
MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs.meta


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

51
MaterialGraphProject/Assets/Eduardo/ConstantsNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ConstantsContolPresenter : GraphControlPresenter
{
private string[] m_ConstantTypeNames;
private string[] constantTypeNames
{
get
{
if (m_ConstantTypeNames == null)
m_ConstantTypeNames = Enum.GetNames(typeof(ConstantType));
return m_ConstantTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ConstantsNode;
if (cNode == null)
return;
cNode.constant = (ConstantType)EditorGUILayout.Popup((int)cNode.constant, constantTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ConstantsNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<ConstantsContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/Eduardo/ConstantsNodePresenter.cs.meta


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

29
MaterialGraphProject/Assets/Eduardo/NegateNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Negate")]
public class NegateNode : Function1Input, IGeneratesFunction
{
public NegateNode()
{
name = "Negate";
}
protected override string GetFunctionName()
{
return "unity_negate_" + precision;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return -1 * arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/Eduardo/NegateNode.cs.meta


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

68
MaterialGraphProject/Assets/Eduardo/PannerNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Panner")]
public class PannerNode : Function3Input, IGeneratesFunction
{
public PannerNode()
{
name = "Panner";
}
protected override string GetFunctionName()
{
return "unity_pan_" + precision;
}
protected override string GetInputSlot1Name()
{
return "UV";
}
protected override string GetInputSlot2Name()
{
return "HorizontalOffset";
}
protected override string GetInputSlot3Name()
{
return "VerticalOffset";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector4.zero);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector2, Vector2.zero);
}
public override bool hasPreview
{
get { return true; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("UV", "HorizontalOffset", "VerticalOffset"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return float2(UV.x + HorizontalOffset, UV.y + VerticalOffset);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/Eduardo/PannerNode.cs.meta


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