GitHub
7 年前
当前提交
9641212d
共有 44 个文件被更改,包括 1788 次插入 和 454 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
-
33MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
56MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PreviewProperty.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Implementation/NodeUtils.cs
-
65MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/CombineNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SplitNode.cs
-
32MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
96MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
-
110MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
-
132MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs
-
379MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/MultiplyNode.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixTransposeNode.cs
-
32MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraph.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
116MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs.meta
-
139MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicValueMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicValueMaterialSlot.cs.meta
-
34MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2ShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2ShaderProperty.cs.meta
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3ShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3ShaderProperty.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4ShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4ShaderProperty.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MatrixShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MatrixShaderProperty.cs.meta
-
121MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixConstructionNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixConstructionNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixDeterminantNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixDeterminantNode.cs.meta
-
278MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixSplitNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixSplitNode.cs.meta
-
19MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyNode.cs.meta
-
106MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs
-
118MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyNode.cs
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class DynamicMatrixMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4> |
|||
{ |
|||
[SerializeField] |
|||
private Matrix4x4 m_Value = Matrix4x4.identity; |
|||
|
|||
[SerializeField] |
|||
private Matrix4x4 m_DefaultValue = Matrix4x4.identity; |
|||
|
|||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Matrix4; |
|||
|
|||
public DynamicMatrixMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public DynamicMatrixMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public override VisualElement InstantiateControl() |
|||
{ |
|||
return new LabelSlotControlView("Identity"); |
|||
} |
|||
|
|||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Matrix4x4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.DynamicMatrix; } } |
|||
|
|||
public override ConcreteSlotValueType concreteValueType |
|||
{ |
|||
get { return m_ConcreteValueType; } |
|||
} |
|||
|
|||
public void SetConcreteType(ConcreteSlotValueType valueType) |
|||
{ |
|||
m_ConcreteValueType = valueType; |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
var channelCount = (int)SlotValueHelper.GetMatrixDimension(concreteValueType); |
|||
var values = ""; |
|||
bool isFirst = true; |
|||
for (var r = 0; r < channelCount; r++) |
|||
{ |
|||
for (var c = 0; c < channelCount; c++) |
|||
{ |
|||
if(!isFirst) |
|||
values += ", "; |
|||
isFirst = false; |
|||
values += value.GetRow(r)[c]; |
|||
} |
|||
} |
|||
return string.Format("{0}{1}x{1}({2})", precision, channelCount, values); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
IShaderProperty property; |
|||
switch (concreteValueType) |
|||
{ |
|||
case ConcreteSlotValueType.Matrix4: |
|||
property = new Matrix4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix3: |
|||
property = new Matrix3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix2: |
|||
property = new Matrix2ShaderProperty(); |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
property.generatePropertyBlock = false; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as DynamicMatrixMaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e985385869ccee4ca3c6fd2fd15174c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class DynamicValueMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4> |
|||
{ |
|||
[SerializeField] |
|||
private Matrix4x4 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Matrix4x4 m_DefaultValue; |
|||
|
|||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4; |
|||
|
|||
public DynamicValueMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public DynamicValueMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Matrix4x4 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Matrix4x4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
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))); |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Dynamic; } } |
|||
|
|||
public override ConcreteSlotValueType concreteValueType |
|||
{ |
|||
get { return m_ConcreteValueType; } |
|||
} |
|||
|
|||
public void SetConcreteType(ConcreteSlotValueType valueType) |
|||
{ |
|||
m_ConcreteValueType = valueType; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var propType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType); |
|||
var pp = new PreviewProperty(propType) { name = name }; |
|||
if (propType == PropertyType.Vector1) |
|||
pp.floatValue = value.m00; |
|||
else |
|||
pp.vector4Value = new Vector4(value.m00, value.m01, value.m02, value.m03); |
|||
return pp; |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType); |
|||
string values = NodeUtils.FloatToShaderValue(value.m00); |
|||
if (channelCount == 1) |
|||
return values; |
|||
for (var i = 1; i < channelCount; i++) |
|||
values += ", " + value.GetRow(0)[i]; |
|||
return string.Format("{0}{1}({2})", precision, channelCount, values); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
IShaderProperty property; |
|||
switch (concreteValueType) |
|||
{ |
|||
case ConcreteSlotValueType.Vector4: |
|||
property = new Vector4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector3: |
|||
property = new Vector3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector2: |
|||
property = new Vector2ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector1: |
|||
property = new Vector1ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix4: |
|||
property = new Matrix4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix3: |
|||
property = new Matrix3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix2: |
|||
property = new Matrix2ShaderProperty(); |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
property.generatePropertyBlock = false; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as DynamicValueMaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 38b2d4645340d4274a793e2e12ec097c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix2ShaderProperty : MatrixShaderProperty |
|||
{ |
|||
public Matrix2ShaderProperty() |
|||
{ |
|||
displayName = "Matrix2"; |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Matrix2; } |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString(string delimiter = ";") |
|||
{ |
|||
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)" + delimiter; |
|||
} |
|||
|
|||
public override INode ToConcreteNode() |
|||
{ |
|||
return new Matrix2Node |
|||
{ |
|||
row0 = new Vector2(value.m00, value.m01), |
|||
row1 = new Vector2(value.m10, value.m11) |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0755d7f7a7e11cb4294563bbd0d434cc |
|||
timeCreated: 1505346935 |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix3ShaderProperty : MatrixShaderProperty |
|||
{ |
|||
public Matrix3ShaderProperty() |
|||
{ |
|||
displayName = "Matrix3"; |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Matrix3; } |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString(string delimiter = ";") |
|||
{ |
|||
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)" + delimiter; |
|||
} |
|||
|
|||
public override INode ToConcreteNode() |
|||
{ |
|||
return new Matrix3Node |
|||
{ |
|||
row0 = new Vector3(value.m00, value.m01, value.m02), |
|||
row1 = new Vector3(value.m10, value.m11, value.m12), |
|||
row2 = new Vector3(value.m20, value.m21, value.m22) |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 95c9c50f50c70c8479180b855a3bd255 |
|||
timeCreated: 1505346935 |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix4ShaderProperty : MatrixShaderProperty |
|||
{ |
|||
public Matrix4ShaderProperty() |
|||
{ |
|||
displayName = "Matrix4"; |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Matrix4; } |
|||
} |
|||
|
|||
public override INode ToConcreteNode() |
|||
{ |
|||
return new Matrix4Node |
|||
{ |
|||
row0 = new Vector4(value.m00, value.m01, value.m02, value.m03), |
|||
row1 = new Vector4(value.m10, value.m11, value.m12, value.m13), |
|||
row2 = new Vector4(value.m20, value.m21, value.m22, value.m23), |
|||
row3 = new Vector4(value.m30, value.m31, value.m32, value.m33) |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6379ce3fb15957343ba875d18f87efbc |
|||
timeCreated: 1505346935 |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public abstract class MatrixShaderProperty : AbstractShaderProperty<Matrix4x4> |
|||
{ |
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
return string.Empty; |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(); } |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString(string delimiter = ";") |
|||
{ |
|||
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)" + delimiter; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return default(PreviewProperty); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 79075442664faac49b00b4c93d28e08b |
|||
timeCreated: 1505408377 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Matrix", "Matrix Construction")] |
|||
public class MatrixConstructionNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
const string kInputSlotM0Name = "M0"; |
|||
const string kInputSlotM1Name = "M1"; |
|||
const string kInputSlotM2Name = "M2"; |
|||
const string kInputSlotM3Name = "M3"; |
|||
const string kOutput4x4SlotName = "4x4"; |
|||
const string kOutput3x3SlotName = "3x3"; |
|||
const string kOutput2x2SlotName = "2x2"; |
|||
|
|||
public const int InputSlotM0Id = 0; |
|||
public const int InputSlotM1Id = 1; |
|||
public const int InputSlotM2Id = 2; |
|||
public const int InputSlotM3Id = 3; |
|||
public const int Output4x4SlotId = 4; |
|||
public const int Output3x3SlotId = 5; |
|||
public const int Output2x2SlotId = 6; |
|||
|
|||
public MatrixConstructionNode() |
|||
{ |
|||
name = "Matrix Construction"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
[SerializeField] |
|||
MatrixAxis m_Axis; |
|||
|
|||
[EnumControl("")] |
|||
MatrixAxis axis |
|||
{ |
|||
get { return m_Axis; } |
|||
set |
|||
{ |
|||
if (m_Axis.Equals(value)) |
|||
return; |
|||
m_Axis = value; |
|||
Dirty(ModificationScope.Graph); |
|||
} |
|||
} |
|||
|
|||
string GetFunctionName() |
|||
{ |
|||
return string.Format("Unity_MatrixConstruction_{0}", precision); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector4MaterialSlot(InputSlotM0Id, kInputSlotM0Name, kInputSlotM0Name, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new Vector4MaterialSlot(InputSlotM1Id, kInputSlotM1Name, kInputSlotM1Name, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new Vector4MaterialSlot(InputSlotM2Id, kInputSlotM2Name, kInputSlotM2Name, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new Vector4MaterialSlot(InputSlotM3Id, kInputSlotM3Name, kInputSlotM3Name, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new Matrix4MaterialSlot(Output4x4SlotId, kOutput4x4SlotName, kOutput4x4SlotName, SlotType.Output)); |
|||
AddSlot(new Matrix3MaterialSlot(Output3x3SlotId, kOutput3x3SlotName, kOutput3x3SlotName, SlotType.Output)); |
|||
AddSlot(new Matrix2MaterialSlot(Output2x2SlotId, kOutput2x2SlotName, kOutput2x2SlotName, SlotType.Output)); |
|||
RemoveSlotsNameNotMatching(new int[] { InputSlotM0Id, InputSlotM1Id, InputSlotM2Id, InputSlotM3Id, Output4x4SlotId, Output3x3SlotId, Output2x2SlotId }); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var sb = new ShaderStringBuilder(); |
|||
var inputM0Value = GetSlotValue(InputSlotM0Id, generationMode); |
|||
var inputM1Value = GetSlotValue(InputSlotM1Id, generationMode); |
|||
var inputM2Value = GetSlotValue(InputSlotM2Id, generationMode); |
|||
var inputM3Value = GetSlotValue(InputSlotM3Id, generationMode); |
|||
|
|||
sb.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(Output4x4SlotId).concreteValueType), GetVariableNameForSlot(Output4x4SlotId)); |
|||
sb.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(Output3x3SlotId).concreteValueType), GetVariableNameForSlot(Output3x3SlotId)); |
|||
sb.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(Output2x2SlotId).concreteValueType), GetVariableNameForSlot(Output2x2SlotId)); |
|||
sb.AppendLine("{0}({1}, {2}, {3}, {4}, {5}, {6}, {7});", |
|||
GetFunctionName(), |
|||
inputM0Value, |
|||
inputM1Value, |
|||
inputM2Value, |
|||
inputM3Value, |
|||
GetVariableNameForSlot(Output4x4SlotId), |
|||
GetVariableNameForSlot(Output3x3SlotId), |
|||
GetVariableNameForSlot(Output2x2SlotId)); |
|||
|
|||
visitor.AddShaderChunk(sb.ToString(), false); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) |
|||
{ |
|||
registry.ProvideFunction(GetFunctionName(), s => |
|||
{ |
|||
s.AppendLine("void {0} ({1} M0, {1} M1, {1} M2, {1} M3, out {2} Out4x4, out {3} Out3x3, out {4} Out2x2)", |
|||
GetFunctionName(), |
|||
FindInputSlot<MaterialSlot>(InputSlotM0Id).concreteValueType.ToString(precision), |
|||
FindOutputSlot<MaterialSlot>(Output4x4SlotId).concreteValueType.ToString(precision), |
|||
FindOutputSlot<MaterialSlot>(Output3x3SlotId).concreteValueType.ToString(precision), |
|||
FindOutputSlot<MaterialSlot>(Output2x2SlotId).concreteValueType.ToString(precision)); |
|||
using (s.BlockScope()) |
|||
{ |
|||
switch(m_Axis) |
|||
{ |
|||
case MatrixAxis.Column: |
|||
s.AppendLine("Out4x4 = {0}4x4(M0.x, M1.x, M2.x, M3.x, M0.y, M1.y, M2.y, M3.y, M0.z, M1.z, M2.z, M3.z, M0.w, M1.w, M2.w, M3.w);", precision); |
|||
s.AppendLine("Out3x3 = {0}3x3(M0.x, M1.x, M2.x, M0.y, M1.y, M2.y, M0.z, M1.z, M2.z);", precision); |
|||
s.AppendLine("Out2x2 = {0}2x2(M0.x, M1.x, M0.y, M1.y);", precision); |
|||
break; |
|||
default: |
|||
s.AppendLine("Out4x4 = {0}4x4(M0.x, M0.y, M0.z, M0.w, M1.x, M1.y, M1.z, M1.w, M2.x, M2.y, M2.z, M2.w, M3.x, M3.y, M3.z, M3.w);", precision); |
|||
s.AppendLine("Out3x3 = {0}3x3(M0.x, M0.y, M0.z, M1.x, M1.y, M1.z, M2.x, M2.y, M2.z);", precision); |
|||
s.AppendLine("Out2x2 = {0}2x2(M0.x, M0.y, M1.x, M1.y);", precision); |
|||
break; |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f3857db61fc34eaabd871901ae5a2b6 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Matrix", "Matrix Determinant")] |
|||
public class MatrixDeterminantNode : CodeFunctionNode |
|||
{ |
|||
public MatrixDeterminantNode() |
|||
{ |
|||
name = "Matrix Determinant"; |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_MatrixDeterminant", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_MatrixDeterminant( |
|||
[Slot(0, Binding.None)] DynamicDimensionMatrix In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = determinant(In); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 41d69945fb0fa45ec8e14292dfb9074d |
|||
timeCreated: 1495542985 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public enum MatrixAxis |
|||
{ |
|||
Row, |
|||
Column |
|||
} |
|||
|
|||
[Title("Math", "Matrix", "Matrix Split")] |
|||
public class MatrixSplitNode : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
const string kInputSlotName = "In"; |
|||
const string kOutputSlotM0Name = "M0"; |
|||
const string kOutputSlotM1Name = "M1"; |
|||
const string kOutputSlotM2Name = "M2"; |
|||
const string kOutputSlotM3Name = "M3"; |
|||
|
|||
public const int InputSlotId = 0; |
|||
public const int OutputSlotRId = 1; |
|||
public const int OutputSlotGId = 2; |
|||
public const int OutputSlotBId = 3; |
|||
public const int OutputSlotAId = 4; |
|||
|
|||
public MatrixSplitNode() |
|||
{ |
|||
name = "Matrix Split"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
[SerializeField] |
|||
MatrixAxis m_Axis; |
|||
|
|||
[EnumControl("")] |
|||
MatrixAxis axis |
|||
{ |
|||
get { return m_Axis; } |
|||
set |
|||
{ |
|||
if (m_Axis.Equals(value)) |
|||
return; |
|||
m_Axis = value; |
|||
Dirty(ModificationScope.Graph); |
|||
} |
|||
} |
|||
|
|||
static string[] s_ComponentList = new string[4] { "r", "g", "b", "a" }; |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new DynamicMatrixMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input)); |
|||
AddSlot(new DynamicVectorMaterialSlot(OutputSlotRId, kOutputSlotM0Name, kOutputSlotM0Name, SlotType.Output, Vector4.zero)); |
|||
AddSlot(new DynamicVectorMaterialSlot(OutputSlotGId, kOutputSlotM1Name, kOutputSlotM1Name, SlotType.Output, Vector4.zero)); |
|||
AddSlot(new DynamicVectorMaterialSlot(OutputSlotBId, kOutputSlotM2Name, kOutputSlotM2Name, SlotType.Output, Vector4.zero)); |
|||
AddSlot(new DynamicVectorMaterialSlot(OutputSlotAId, kOutputSlotM3Name, kOutputSlotM3Name, SlotType.Output, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new int[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId }); |
|||
} |
|||
|
|||
static int[] s_OutputSlots = {OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId}; |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
|
|||
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId); |
|||
var numInputRows = 0; |
|||
bool useIndentity = false; |
|||
|
|||
if (inputSlot != null) |
|||
{ |
|||
numInputRows = SlotValueHelper.GetMatrixDimension(inputSlot.concreteValueType); |
|||
if (numInputRows > 4) |
|||
numInputRows = 0; |
|||
|
|||
if (!owner.GetEdges(inputSlot.slotReference).Any()) |
|||
{ |
|||
numInputRows = 0; |
|||
useIndentity = true; |
|||
} |
|||
} |
|||
|
|||
int concreteRowCount = useIndentity ? 2 : numInputRows; |
|||
|
|||
for (var r = 0; r < 4; r++) |
|||
{ |
|||
string outputValue; |
|||
if(r >= numInputRows) |
|||
{ |
|||
outputValue = string.Format("{0}{1}(", precision, concreteRowCount); |
|||
for(int c = 0; c < concreteRowCount; c++) |
|||
{ |
|||
if(c!= 0) |
|||
outputValue += ", "; |
|||
outputValue += Matrix4x4.identity.GetRow(r)[c]; |
|||
} |
|||
outputValue += ")"; |
|||
} |
|||
else |
|||
{ |
|||
switch(m_Axis) |
|||
{ |
|||
case MatrixAxis.Column: |
|||
outputValue = string.Format("{0}{1}(", precision, numInputRows); |
|||
for(int c = 0; c < numInputRows; c++) |
|||
{ |
|||
if(c!= 0) |
|||
outputValue += ", "; |
|||
outputValue += string.Format("{0}[{1}].{2}", inputValue, c, s_ComponentList[r]); |
|||
} |
|||
outputValue += ")"; |
|||
break; |
|||
default: |
|||
outputValue = string.Format("{0}[{1}]", inputValue, r); |
|||
break; |
|||
} |
|||
} |
|||
visitor.AddShaderChunk(string.Format("{0}{1} {2} = {3};", precision, concreteRowCount, GetVariableNameForSlot(s_OutputSlots[r]), outputValue), true); |
|||
} |
|||
} |
|||
|
|||
public override void ValidateNode() |
|||
{ |
|||
var isInError = false; |
|||
|
|||
// all children nodes needs to be updated first
|
|||
// so do that here
|
|||
var slots = ListPool<MaterialSlot>.Get(); |
|||
GetInputSlots(slots); |
|||
foreach (var inputSlot in slots) |
|||
{ |
|||
inputSlot.hasError = false; |
|||
|
|||
var edges = owner.GetEdges(inputSlot.slotReference); |
|||
foreach (var edge in edges) |
|||
{ |
|||
var fromSocketRef = edge.outputSlot; |
|||
var outputNode = owner.GetNodeFromGuid(fromSocketRef.nodeGuid); |
|||
if (outputNode == null) |
|||
continue; |
|||
|
|||
outputNode.ValidateNode(); |
|||
if (outputNode.hasError) |
|||
isInError = true; |
|||
} |
|||
} |
|||
ListPool<MaterialSlot>.Release(slots); |
|||
|
|||
var dynamicInputSlotsToCompare = DictionaryPool<DynamicVectorMaterialSlot, ConcreteSlotValueType>.Get(); |
|||
var skippedDynamicSlots = ListPool<DynamicVectorMaterialSlot>.Get(); |
|||
|
|||
var dynamicMatrixInputSlotsToCompare = DictionaryPool<DynamicMatrixMaterialSlot, ConcreteSlotValueType>.Get(); |
|||
var skippedDynamicMatrixSlots = ListPool<DynamicMatrixMaterialSlot>.Get(); |
|||
|
|||
// iterate the input slots
|
|||
s_TempSlots.Clear(); |
|||
GetInputSlots(s_TempSlots); |
|||
foreach (var inputSlot in s_TempSlots) |
|||
{ |
|||
// if there is a connection
|
|||
var edges = owner.GetEdges(inputSlot.slotReference).ToList(); |
|||
if (!edges.Any()) |
|||
{ |
|||
if (inputSlot is DynamicVectorMaterialSlot) |
|||
skippedDynamicSlots.Add(inputSlot as DynamicVectorMaterialSlot); |
|||
if (inputSlot is DynamicMatrixMaterialSlot) |
|||
skippedDynamicMatrixSlots.Add(inputSlot as DynamicMatrixMaterialSlot); |
|||
continue; |
|||
} |
|||
|
|||
// get the output details
|
|||
var outputSlotRef = edges[0].outputSlot; |
|||
var outputNode = owner.GetNodeFromGuid(outputSlotRef.nodeGuid); |
|||
if (outputNode == null) |
|||
continue; |
|||
|
|||
var outputSlot = outputNode.FindOutputSlot<MaterialSlot>(outputSlotRef.slotId); |
|||
if (outputSlot == null) |
|||
continue; |
|||
|
|||
if (outputSlot.hasError) |
|||
{ |
|||
inputSlot.hasError = true; |
|||
continue; |
|||
} |
|||
|
|||
var outputConcreteType = outputSlot.concreteValueType; |
|||
// dynamic input... depends on output from other node.
|
|||
// we need to compare ALL dynamic inputs to make sure they
|
|||
// are compatable.
|
|||
if (inputSlot is DynamicVectorMaterialSlot) |
|||
{ |
|||
dynamicInputSlotsToCompare.Add((DynamicVectorMaterialSlot)inputSlot, outputConcreteType); |
|||
continue; |
|||
} |
|||
else if (inputSlot is DynamicMatrixMaterialSlot) |
|||
{ |
|||
dynamicMatrixInputSlotsToCompare.Add((DynamicMatrixMaterialSlot)inputSlot, outputConcreteType); |
|||
continue; |
|||
} |
|||
|
|||
// if we have a standard connection... just check the types work!
|
|||
if (!AbstractMaterialNode.ImplicitConversionExists(outputConcreteType, inputSlot.concreteValueType)) |
|||
inputSlot.hasError = true; |
|||
} |
|||
|
|||
// and now dynamic matrices
|
|||
var dynamicMatrixType = ConvertDynamicMatrixInputTypeToConcrete(dynamicMatrixInputSlotsToCompare.Values); |
|||
foreach (var dynamicKvP in dynamicMatrixInputSlotsToCompare) |
|||
dynamicKvP.Key.SetConcreteType(dynamicMatrixType); |
|||
foreach (var skippedSlot in skippedDynamicMatrixSlots) |
|||
skippedSlot.SetConcreteType(dynamicMatrixType); |
|||
|
|||
// we can now figure out the dynamic slotType
|
|||
// from here set all the
|
|||
var dynamicType = SlotValueHelper.ConvertMatrixToVectorType(dynamicMatrixType); |
|||
foreach (var dynamicKvP in dynamicInputSlotsToCompare) |
|||
dynamicKvP.Key.SetConcreteType(dynamicType); |
|||
foreach (var skippedSlot in skippedDynamicSlots) |
|||
skippedSlot.SetConcreteType(dynamicType); |
|||
|
|||
s_TempSlots.Clear(); |
|||
GetInputSlots(s_TempSlots); |
|||
var inputError = s_TempSlots.Any(x => x.hasError); |
|||
|
|||
// configure the output slots now
|
|||
// their slotType will either be the default output slotType
|
|||
// or the above dynanic slotType for dynamic nodes
|
|||
// or error if there is an input error
|
|||
s_TempSlots.Clear(); |
|||
GetOutputSlots(s_TempSlots); |
|||
foreach (var outputSlot in s_TempSlots) |
|||
{ |
|||
outputSlot.hasError = false; |
|||
|
|||
if (inputError) |
|||
{ |
|||
outputSlot.hasError = true; |
|||
continue; |
|||
} |
|||
|
|||
if (outputSlot is DynamicVectorMaterialSlot) |
|||
{ |
|||
(outputSlot as DynamicVectorMaterialSlot).SetConcreteType(dynamicType); |
|||
continue; |
|||
} |
|||
else if (outputSlot is DynamicMatrixMaterialSlot) |
|||
{ |
|||
(outputSlot as DynamicMatrixMaterialSlot).SetConcreteType(dynamicMatrixType); |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
isInError |= inputError; |
|||
s_TempSlots.Clear(); |
|||
GetOutputSlots(s_TempSlots); |
|||
isInError |= s_TempSlots.Any(x => x.hasError); |
|||
isInError |= CalculateNodeHasError(); |
|||
hasError = isInError; |
|||
|
|||
if (!hasError) |
|||
{ |
|||
++version; |
|||
} |
|||
|
|||
ListPool<DynamicVectorMaterialSlot>.Release(skippedDynamicSlots); |
|||
DictionaryPool<DynamicVectorMaterialSlot, ConcreteSlotValueType>.Release(dynamicInputSlotsToCompare); |
|||
|
|||
ListPool<DynamicMatrixMaterialSlot>.Release(skippedDynamicMatrixSlots); |
|||
DictionaryPool<DynamicMatrixMaterialSlot, ConcreteSlotValueType>.Release(dynamicMatrixInputSlotsToCompare); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 03599e40507c24caba0dd9b596f3b5dc |
|||
timeCreated: 1490896965 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Slots |
|||
{ |
|||
public class LabelSlotControlView : VisualElement |
|||
{ |
|||
public LabelSlotControlView(string label) |
|||
{ |
|||
var labelField = new Label (label); |
|||
Add(labelField); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b7e0bdc2deb5a43aca74fd1e84c94cfa |
|||
timeCreated: 1509718979 |
|
|||
fileFormatVersion: 2 |
|||
guid: ad9cec4b346abf749b3eb1730875ee5d |
|||
timeCreated: 1495542985 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8eb82c17970f84fc2b84d060df718533 |
|||
timeCreated: 1495542985 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Matrix", "MultiplyMatrixByVector")] |
|||
public class MatrixMultiplyByVectorNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
protected const string kInputSlot1ShaderName = "Input1"; |
|||
protected const string kInputSlot2ShaderName = "Input2"; |
|||
protected const string kOutputSlotShaderName = "Output"; |
|||
|
|||
public const int InputSlot1Id = 0; |
|||
public const int InputSlot2Id = 1; |
|||
public const int OutputSlotId = 2; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
public MatrixMultiplyByVectorNode() |
|||
{ |
|||
name = "MultiplyMatrixByVector"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected string GetFunctionName() |
|||
{ |
|||
return "unity_matrix_multiplybyvector_" + precision; |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot1()); |
|||
AddSlot(GetInputSlot2()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; } |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new Matrix4MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input); |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new Vector4MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, Vector4.zero); |
|||
} |
|||
|
|||
protected MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new Vector4MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlot1Name() |
|||
{ |
|||
return "Input1"; |
|||
} |
|||
|
|||
protected virtual string GetInputSlot2Name() |
|||
{ |
|||
return "Input2"; |
|||
} |
|||
|
|||
protected string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
protected string GetFunctionPrototype(string arg1Name, string arg2Name) |
|||
{ |
|||
return string.Format("inline {0} {1} ({2} {3}, {4} {5})", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetFunctionName(), NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType), arg1Name, NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), arg2Name); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId }); |
|||
string input1Value = GetSlotValue(InputSlot1Id, generationMode); |
|||
string input2Value = GetSlotValue(InputSlot2Id, generationMode); |
|||
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetVariableNameForSlot(OutputSlotId), GetFunctionCallBody(input1Value, input2Value)), true); |
|||
} |
|||
|
|||
protected string GetFunctionCallBody(string input1Value, string input2Value) |
|||
{ |
|||
return string.Format("{0} ({1}, {2})", GetFunctionName(), input1Value, input2Value); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) |
|||
{ |
|||
registry.ProvideFunction(GetFunctionName(), s => |
|||
{ |
|||
s.AppendLine(GetFunctionPrototype("arg1", "arg2")); |
|||
using (s.BlockScope()) |
|||
{ |
|||
s.AppendLine("return mul(arg1, arg2);"); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Matrix", "MultiplyMatrix")] |
|||
public class MatrixMultiplyNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
protected const string kInputSlot1ShaderName = "Input1"; |
|||
protected const string kInputSlot2ShaderName = "Input2"; |
|||
protected const string kOutputSlotShaderName = "Output"; |
|||
|
|||
public const int InputSlot1Id = 0; |
|||
public const int InputSlot2Id = 1; |
|||
public const int OutputSlotId = 2; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
public MatrixMultiplyNode() |
|||
{ |
|||
name = "MultiplyMatrix"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected string GetFunctionName() |
|||
{ |
|||
return "unity_matrix_multiply_" + precision; |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot1()); |
|||
AddSlot(GetInputSlot2()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; } |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new Matrix4MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input); |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new Matrix4MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input); |
|||
} |
|||
|
|||
protected MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new Matrix4MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output); |
|||
} |
|||
|
|||
protected virtual string GetInputSlot1Name() |
|||
{ |
|||
return "Input1"; |
|||
} |
|||
|
|||
protected virtual string GetInputSlot2Name() |
|||
{ |
|||
return "Input2"; |
|||
} |
|||
|
|||
protected string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
protected string GetFunctionPrototype(string arg1Name, string arg2Name) |
|||
{ |
|||
return string.Format("inline {0} {1} ({2} {3}, {4} {5})", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetFunctionName(), NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType), arg1Name, NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), arg2Name); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId }); |
|||
string input1Value = GetSlotValue(InputSlot1Id, generationMode); |
|||
string input2Value = GetSlotValue(InputSlot2Id, generationMode); |
|||
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType), GetVariableNameForSlot(OutputSlotId), GetFunctionCallBody(input1Value, input2Value)), true); |
|||
} |
|||
|
|||
protected string GetFunctionCallBody(string input1Value, string input2Value) |
|||
{ |
|||
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")"; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return mul(arg1, arg2);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) |
|||
{ |
|||
registry.ProvideFunction(GetFunctionName(), s => |
|||
{ |
|||
s.AppendLine(GetFunctionPrototype("arg1", "arg2")); |
|||
using (s.BlockScope()) |
|||
{ |
|||
s.AppendLine("return mul(arg1, arg2);"); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue