浏览代码

Merge pull request #293 from Unity-Technologies/vector-input-fields

Vector input fields and IMayRequirePosition
/main
GitHub 7 年前
当前提交
eae8c0fc
共有 24 个文件被更改,包括 168 次插入242 次删除
  1. 2
      com.unity.shadergraph/Editor/Data/Graphs/ColorMaterialSlot.cs
  2. 2
      com.unity.shadergraph/Editor/Data/Graphs/ColorRGBMaterialSlot.cs
  3. 12
      com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs
  4. 11
      com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  5. 8
      com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs
  6. 2
      com.unity.shadergraph/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs
  7. 2
      com.unity.shadergraph/Editor/Data/Graphs/SpaceMaterialSlot.cs
  8. 2
      com.unity.shadergraph/Editor/Data/Graphs/UVMaterialSlot.cs
  9. 10
      com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs
  10. 4
      com.unity.shadergraph/Editor/Data/Graphs/Vector1ShaderProperty.cs
  11. 11
      com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs
  12. 7
      com.unity.shadergraph/Editor/Data/Graphs/Vector2ShaderProperty.cs
  13. 8
      com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs
  14. 8
      com.unity.shadergraph/Editor/Data/Graphs/Vector3ShaderProperty.cs
  15. 9
      com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs
  16. 7
      com.unity.shadergraph/Editor/Data/Graphs/Vector4ShaderProperty.cs
  17. 2
      com.unity.shadergraph/Editor/Data/Graphs/VertexColorMaterialSlot.cs
  18. 2
      com.unity.shadergraph/Editor/Data/Interfaces/IMayRequirePosition.cs
  19. 54
      com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector1Node.cs
  20. 73
      com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector2Node.cs
  21. 78
      com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector3Node.cs
  22. 83
      com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector4Node.cs
  23. 2
      com.unity.shadergraph/Editor/Data/Nodes/SlotValue.cs
  24. 11
      com.unity.shadergraph/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs

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


Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, value, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, value, shaderStage, hidden: hidden)
{
}

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


Color value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, (Vector4)value, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, (Vector4)value, shaderStage, hidden: hidden)
{
}

12
com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs


using System;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

[SerializeField]
private Matrix4x4 m_DefaultValue;
static readonly string[] k_Labels = {"X", "Y", "Z", "W"};
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4;

public override VisualElement InstantiateControl()
{
int components =
concreteValueType == ConcreteSlotValueType.Vector4 ? 4 :
concreteValueType == ConcreteSlotValueType.Vector3 ? 3 :
concreteValueType == ConcreteSlotValueType.Vector2 ? 2 :
concreteValueType == ConcreteSlotValueType.Vector1 ? 1 : 0;
return new MultiFloatSlotControlView(owner, components, () => value.GetRow(0), (newValue) => value = new Matrix4x4(newValue, value.GetRow(1), value.GetRow(2), value.GetRow(3)));
var labels = k_Labels.Take(concreteValueType.GetChannelCount()).ToArray();
return new MultiFloatSlotControlView(owner, labels, () => value.GetRow(0), (newValue) => value = new Matrix4x4(newValue, value.GetRow(1), value.GetRow(2), value.GetRow(3)));
}
public override SlotValueType valueType { get { return SlotValueType.Dynamic; } }

11
com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


using System;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;

[SerializeField]
private Vector4 m_DefaultValue;
static readonly string[] k_Labels = {"X", "Y", "Z", "W"};
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4;

public override VisualElement InstantiateControl()
{
int components =
concreteValueType == ConcreteSlotValueType.Vector4 ? 4 :
concreteValueType == ConcreteSlotValueType.Vector3 ? 3 :
concreteValueType == ConcreteSlotValueType.Vector2 ? 2 :
concreteValueType == ConcreteSlotValueType.Vector1 ? 1 : 0;
return new MultiFloatSlotControlView(owner, components, () => value, (newValue) => value = newValue);
var labels = k_Labels.Take(concreteValueType.GetChannelCount()).ToArray();
return new MultiFloatSlotControlView(owner, labels, () => value, (newValue) => value = newValue);
}
public override SlotValueType valueType { get { return SlotValueType.DynamicVector; } }

8
com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs


case SlotValueType.DynamicVector:
return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector4:
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden);
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden: hidden);
case SlotValueType.Dynamic:
return new DynamicValueMaterialSlot(slotId, displayName, shaderOutputName, slotType, new Matrix4x4(defaultValue, Vector4.zero, Vector4.zero, Vector4.zero), shaderStage, hidden);
case SlotValueType.Boolean:

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


public ScreenPositionMaterialSlot(int slotId, string displayName, string shaderOutputName, ScreenSpaceType screenSpaceType,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
{
this.screenSpaceType = screenSpaceType;
}

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


protected SpaceMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
{
this.space = space;
}

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


public UVMaterialSlot(int slotId, string displayName, string shaderOutputName, UVChannel channel,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, shaderStage, hidden: hidden)
{
this.channel = channel;
}

10
com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs


public class Vector1MaterialSlot : MaterialSlot, IMaterialSlotHasValue<float>
{
[SerializeField]
private float m_Value;
float m_Value;
private float m_DefaultValue;
float m_DefaultValue;
string[] m_Labels;
public Vector1MaterialSlot()
{}

SlotType slotType,
float value,
ShaderStage shaderStage = ShaderStage.Dynamic,
string label1 = "X",
m_Labels = new[] { label1 };
}
public float defaultValue { get { return m_DefaultValue; } }

public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 1, () => new Vector4(value, 0f, 0f, 0f), (newValue) => value = newValue.x);
return new MultiFloatSlotControlView(owner, m_Labels, () => new Vector4(value, 0f, 0f, 0f), (newValue) => value = newValue.x);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

4
com.unity.shadergraph/Editor/Data/Graphs/Vector1ShaderProperty.cs


case FloatType.Integer:
return new IntegerNode { value = (int)value };
default:
return new Vector1Node { value = value };
var node = new Vector1Node();
node.FindInputSlot<Vector1MaterialSlot>(Vector1Node.InputSlotXId).value = value;
return node;
}
}
}

11
com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs


public class Vector2MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Vector2>
{
[SerializeField]
private Vector2 m_Value;
Vector2 m_Value;
private Vector2 m_DefaultValue;
Vector2 m_DefaultValue;
string[] m_Labels;
public Vector2MaterialSlot()
{}

SlotType slotType,
Vector2 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
string label1 = "X",
string label2 = "Y",
m_Labels = new[] { label1, label2 };
}
public Vector2 defaultValue { get { return m_DefaultValue; } }

public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 2, () => value, (newValue) => value = newValue);
return new MultiFloatSlotControlView(owner, m_Labels, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

7
com.unity.shadergraph/Editor/Data/Graphs/Vector2ShaderProperty.cs


{
get { return new Vector4(value.x, value.y, 0, 0); }
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("float2 {0}{1}", referenceName, delimiter);

public override INode ToConcreteNode()
{
return new Vector2Node { value = value };
var node = new Vector2Node();
node.FindInputSlot<Vector1MaterialSlot>(Vector2Node.InputSlotXId).value = value.x;
node.FindInputSlot<Vector1MaterialSlot>(Vector2Node.InputSlotYId).value = value.y;
return node;
}
}
}

8
com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs


[SerializeField]
private Vector3 m_DefaultValue;
string[] m_Labels;
public Vector3MaterialSlot()
{
}

SlotType slotType,
Vector3 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
string label1 = "X",
string label2 = "Y",
string label3 = "Z",
m_Labels = new[] { label1, label2, label3 };
}
public Vector3 defaultValue { get { return m_DefaultValue; } }

public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 3, () => value, (newValue) => value = newValue);
return new MultiFloatSlotControlView(owner, m_Labels, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

8
com.unity.shadergraph/Editor/Data/Graphs/Vector3ShaderProperty.cs


{
get { return new Vector4(value.x, value.y, value.z, 0); }
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("float3 {0}{1}", referenceName, delimiter);

public override INode ToConcreteNode()
{
return new Vector3Node { value = value };
var node = new Vector3Node();
node.FindInputSlot<Vector1MaterialSlot>(Vector3Node.InputSlotXId).value = value.x;
node.FindInputSlot<Vector1MaterialSlot>(Vector3Node.InputSlotYId).value = value.y;
node.FindInputSlot<Vector1MaterialSlot>(Vector3Node.InputSlotZId).value = value.z;
return node;
}
}
}

9
com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs


[SerializeField]
private Vector4 m_DefaultValue;
string[] m_Labels;
public Vector4MaterialSlot()
{
}

SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
string label1 = "X",
string label2 = "Y",
string label3 = "Z",
string label4 = "W",
m_Labels = new[] { label1, label2, label3, label4 };
}
public Vector4 defaultValue { get { return m_DefaultValue; } }

public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 4, () => value, (newValue) => value = newValue);
return new MultiFloatSlotControlView(owner, m_Labels, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

7
com.unity.shadergraph/Editor/Data/Graphs/Vector4ShaderProperty.cs


public override INode ToConcreteNode()
{
return new Vector4Node { value = value };
var node = new Vector4Node();
node.FindInputSlot<Vector1MaterialSlot>(Vector4Node.InputSlotXId).value = value.x;
node.FindInputSlot<Vector1MaterialSlot>(Vector4Node.InputSlotYId).value = value.y;
node.FindInputSlot<Vector1MaterialSlot>(Vector4Node.InputSlotZId).value = value.z;
node.FindInputSlot<Vector1MaterialSlot>(Vector4Node.InputSlotWId).value = value.w;
return node;
}
}
}

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


{
public VertexColorMaterialSlot(int slotId, string displayName, string shaderOutputName,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
{}
public override VisualElement InstantiateControl()

2
com.unity.shadergraph/Editor/Data/Interfaces/IMayRequirePosition.cs


namespace UnityEditor.ShaderGraph
{
interface IMayRequirePosition
public interface IMayRequirePosition
{
NeededCoordinateSpace RequiresPosition();
}

54
com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector1Node.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;

[SerializeField]
private float m_Value;
const string kInputSlotXName = "X";
const string kOutputSlotName = "Out";
public const int InputSlotXId = 1;
private const string kOutputSlotName = "Out";
public Vector1Node()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public float value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value
});
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId });
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + NodeUtils.FloatToShaderValue(m_Value) + ";", true);
var inputValue = GetSlotValue(InputSlotXId, generationMode);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + inputValue + ";", false);
}
public override string GetVariableNameForSlot(int slotId)

public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = GetVariableNameForNode(),
floatValue = m_Value
});
}
return new Vector1ShaderProperty { value = value };
var slot = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
return new Vector1ShaderProperty { value = slot.value };
public int outputSlotId { get { return OutputSlotId; } }
int IPropertyFromNode.outputSlotId { get { return OutputSlotId; } }
}
}

73
com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector2Node.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;

{
[SerializeField]
private Vector2 m_Value;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kOutputSlotName = "Out";
private const string kOutputSlotName = "Out";
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public Vector2Node()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector2 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector2ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value
});
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId });
if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(string.Format("{0}2 {1} = {0}2({2},{3});", precision, GetVariableNameForNode(), NodeUtils.FloatToShaderValue(m_Value.x), NodeUtils.FloatToShaderValue(m_Value.y)), true);
}
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var outputName = GetVariableNameForSlot(OutputSlotId);
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = GetVariableNameForNode(),
vector4Value = m_Value
});
var s = string.Format("{0}2 {1} = {0}2({2},{3});",
precision,
outputName,
inputXValue,
inputYValue);
visitor.AddShaderChunk(s, false);
return new Vector2ShaderProperty { value = value };
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
return new Vector2ShaderProperty { value = new Vector2(slotX.value, slotY.value) };
public int outputSlotId { get { return OutputSlotId; } }
int IPropertyFromNode.outputSlotId { get { return OutputSlotId; } }
}
}

78
com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector3Node.cs


[SerializeField]
private Vector3 m_Value;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kInputSlotZName = "Z";
const string kOutputSlotName = "Out";
private const string kOutputSlotName = "Out";
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public const int InputSlotZId = 3;
public Vector3Node()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
AddSlot(new Vector1MaterialSlot(InputSlotZId, kInputSlotZName, kInputSlotZName, SlotType.Input, m_Value.z, label1: "Z"));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector3 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value
});
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId, InputSlotZId });
if (generationMode.IsPreview())
return;
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var inputZValue = GetSlotValue(InputSlotZId, generationMode);
var outputName = GetVariableNameForSlot(outputSlotId);
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z));
visitor.AddShaderChunk(s, true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = GetVariableNameForNode(),
vector4Value = m_Value
});
outputName,
inputXValue,
inputYValue,
inputZValue);
visitor.AddShaderChunk(s, false);
return new Vector3ShaderProperty { value = value };
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
var slotZ = FindInputSlot<Vector1MaterialSlot>(InputSlotZId);
return new Vector3ShaderProperty { value = new Vector3(slotX.value, slotY.value, slotZ.value) };
}
public int outputSlotId { get { return OutputSlotId; } }

83
com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/Vector4Node.cs


[SerializeField]
private Vector4 m_Value;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kInputSlotZName = "Z";
const string kInputSlotWName = "W";
const string kOutputSlotName = "Out";
private const string kOutputSlotName = "Out";
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public const int InputSlotZId = 3;
public const int InputSlotWId = 4;
public Vector4Node()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
AddSlot(new Vector1MaterialSlot(InputSlotZId, kInputSlotZName, kInputSlotZName, SlotType.Input, m_Value.z, label1: "Z"));
AddSlot(new Vector1MaterialSlot(InputSlotWId, kInputSlotWName, kInputSlotWName, SlotType.Input, m_Value.w, label1: "W"));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[MultiFloatControl("")]
public Vector4 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value
});
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId, InputSlotZId, InputSlotWId });
if (generationMode.IsPreview())
return;
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var inputZValue = GetSlotValue(InputSlotZId, generationMode);
var inputWValue = GetSlotValue(InputSlotWId, generationMode);
var outputName = GetVariableNameForSlot(outputSlotId);
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z),
NodeUtils.FloatToShaderValue(m_Value.w));
outputName,
inputXValue,
inputYValue,
inputZValue,
inputWValue);
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = GetVariableNameForNode(),
vector4Value = m_Value
});
}
return new Vector4ShaderProperty { value = value };
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
var slotZ = FindInputSlot<Vector1MaterialSlot>(InputSlotZId);
var slotW = FindInputSlot<Vector1MaterialSlot>(InputSlotWId);
return new Vector4ShaderProperty { value = new Vector4(slotX.value, slotY.value, slotZ.value, slotW.value) };
}
public int outputSlotId { get { return OutputSlotId; } }

2
com.unity.shadergraph/Editor/Data/Nodes/SlotValue.cs


public static class SlotValueHelper
{
public static int GetChannelCount(ConcreteSlotValueType type)
public static int GetChannelCount(this ConcreteSlotValueType type)
{
switch (type)
{

11
com.unity.shadergraph/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs


readonly Action<Vector4> m_Set;
int m_UndoGroup = -1;
public MultiFloatSlotControlView(INode node, int components, Func<Vector4> get, Action<Vector4> set)
public MultiFloatSlotControlView(INode node, string[] labels, Func<Vector4> get, Action<Vector4> set)
{
AddStyleSheetPath("Styles/Controls/MultiFloatSlotControlView");
m_Node = node;

AddField(initialValue, 0, "X");
if (components > 1)
AddField(initialValue, 1, "Y");
if (components > 2)
AddField(initialValue, 2, "Z");
if (components > 3)
AddField(initialValue, 3, "W");
for (var i = 0; i < labels.Length; i++)
AddField(initialValue, i, labels[i]);
}
void AddField(Vector4 initialValue, int index, string subLabel)

正在加载...
取消
保存