浏览代码

Gradient node bug-fix and RGBA

/main
MingWai 8 年前
当前提交
7d5a2883
共有 2 个文件被更改,包括 16 次插入16 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GradientNodePresenter.cs
  2. 29
      MaterialGraphProject/Assets/_MingWai/GradientNode.cs

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GradientNodePresenter.cs


Event e = Event.current;
if (prevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
if (EditorWindow.focusedWindow != null && prevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
cNode.UpdateGradient();
prevWindow = EditorWindow.focusedWindow.ToString();

29
MaterialGraphProject/Assets/_MingWai/GradientNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Gradient Editor")]
public class GradientNode : Function1Input, IGeneratesFunction
public class GradientNode : FunctionNInNOut, IGeneratesFunction
{
[SerializeField]
private Gradient m_gradient;

public GradientNode()
{
name = "Gradient";
AddSlot("Value", "v", Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.one);
AddSlot("RGBA", "finalColor", Graphing.SlotType.Output, SlotValueType.Vector4, Vector4.zero);
AddSlot("R", "finalR", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("G", "finalG", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("B", "finalB", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("A", "finalA", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
UpdateNodeAfterDeserialization();
}

}
protected override string GetInputSlotName()
public override bool hasPreview
return "Value";
get { return true; }
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector4, Vector2.zero);
}
private void GNF(ShaderGenerator visitor, GenerationMode generationMode)
{

//Start
outputString.AddShaderChunk(GetFunctionPrototype("v"), false);
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();

//Result
outputString.AddShaderChunk("return float4(gradcolor,gradalpha);", false);
outputString.AddShaderChunk("finalColor = float4(gradcolor,gradalpha);", false);
outputString.AddShaderChunk("finalR = finalColor.r;", false);
outputString.AddShaderChunk("finalG = finalColor.g;", false);
outputString.AddShaderChunk("finalB = finalColor.b;", false);
outputString.AddShaderChunk("finalA = finalColor.a;", false);
//End

正在加载...
取消
保存