浏览代码

Add flexibility to splitnode

/main
Florent Guinier 8 年前
当前提交
dd853ee2
共有 1 个文件被更改,包括 30 次插入57 次删除
  1. 87
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs

87
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Channel/Split")]
public class SplitNode : PropertyNode, IGeneratesBodyCode
public class SplitNode : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlotName = "Input";
protected const string kOutputSlotRName = "R";

get { return new[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, OutputSlotRGBId, OutputSlotRGId }; }
}
[SerializeField]
private Vector4 m_Value;
public Vector4 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public override PropertyType propertyType { get { return PropertyType.Vector4; } }
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
}
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
var inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false);
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotRGBId, OutputSlotRGId });
string inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision +"4 "+ GetVariableNameForNode() + " = " + GetNodeBody(inputValue) + ";", true);
protected virtual MaterialSlot GetInputSlot()
protected string GetNodeBody(string inputValue)
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
string[] channelNames = { "r", "g", "b", "a" };
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId);
if (inputSlot == null)
return "1.0";
protected virtual string GetInputSlotName() { return "Input"; }
int numInputChannels = (int)inputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
string outputString = precision + "4(";
if (numInputChannels == 0)
{
outputString += "1.0, 1.0, 1.0, 1.0)";
}
else
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
//float4(arg1, 1.0, 1.0)
outputString += inputValue;
for (int i = numInputChannels; i < 4; i++)
{
outputString += ", 1.0";
}
outputString += ")";
}
return outputString;
{
{
string slotOutput;
switch (slotId)
{

slotOutput = "";
break;
}
return propertyName + slotOutput;
//return GetVariableNameForNode() + slotOutput;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
return GetVariableNameForNode() + slotOutput;
}
}
}
正在加载...
取消
保存