浏览代码

Add pre-split to TextureSamplerNode (#60)

/main
Peter Bay Bastian 7 年前
当前提交
65d3639a
共有 1 个文件被更改,包括 27 次插入10 次删除
  1. 37
      MaterialGraphProject/Assets/NewNodes/Keep/TextureSamplerNode.cs

37
MaterialGraphProject/Assets/NewNodes/Keep/TextureSamplerNode.cs


[Title("Texture/Sample 2D")]
public class Sample2DTexture : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotId = 0;
public const int OutputSlotRGBAId = 0;
public const int OutputSlotRId = 4;
public const int OutputSlotGId = 5;
public const int OutputSlotBId = 6;
public const int OutputSlotAId = 7;
private const string kOutputSlotName = "rgba";
private const string kTextureInputName = "Tex";
private const string kUVInputName = "UV";
private const string kSamplerInputName = "Sampler";
const string kOutputSlotRGBAName = "RGBA";
const string kOutputSlotRName = "R";
const string kOutputSlotGName = "G";
const string kOutputSlotBName = "B";
const string kOutputSlotAName = "A";
const string kTextureInputName = "Tex";
const string kUVInputName = "UV";
const string kSamplerInputName = "Sampler";
public override bool hasPreview { get { return true; } }

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, TextureInputId, UVInput, SamplerInput });
RemoveSlotsNameNotMatching(new[] { OutputSlotRGBAId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, TextureInputId, UVInput, SamplerInput });
}
// Node generations

// if no texture connected return nothing
if (!edgesTexture.Any())
{
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + precision + "4(0,0,0,0);", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotRGBAId) + " = " + precision + "4(0,0,0,0);", true);
return;
}

{0}4 {1} = UNITY_SAMPLE_TEX2D({2}, {4});
#endif"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForSlot(OutputSlotRGBAId)
, GetSlotValue(TextureInputId, generationMode)
, GetSlotValue(SamplerInput, generationMode)
, uvName);

result = string.Format("{0}4 {1} = UNITY_SAMPLE_TEX2D({2},{3});"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForSlot(OutputSlotRGBAId)
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.r;", precision, GetVariableNameForSlot(OutputSlotRId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.g;", precision, GetVariableNameForSlot(OutputSlotGId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.b;", precision, GetVariableNameForSlot(OutputSlotBId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.a;", precision, GetVariableNameForSlot(OutputSlotAId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
}
public bool RequiresMeshUV(UVChannel channel)

正在加载...
取消
保存