浏览代码

Texture Asset Node supports output for Texture2D AND sampler2D

/main
vlad 8 年前
当前提交
107ba5ee
共有 1 个文件被更改,包括 28 次插入7 次删除
  1. 35
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs

35
MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs


[Title("Input/Texture/Texture Asset")]
public class TextureAssetNode : PropertyNode
{
protected const string kOutputSlotRGBAName = "Texture";
protected const string outputTexture2D_name = "Texture2D";
protected const string outputSampler2D_name = "Sampler2D";
public const int OutputSlotRgbaId = 0;
public const int outputTexture2D_id = 0;
public const int outputSampler2D_id = 1;
[SerializeField]
private string m_SerializedTexture;

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Texture2D, Vector4.zero, false));
AddSlot(new MaterialSlot(outputTexture2D_id, outputTexture2D_name, outputTexture2D_name, SlotType.Output, SlotValueType.Texture2D, Vector4.zero, false));
AddSlot(new MaterialSlot(outputSampler2D_id, outputSampler2D_name, outputSampler2D_name, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero, false));
get { return new[] { OutputSlotRgbaId }; }
get { return new[] { outputTexture2D_id, outputSampler2D_id }; }
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)

public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true);
visitor.AddShaderChunk("Texture2D " + propertyName + ";", true);
visitor.AddShaderChunk("#endif", true);
var slotTexture2D = FindInputSlot<MaterialSlot>(0);
if (slotTexture2D != null)
{
var edgesTexture2D = owner.GetEdges(slotTexture2D.slotReference).ToList();
if (edgesTexture2D.Count > 0)
{
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true);
visitor.AddShaderChunk("Texture2D " + propertyName + "_T2D;", true);
visitor.AddShaderChunk("#endif", true);
}
}
var slotSampler2D = FindInputSlot<MaterialSlot>(0);
if (slotSampler2D != null)
{
var edgesSampler2D = owner.GetEdges(slotTexture2D.slotReference).ToList();
if (edgesSampler2D.Count > 0)
{
visitor.AddShaderChunk("Sampler2D " + propertyName + "_S2D;", true);
}
}
}

正在加载...
取消
保存