浏览代码

Add support for Fixed gradient mode

/main
Matt Dean 7 年前
当前提交
15328c1d
共有 5 个文件被更改,包括 26 次插入24 次删除
  1. 2
      com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs
  2. 5
      com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/GradientAssetNode.cs
  3. 22
      com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/SampleGradientNode.cs
  4. 12
      com.unity.shadergraph/Editor/Drawing/Controls/GradientControl.cs
  5. 9
      com.unity.shadergraph/Editor/Drawing/Views/Slots/GradientSlotControlView.cs

2
com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs


props.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("{0}_Type", name),
floatValue = 0
floatValue = (int)value.mode
});
props.Add(new PreviewProperty(PropertyType.Vector1)

5
com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/GradientAssetNode.cs


[SerializeField]
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) };
[SerializeField]
int m_SerializableMode = 0;
[GradientControl("")]
public Gradient gradient
{

m_SerializableAlphaKeys = null;
m_SerializableColorKeys = null;
m_Gradient.SetKeys(colorKeys, alphaKeys);
m_Gradient.mode = (GradientMode)m_SerializableMode;
}
public override void OnBeforeSerialize()

m_SerializableAlphaKeys = gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
m_SerializableMode = (int)gradient.mode;
}
public override bool hasPreview { get { return false; } }

22
com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/SampleGradientNode.cs


else
break;
}
float colorPos = min(1, max(0, (Time - Gradient.colors[colorKey1].w) / (Gradient.colors[colorKey2].w - Gradient.colors[colorKey1].w)));
float3 color = lerp(Gradient.colors[colorKey1].rgb, Gradient.colors[colorKey2].rgb, colorPos);
float alphaPos = min(1, max(0, (Time - Gradient.alphas[alphaKey1].y) / (Gradient.alphas[alphaKey2].y - Gradient.alphas[alphaKey1].y)));
float alpha = lerp(Gradient.alphas[alphaKey1].r, Gradient.alphas[alphaKey2].r, alphaPos);
Out = float4(color, alpha);
if(Gradient.type == 1)
{
float colorPos = min(1, max(0, (Time - Gradient.colors[colorKey1].w) / (Gradient.colors[colorKey2].w - Gradient.colors[colorKey1].w)));
float3 color = lerp(Gradient.colors[colorKey1].rgb, Gradient.colors[colorKey2].rgb, step(0.01, colorPos));
float alphaPos = min(1, max(0, (Time - Gradient.alphas[alphaKey1].y) / (Gradient.alphas[alphaKey2].y - Gradient.alphas[alphaKey1].y)));
float alpha = lerp(Gradient.alphas[alphaKey1].r, Gradient.alphas[alphaKey2].r, step(0.01, alphaPos));
Out = float4(color, alpha);
}
else
{
float colorPos = min(1, max(0, (Time - Gradient.colors[colorKey1].w) / (Gradient.colors[colorKey2].w - Gradient.colors[colorKey1].w)));
float3 color = lerp(Gradient.colors[colorKey1].rgb, Gradient.colors[colorKey2].rgb, colorPos);
float alphaPos = min(1, max(0, (Time - Gradient.alphas[alphaKey1].y) / (Gradient.alphas[alphaKey2].y - Gradient.alphas[alphaKey1].y)));
float alpha = lerp(Gradient.alphas[alphaKey1].r, Gradient.alphas[alphaKey2].r, alphaPos);
Out = float4(color, alpha);
}
}
";
}

12
com.unity.shadergraph/Editor/Drawing/Controls/GradientControl.cs


PropertyInfo m_PropertyInfo;
string m_PrevWindow = "";
[SerializeField]
GradientObject m_GradientObject;

m_SerializedObject.Update();
var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null);
m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
m_GradientObject.gradient.mode = gradient.mode;
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{

{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
Dirty(ChangeType.Repaint);
}
var e = Event.current;
if (EditorWindow.focusedWindow != null && m_PrevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
m_PrevWindow = EditorWindow.focusedWindow.ToString();
}
}
}

9
com.unity.shadergraph/Editor/Drawing/Views/Slots/GradientSlotControlView.cs


public class GradientSlotControlView : VisualElement, INodeModificationListener
{
GradientInputMaterialSlot m_Slot;
string m_PrevWindow = "";
[SerializeField]
GradientObject m_GradientObject;

{
m_SerializedObject.Update();
m_GradientObject.gradient.SetKeys(m_Slot.value.colorKeys, m_Slot.value.alphaKeys);
m_GradientObject.gradient.mode = m_Slot.value.mode;
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{

m_Slot.owner.Dirty(ModificationScope.Node);
m_Container.Dirty(ChangeType.Repaint);
}
}
var e = Event.current;
if (EditorWindow.focusedWindow != null && m_PrevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
m_PrevWindow = EditorWindow.focusedWindow.ToString();
}
}
}
正在加载...
取消
保存