浏览代码

Rename ColorMaterialSlot > ColorRGBAMaterialSlot and add ColorRGB slot

/main
Matt Dean 7 年前
当前提交
00d8b6e8
共有 11 个文件被更改,包括 104 次插入17 次删除
  1. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorMaterialSlot.cs
  2. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ReplaceColorNode.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs
  4. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
  5. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Procedural/CheckerboardNode.cs
  6. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorSlotControlView.cs
  7. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  8. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorRGBMaterialSlot.cs
  9. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorRGBMaterialSlot.cs.meta
  10. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorRGBSlotControlView.cs
  11. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorRGBSlotControlView.cs.meta

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorMaterialSlot.cs


namespace UnityEditor.ShaderGraph
{
public class ColorMaterialSlot : Vector4MaterialSlot
public class ColorRGBAMaterialSlot : Vector4MaterialSlot
public ColorMaterialSlot() {}
public ColorRGBAMaterialSlot() {}
public ColorMaterialSlot(
public ColorRGBAMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,

public override VisualElement InstantiateControl()
{
return new ColorSlotControlView(this);
return new ColorRGBASlotControlView(this);
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ReplaceColorNode.cs


static string Unity_ReplaceColor(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Color From,
[Slot(2, Binding.None)] Color To,
[Slot(1, Binding.None)] ColorRGB From,
[Slot(2, Binding.None)] ColorRGB To,
[Slot(3, Binding.None)] Vector1 Range,
[Slot(4, Binding.None)] out Vector3 Out)
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs


static string Unity_ColorMask(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Color MaskColor,
[Slot(1, Binding.None)] ColorRGB MaskColor,
[Slot(2, Binding.None)] Vector1 Range,
[Slot(3, Binding.None)] out Vector3 Out)
{

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs


protected abstract MethodInfo GetFunctionToConvert();
public class ColorRGBA { };
public class ColorRGB { };
private static SlotValueType ConvertTypeToSlotValueType(ParameterInfo p)
{
Type t = p.ParameterType;

return SlotValueType.Vector4;
}
if (t == typeof(Color))
{
return SlotValueType.Vector4;
}
if (t == typeof(ColorRGBA))
{
return SlotValueType.Vector4;
}
if (t == typeof(ColorRGB))
{
return SlotValueType.Vector4;
}

MaterialSlot s;
if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(Color))
s = new ColorMaterialSlot(attribute.slotId, par.Name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden);
s = new ColorRGBAMaterialSlot(attribute.slotId, par.Name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden);
else if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(ColorRGBA))
s = new ColorRGBAMaterialSlot(attribute.slotId, par.Name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden);
else if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(ColorRGB))
s = new ColorRGBMaterialSlot(attribute.slotId, par.Name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector3.zero, hidden: attribute.hidden);
else if (attribute.binding == Binding.None || par.IsOut)
s = MaterialSlot.CreateMaterialSlot(
ConvertTypeToSlotValueType(par),

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Procedural/CheckerboardNode.cs


static string Unity_Checkerboard(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 0.2f, 0.2f, 0.2f, 1f)] Color ColorA,
[Slot(2, Binding.None, 0.7f, 0.7f, 0.7f, 1f)] Color ColorB,
[Slot(1, Binding.None, 0.2f, 0.2f, 0.2f, 1f)] ColorRGB ColorA,
[Slot(2, Binding.None, 0.7f, 0.7f, 0.7f, 1f)] ColorRGB ColorB,
[Slot(4, Binding.None)] out Vector4 Out)
[Slot(4, Binding.None)] out Vector3 Out)
{
Out = Vector2.zero;
return

{precision}2 blend_out = saturate(scale / 3);
{precision}2 vector_alpha = clamp(distance3 * scale.xy * blend_out.xy, -1.0, 1.0);
{precision} alpha = saturate(vector_alpha.x * vector_alpha.y);
Out = lerp(ColorA, ColorB, alpha.xxxx);
Out = lerp(ColorA, ColorB, alpha.xxx);
}";
}
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorSlotControlView.cs


namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class ColorSlotControlView : VisualElement
public class ColorRGBASlotControlView : VisualElement
ColorMaterialSlot m_Slot;
ColorRGBAMaterialSlot m_Slot;
public ColorSlotControlView(ColorMaterialSlot slot)
public ColorRGBASlotControlView(ColorRGBAMaterialSlot slot)
{
m_Slot = slot;
var colorField = new ColorField { value = slot.value };

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


width: 40;
}
ColorSlotControlView {
ColorRGBASlotControlView {
flex-direction: row;
align-items: center;
}
ColorRGBASlotControlView > ColorField {
width: 50;
}
ColorRGBSlotControlView {
ColorSlotControlView > ColorField {
ColorRGBSlotControlView > ColorField {
width: 50;
}

29
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorRGBMaterialSlot.cs


using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{
public class ColorRGBMaterialSlot : Vector3MaterialSlot
{
public ColorRGBMaterialSlot() {}
public ColorRGBMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, value, shaderStage, hidden)
{
}
public override VisualElement InstantiateControl()
{
return new ColorRGBSlotControlView(this);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorRGBMaterialSlot.cs.meta


fileFormatVersion: 2
guid: a29c1f6321a430d439c5623e2a44f397
timeCreated: 1510659340

28
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorRGBSlotControlView.cs


using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class ColorRGBSlotControlView : VisualElement
{
ColorRGBMaterialSlot m_Slot;
public ColorRGBSlotControlView(ColorRGBMaterialSlot slot)
{
m_Slot = slot;
var colorField = new ColorField { value = new Color(slot.value.x, slot.value.y, slot.value.z, 0), showAlpha = false };
colorField.OnValueChanged(OnValueChanged);
Add(colorField);
}
void OnValueChanged(ChangeEvent<Color> evt)
{
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Color Change");
m_Slot.value = new Vector3(evt.newValue.r, evt.newValue.g, evt.newValue.b);
if (m_Slot.owner.onModified != null)
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/ColorRGBSlotControlView.cs.meta


fileFormatVersion: 2
guid: a184620cc50fd2e40a845d6ebb39529e
timeCreated: 1510659384
正在加载...
取消
保存