浏览代码

Added a procedural box node and made a few changes to the inputs of the pulse node.

/main
bfogerty 8 年前
当前提交
f0331f23
共有 3 个文件被更改,包括 86 次插入16 次删除
  1. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/PulseNode.cs
  2. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/BoxNode.cs
  3. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/BoxNode.cs.meta

22
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/PulseNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Pulse")]
public class PulseNode : Function3Input, IGeneratesFunction
public class PulseNode : Function2Input, IGeneratesFunction
{
public PulseNode()
{

protected override string GetInputSlot1Name()
{
return "Value";
return "X Value";
return "MinValue";
}
protected override string GetInputSlot3Name()
{
return "MaxValue";
return "X Min and Max";
}
protected override MaterialSlot GetInputSlot1()

protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override MaterialSlot GetOutputSlot()

public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("value", "minValue", "maxValue"), false);
outputString.AddShaderChunk(GetFunctionPrototype("xValue", "xMinAndMax"), false);
outputString.AddShaderChunk("return step( minValue, value ) - step( maxValue, value );", false);
outputString.AddShaderChunk("return step( xMinAndMax.x, xValue ) - step( xMinAndMax.y, xValue );", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

68
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/BoxNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Box")]
public class BoxNode : Function3Input, IGeneratesFunction
{
public BoxNode()
{
name = "Box";
}
protected override string GetFunctionName()
{
return "unity_boxnode_" + precision;
}
protected override string GetInputSlot1Name()
{
return "X and Y";
}
protected override string GetInputSlot2Name()
{
return "X Min and Max";
}
protected override string GetInputSlot3Name()
{
return "Y Min and Max";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector3.zero);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector3.zero);
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector1, Vector2.zero);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("xy", "xMinAndMax", "yMinAndMax"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float x = step( xMinAndMax.x, xy.x ) - step( xMinAndMax.y, xy.x );", false);
outputString.AddShaderChunk("float y = step( yMinAndMax.x, xy.y ) - step( yMinAndMax.y, xy.y );", false);
outputString.AddShaderChunk("return x * y;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/BoxNode.cs.meta


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