Matt Dean
7 年前
当前提交
41b314d2
共有 63 个文件被更改,包括 1943 次插入 和 1603 次删除
-
3MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraphObject.cs
-
15MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs
-
2MaterialGraphProject/Assets/NewNodes/Editor/Keep/UVTriPlanar.cs
-
458MaterialGraphProject/Assets/PartyPreview.ShaderGraph
-
485MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableTexture.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Art/Filters/ConvolutionFilterNode.cs
-
219MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/TextureNode.cs
-
34MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/TextureSamplerNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ProjectSpecificMasterNode.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
-
28MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BitangentMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BitangentMaterialSlot.cs.meta
-
114MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs.meta
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IMaterialSlotHasVaule.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IMaterialSlotHasVaule.cs.meta
-
43MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs.meta
-
42MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs.meta
-
43MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/NormalMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/NormalMaterialSlot.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PositionMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PositionMaterialSlot.cs.meta
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerStateMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerStateMaterialSlot.cs.meta
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs.meta
-
36MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SpaceMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SpaceMaterialSlot.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TangentMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TangentMaterialSlot.cs.meta
-
72MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DMaterialSlot.cs.meta
-
48MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs.meta
-
87MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs.meta
-
87MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs.meta
-
87MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs.meta
-
88MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs.meta
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/VertexColorMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/VertexColorMaterialSlot.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs.meta
-
432MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
507MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/HLSLNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs.meta
458
MaterialGraphProject/Assets/PartyPreview.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
/* [Title("Input/Texture/Texture")] |
|||
public class TextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
protected const string kUVSlotName = "UV"; |
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
protected const string kOutputSlotRName = "R"; |
|||
protected const string kOutputSlotGName = "G"; |
|||
protected const string kOutputSlotBName = "B"; |
|||
protected const string kOutputSlotAName = "A"; |
|||
public const int UvSlotId = 0; |
|||
public const int OutputSlotRgbaId = 1; |
|||
public const int OutputSlotRId = 2; |
|||
public const int OutputSlotGId = 3; |
|||
public const int OutputSlotBId = 4; |
|||
public const int OutputSlotAId = 5; |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture defaultTexture {get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
|
|||
|
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public TextureNode() |
|||
{ |
|||
name = "Texture"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
|
|||
if (edges.Count > 0) |
|||
{ |
|||
var edge = edges[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
string body = "tex2D (" + propertyName + ", " + uvName + ")"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true); |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
string slotOutput; |
|||
switch (slotId) |
|||
{ |
|||
case OutputSlotRId: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case OutputSlotGId: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case OutputSlotBId: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case OutputSlotAId: |
|||
slotOutput = ".a"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return GetVariableNameForNode() + slotOutput; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true); |
|||
} |
|||
|
|||
/* |
|||
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot != inputSlot) |
|||
return base.DrawSlotDefaultInput(rect, inputSlot); |
|||
|
|||
|
|||
var rectXmax = rect.xMax; |
|||
rect.x = rectXmax - 70; |
|||
rect.width = 70; |
|||
|
|||
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
|||
GUI.Label(rect, "From Mesh"); |
|||
|
|||
return false; |
|||
} |
|||
* |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture; } } |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class BitangentMaterialSlot : SpaceMaterialSlot, IMayRequireBitangent |
|||
{ |
|||
public BitangentMaterialSlot() : base() |
|||
{} |
|||
|
|||
public BitangentMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return space.ToVariableName(InterpolatorType.BiTangent); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
if (isConnected) |
|||
return NeededCoordinateSpace.None; |
|||
return space.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 67f66fefcaac3e04388ec470163bf127 |
|||
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 DynamicVectorMaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector4> |
|||
{ |
|||
[SerializeField] |
|||
private Vector4 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Vector4 m_DefaultValue; |
|||
|
|||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4; |
|||
|
|||
public DynamicVectorMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public DynamicVectorMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Vector4 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Vector4 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Vector4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
|
|||
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 pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType), |
|||
m_Vector4 = new Vector4(value.x, value.y, value.z, value.w), |
|||
m_Float = value.x, |
|||
m_Color = new Vector4(value.x, value.x, value.z, value.w), |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")"; |
|||
} |
|||
|
|||
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 FloatShaderProperty(); |
|||
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 DynamicVectorMaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a5dfe8ebe34ab064fb2769846adaa6a3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public interface IMaterialSlotHasVaule<T> |
|||
{ |
|||
T defaultValue { get; } |
|||
T value { get; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 722107fbcd3d86249ac260090e5cc77e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix2MaterialSlot : MaterialSlot |
|||
{ |
|||
|
|||
public Matrix2MaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public Matrix2MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "2x2 (1,0,0,1)"; |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Matrix2; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix2; } } |
|||
|
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4cba4fbdefbdfa04cb2f6f84376a1353 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix3MaterialSlot : MaterialSlot |
|||
{ |
|||
|
|||
public Matrix3MaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public Matrix3MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "3x3 (1,0,0,0,1,0,0,0,1)"; |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Matrix3; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix3; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5afbdbfda75b8c24ab4c07b8b3deddbe |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Matrix4MaterialSlot : MaterialSlot |
|||
{ |
|||
public Matrix4MaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public Matrix4MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "4x4 (1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)"; |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Matrix4; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix4; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 69e137d338a024949b0a96921f86ee50 |
|||
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 NormalMaterialSlot : SpaceMaterialSlot, IMayRequireNormal |
|||
{ |
|||
|
|||
public NormalMaterialSlot() |
|||
{} |
|||
|
|||
public NormalMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return space.ToVariableName(InterpolatorType.Normal); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
if (isConnected) |
|||
return NeededCoordinateSpace.None; |
|||
return space.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 08969711a3defe445a6803416d676b5b |
|||
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 PositionMaterialSlot : SpaceMaterialSlot, IMayRequirePosition |
|||
{ |
|||
public PositionMaterialSlot() |
|||
{} |
|||
|
|||
public PositionMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return space.ToVariableName(InterpolatorType.Position); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresPosition() |
|||
{ |
|||
if (isConnected) |
|||
return NeededCoordinateSpace.None; |
|||
return space.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0612806deec2f154587fad5a1f7b060a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class SamplerStateMaterialSlot : MaterialSlot |
|||
{ |
|||
public SamplerStateMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public SamplerStateMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.SamplerState; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.SamplerState; } } |
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 095dad16f79a37b4d9aba1e9c31691f9 |
|||
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 ScreenPositionMaterialSlot : Vector4MaterialSlot, IMayRequireScreenPosition |
|||
{ |
|||
public ScreenPositionMaterialSlot(int slotId, string displayName, string shaderOutputName, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden) |
|||
{ } |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return ShaderGeneratorNames.ScreenPosition; |
|||
} |
|||
|
|||
public bool RequiresScreenPosition() |
|||
{ |
|||
return !isConnected; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 20a329ed82797b8459cd7b6e22787f2e |
|||
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 abstract class SpaceMaterialSlot : Vector3MaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private CoordinateSpace m_Space = CoordinateSpace.World; |
|||
|
|||
public CoordinateSpace space |
|||
{ |
|||
get { return m_Space; } |
|||
set { m_Space = value; } |
|||
} |
|||
|
|||
protected SpaceMaterialSlot() |
|||
{} |
|||
|
|||
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) |
|||
{ |
|||
this.space = space; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as NormalMaterialSlot; |
|||
if (slot != null) |
|||
space = slot.space; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 66199806246c45e493afdfc09208cbdc |
|||
timeCreated: 1509290088 |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class TangentMaterialSlot : SpaceMaterialSlot, IMayRequireTangent |
|||
{ |
|||
public TangentMaterialSlot() |
|||
{} |
|||
|
|||
public TangentMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return space.ToVariableName(InterpolatorType.Tangent); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
if (isConnected) |
|||
return NeededCoordinateSpace.None; |
|||
return space.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4c42ea0d8f47bbb4c9933bd050602d04 |
|||
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 Texture2DInputMaterialSlot : Texture2DMaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private SerializableTexture m_Texture = new SerializableTexture(); |
|||
|
|||
public Texture texture |
|||
{ |
|||
get { return m_Texture.texture; } |
|||
set { m_Texture.texture = value; } |
|||
} |
|||
|
|||
public Texture2DInputMaterialSlot() |
|||
{} |
|||
|
|||
public Texture2DInputMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
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))); |
|||
|
|||
return matOwner.GetVariableNameForSlot(id); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
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))); |
|||
|
|||
var prop = new TextureShaderProperty(); |
|||
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
prop.modifiable = false; |
|||
prop.generatePropertyBlock = true; |
|||
prop.value.texture = texture; |
|||
properties.AddShaderProperty(prop); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = texture |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Texture2DInputMaterialSlot; |
|||
if (slot != null) |
|||
m_Texture = slot.m_Texture; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ebeb3a21d05d49caa5d3318fb49b7612 |
|||
timeCreated: 1509276977 |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Texture2DMaterialSlot : MaterialSlot |
|||
{ |
|||
public Texture2DMaterialSlot() |
|||
{} |
|||
|
|||
public Texture2DMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Texture2D; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Texture2D; } } |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: af7e1a692e5050c4ca44bb5a0e4ae4ca |
|||
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 UVMaterialSlot : Vector2MaterialSlot, IMayRequireMeshUV |
|||
{ |
|||
private UVChannel m_Channel = UVChannel.uv0; |
|||
|
|||
public UVChannel channel |
|||
{ |
|||
get { return m_Channel; } |
|||
set { m_Channel = value; } |
|||
} |
|||
|
|||
public UVMaterialSlot() |
|||
{} |
|||
|
|||
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) |
|||
{ |
|||
this.channel = channel; |
|||
} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return string.Format("{0}.xy", channel.GetUVName()); |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (isConnected) |
|||
return false; |
|||
|
|||
return m_Channel == channel; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as UVMaterialSlot; |
|||
if (slot != null) |
|||
channel = slot.channel; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 33b78bbe7d29809499c4e314b196f3cf |
|||
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 Vector1MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<float> |
|||
{ |
|||
[SerializeField] |
|||
private float m_Value; |
|||
|
|||
[SerializeField] |
|||
private float m_DefaultValue; |
|||
|
|||
public Vector1MaterialSlot() |
|||
{} |
|||
|
|||
public Vector1MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
float value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_DefaultValue = value; |
|||
m_Value = value; |
|||
} |
|||
|
|||
public float defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public float value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return value.ToString(); |
|||
} |
|||
|
|||
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))); |
|||
|
|||
var property = new FloatShaderProperty() |
|||
{ |
|||
overrideReferenceName = matOwner.GetVariableNameForSlot(id), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Vector1; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector1; } } |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType), |
|||
m_Vector4 = new Vector4(value, value, value, value), |
|||
m_Float = value, |
|||
m_Color = new Vector4(value, value, value, value), |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Vector1MaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 040094878824e9948a10bc97408f84f3 |
|||
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 Vector2MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector2> |
|||
{ |
|||
[SerializeField] |
|||
private Vector2 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Vector2 m_DefaultValue; |
|||
|
|||
public Vector2MaterialSlot() |
|||
{} |
|||
|
|||
public Vector2MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Vector2 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Vector2 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Vector2 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "2 (" + value.x + "," + value.y + ")"; |
|||
} |
|||
|
|||
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))); |
|||
|
|||
var property = new Vector2ShaderProperty |
|||
{ |
|||
overrideReferenceName = matOwner.GetVariableNameForSlot(id), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType), |
|||
m_Vector4 = new Vector4(value.x, value.y, 0, 0), |
|||
m_Float = value.x, |
|||
m_Color = new Vector4(value.x, value.x, 0, 0), |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Vector2; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector2; } } |
|||
|
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Vector2MaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1a465b9562de8ef4eb8d8169e41b7e90 |
|||
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 Vector3MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector3> |
|||
{ |
|||
[SerializeField] |
|||
private Vector3 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Vector3 m_DefaultValue; |
|||
|
|||
public Vector3MaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public Vector3MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Vector3 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Vector3 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Vector3 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "3 (" + value.x + "," + value.y + "," + value.z + ")"; |
|||
} |
|||
|
|||
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))); |
|||
|
|||
var property = new Vector3ShaderProperty() |
|||
{ |
|||
overrideReferenceName = matOwner.GetVariableNameForSlot(id), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType), |
|||
m_Vector4 = new Vector4(value.x, value.y, value.z, 0), |
|||
m_Float = value.x, |
|||
m_Color = new Vector4(value.x, value.x, value.z, 0), |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Vector3; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector3; } } |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Vector3MaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: eb19b5420cdd2894c92c1683993bee49 |
|||
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 Vector4MaterialSlot : MaterialSlot, IMaterialSlotHasVaule<Vector4> |
|||
{ |
|||
[SerializeField] |
|||
private Vector4 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Vector4 m_DefaultValue; |
|||
|
|||
public Vector4MaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public Vector4MaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Vector4 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
:base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Vector4 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Vector4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")"; |
|||
} |
|||
|
|||
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))); |
|||
|
|||
var property = new Vector4ShaderProperty() |
|||
{ |
|||
overrideReferenceName = matOwner.GetVariableNameForSlot(id), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType), |
|||
m_Vector4 = new Vector4(value.x, value.y, value.z, value.w), |
|||
m_Float = value.x, |
|||
m_Color = new Vector4(value.x, value.x, value.z, value.w), |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Vector4; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector4; } } |
|||
|
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Vector4MaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aad5b297ad24f804aa36b04329f70020 |
|||
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 VertexColorMaterialSlot : Vector4MaterialSlot, IMayRequireScreenPosition |
|||
{ |
|||
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) |
|||
{ } |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return ShaderGeneratorNames.VertexColor; |
|||
} |
|||
|
|||
public bool RequiresScreenPosition() |
|||
{ |
|||
return !isConnected; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d03029f14ab44744d948ca282e300cb3 |
|||
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 ViewDirectionMaterialSlot : SpaceMaterialSlot, IMayRequireViewDirection |
|||
{ |
|||
public ViewDirectionMaterialSlot() |
|||
{} |
|||
|
|||
public ViewDirectionMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
return space.ToVariableName(InterpolatorType.ViewDirection); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
if (isConnected) |
|||
return NeededCoordinateSpace.None; |
|||
return space.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fd41e705ec44f6a428a22f08da1b19b3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public abstract class CodeFunctionNode : AbstractMaterialNode |
|||
, IGeneratesBodyCode |
|||
, IGeneratesFunction |
|||
, IMayRequireNormal |
|||
, IMayRequireTangent |
|||
, IMayRequireBitangent |
|||
, IMayRequireMeshUV |
|||
, IMayRequireScreenPosition |
|||
, IMayRequireViewDirection |
|||
, IMayRequirePosition |
|||
, IMayRequireVertexColor |
|||
{ |
|||
[NonSerialized] |
|||
private List<SlotAttribute> m_Slots = new List<SlotAttribute>(); |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected CodeFunctionNode() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected struct Vector1 |
|||
{} |
|||
|
|||
protected struct Texture2D |
|||
{} |
|||
|
|||
protected struct SamplerState |
|||
{} |
|||
|
|||
protected struct DynamicDimensionVector |
|||
{} |
|||
|
|||
protected enum Binding |
|||
{ |
|||
None, |
|||
ObjectSpaceNormal, |
|||
ObjectSpaceTangent, |
|||
ObjectSpaceBitangent, |
|||
ObjectSpacePosition, |
|||
ViewSpaceNormal, |
|||
ViewSpaceTangent, |
|||
ViewSpaceBitangent, |
|||
ViewSpacePosition, |
|||
WorldSpaceNormal, |
|||
WorldSpaceTangent, |
|||
WorldSpaceBitangent, |
|||
WorldSpacePosition, |
|||
TangentSpaceNormal, |
|||
TangentSpaceTangent, |
|||
TangentSpaceBitangent, |
|||
TangentSpacePosition, |
|||
MeshUV0, |
|||
MeshUV1, |
|||
MeshUV2, |
|||
MeshUV3, |
|||
ScreenPosition, |
|||
ObjectSpaceViewDirection, |
|||
ViewSpaceViewDirection, |
|||
WorldSpaceViewDirection, |
|||
TangentSpaceViewDirection, |
|||
VertexColor, |
|||
} |
|||
|
|||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] |
|||
protected class SlotAttribute : Attribute |
|||
{ |
|||
public int slotId { get; private set; } |
|||
public Binding binding { get; private set; } |
|||
public bool hidden { get; private set; } |
|||
public Vector4? defaultValue { get; private set; } |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
defaultValue = null; |
|||
} |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding, bool mHidden) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
hidden = mHidden; |
|||
defaultValue = null; |
|||
} |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding, float defaultX, float defaultY, float defaultZ, float defaultW) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
defaultValue = new Vector4(defaultX, defaultY, defaultZ, defaultW); |
|||
} |
|||
} |
|||
|
|||
protected abstract MethodInfo GetFunctionToConvert(); |
|||
|
|||
private static SlotValueType ConvertTypeToSlotValueType(ParameterInfo p) |
|||
{ |
|||
Type t = p.ParameterType; |
|||
if (p.ParameterType.IsByRef) |
|||
t = p.ParameterType.GetElementType(); |
|||
|
|||
if (t == typeof(Vector1)) |
|||
{ |
|||
return SlotValueType.Vector1; |
|||
} |
|||
if (t == typeof(Vector2)) |
|||
{ |
|||
return SlotValueType.Vector2; |
|||
} |
|||
if (t == typeof(Vector3)) |
|||
{ |
|||
return SlotValueType.Vector3; |
|||
} |
|||
if (t == typeof(Vector4)) |
|||
{ |
|||
return SlotValueType.Vector4; |
|||
} |
|||
if (t == typeof(Texture2D)) |
|||
{ |
|||
return SlotValueType.Texture2D; |
|||
} |
|||
if (t == typeof(SamplerState)) |
|||
{ |
|||
return SlotValueType.SamplerState; |
|||
} |
|||
if (t == typeof(DynamicDimensionVector)) |
|||
{ |
|||
return SlotValueType.Dynamic; |
|||
} |
|||
if (t == typeof(Matrix4x4)) |
|||
{ |
|||
return SlotValueType.Matrix4; |
|||
} |
|||
throw new ArgumentException("Unsupported type " + t); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
var method = GetFunctionToConvert(); |
|||
|
|||
if (method == null) |
|||
throw new ArgumentException("Mapped method is null on node" + this); |
|||
|
|||
if (method.ReturnType != typeof(string)) |
|||
throw new ArgumentException("Mapped function should return string"); |
|||
|
|||
// validate no duplicates
|
|||
var slotAtributes = method.GetParameters().Select(GetSlotAttribute).ToList(); |
|||
if (slotAtributes.Any(x => x == null)) |
|||
throw new ArgumentException("Missing SlotAttribute on " + method.Name); |
|||
|
|||
if (slotAtributes.GroupBy(x => x.slotId).Any(x => x.Count() > 1)) |
|||
throw new ArgumentException("Duplicate SlotAttribute on " + method.Name); |
|||
|
|||
List<MaterialSlot> slots = new List<MaterialSlot>(); |
|||
foreach (var par in method.GetParameters()) |
|||
{ |
|||
var attribute = GetSlotAttribute(par); |
|||
|
|||
MaterialSlot s; |
|||
if (attribute.binding == Binding.None || par.IsOut) |
|||
{ |
|||
s = MaterialSlot.CreateMaterialSlot( |
|||
ConvertTypeToSlotValueType(par), |
|||
attribute.slotId, |
|||
par.Name, |
|||
par.Name, |
|||
par.IsOut ? SlotType.Output : SlotType.Input, |
|||
attribute.defaultValue ?? Vector4.zero, |
|||
hidden: attribute.hidden); |
|||
} |
|||
else |
|||
{ |
|||
s = CreateBoundSlot(attribute.binding, attribute.slotId, par.Name, par.Name, attribute.hidden); |
|||
} |
|||
slots.Add(s); |
|||
|
|||
m_Slots.Add(attribute); |
|||
} |
|||
foreach (var slot in slots) |
|||
{ |
|||
AddSlot(slot); |
|||
} |
|||
RemoveSlotsNameNotMatching(slots.Select(x => x.id)); |
|||
} |
|||
|
|||
private static MaterialSlot CreateBoundSlot(Binding attributeBinding, int slotId, string displayName, string shaderOutputName, bool hidden) |
|||
{ |
|||
switch (attributeBinding) |
|||
{ |
|||
case Binding.ObjectSpaceNormal: |
|||
return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object); |
|||
case Binding.ObjectSpaceTangent: |
|||
return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object); |
|||
case Binding.ObjectSpaceBitangent: |
|||
return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object); |
|||
case Binding.ObjectSpacePosition: |
|||
return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object); |
|||
case Binding.ViewSpaceNormal: |
|||
return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View); |
|||
case Binding.ViewSpaceTangent: |
|||
return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View); |
|||
case Binding.ViewSpaceBitangent: |
|||
return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View); |
|||
case Binding.ViewSpacePosition: |
|||
return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View); |
|||
case Binding.WorldSpaceNormal: |
|||
return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World); |
|||
case Binding.WorldSpaceTangent: |
|||
return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World); |
|||
case Binding.WorldSpaceBitangent: |
|||
return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World); |
|||
case Binding.WorldSpacePosition: |
|||
return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World); |
|||
case Binding.TangentSpaceNormal: |
|||
return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent); |
|||
case Binding.TangentSpaceTangent: |
|||
return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent); |
|||
case Binding.TangentSpaceBitangent: |
|||
return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent); |
|||
case Binding.TangentSpacePosition: |
|||
return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent); |
|||
case Binding.MeshUV0: |
|||
return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.uv0); |
|||
case Binding.MeshUV1: |
|||
return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.uv1); |
|||
case Binding.MeshUV2: |
|||
return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.uv2); |
|||
case Binding.MeshUV3: |
|||
return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.uv3); |
|||
case Binding.ScreenPosition: |
|||
return new ScreenPositionMaterialSlot(slotId, displayName, shaderOutputName); |
|||
case Binding.ObjectSpaceViewDirection: |
|||
return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object); |
|||
case Binding.ViewSpaceViewDirection: |
|||
return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View); |
|||
case Binding.WorldSpaceViewDirection: |
|||
return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World); |
|||
case Binding.TangentSpaceViewDirection: |
|||
return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent); |
|||
case Binding.VertexColor: |
|||
return new VertexColorMaterialSlot(slotId, displayName, shaderOutputName); |
|||
default: |
|||
throw new ArgumentOutOfRangeException("attributeBinding", attributeBinding, null); |
|||
} |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var outSlot in GetOutputSlots<MaterialSlot>()) |
|||
{ |
|||
visitor.AddShaderChunk(GetParamTypeName(outSlot) + " " + GetVariableNameForSlot(outSlot.id) + ";", true); |
|||
} |
|||
|
|||
string call = GetFunctionName() + "("; |
|||
bool first = true; |
|||
foreach (var slot in GetSlots<MaterialSlot>().OrderBy(x => x.id)) |
|||
{ |
|||
if (!first) |
|||
{ |
|||
call += ", "; |
|||
} |
|||
first = false; |
|||
|
|||
if (slot.isInputSlot) |
|||
call += GetSlotValue(slot.id, generationMode); |
|||
else |
|||
call += GetVariableNameForSlot(slot.id); |
|||
} |
|||
call += ");"; |
|||
|
|||
visitor.AddShaderChunk(call, true); |
|||
} |
|||
|
|||
private string GetParamTypeName(MaterialSlot slot) |
|||
{ |
|||
return ConvertConcreteSlotValueTypeToString(precision, slot.concreteValueType); |
|||
} |
|||
|
|||
private string GetFunctionName() |
|||
{ |
|||
var function = GetFunctionToConvert(); |
|||
return function.Name + "_" + (function.IsStatic ? string.Empty : GuidEncoder.Encode(guid) + "_") + precision; |
|||
} |
|||
|
|||
private string GetFunctionHeader() |
|||
{ |
|||
string header = "void " + GetFunctionName() + "("; |
|||
|
|||
var first = true; |
|||
foreach (var slot in GetSlots<MaterialSlot>().OrderBy(x => x.id)) |
|||
{ |
|||
if (!first) |
|||
header += ", "; |
|||
|
|||
first = false; |
|||
|
|||
if (slot.isOutputSlot) |
|||
header += "out "; |
|||
|
|||
header += GetParamTypeName(slot) + " " + slot.shaderOutputName; |
|||
} |
|||
|
|||
header += ")"; |
|||
return header; |
|||
} |
|||
|
|||
private static object GetDefault(Type type) |
|||
{ |
|||
return type.IsValueType ? Activator.CreateInstance(type) : null; |
|||
} |
|||
|
|||
private string GetFunctionBody(MethodInfo info) |
|||
{ |
|||
var args = new List<object>(); |
|||
foreach (var param in info.GetParameters()) |
|||
args.Add(GetDefault(param.ParameterType)); |
|||
|
|||
var result = info.Invoke(this, args.ToArray()) as string; |
|||
|
|||
if (string.IsNullOrEmpty(result)) |
|||
return string.Empty; |
|||
|
|||
result = result.Replace("{precision}", precision.ToString()); |
|||
foreach (var slot in GetSlots<MaterialSlot>()) |
|||
{ |
|||
var toReplace = string.Format("{{slot{0}dimension}}", slot.id); |
|||
var replacement = GetSlotDimension(slot.concreteValueType); |
|||
result = result.Replace(toReplace, replacement); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
public virtual void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string function = GetFunctionHeader() + GetFunctionBody(GetFunctionToConvert()); |
|||
visitor.AddShaderChunk(function, true); |
|||
} |
|||
|
|||
private static SlotAttribute GetSlotAttribute([NotNull] ParameterInfo info) |
|||
{ |
|||
var attrs = info.GetCustomAttributes(typeof(SlotAttribute), false).OfType<SlotAttribute>().ToList(); |
|||
return attrs.FirstOrDefault(); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireNormal>()) |
|||
binding |= slot.RequiresNormal(); |
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireViewDirection>()) |
|||
binding |= slot.RequiresViewDirection(); |
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresPosition() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequirePosition>()) |
|||
binding |= slot.RequiresPosition(); |
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireTangent>()) |
|||
binding |= slot.RequiresTangent(); |
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireBitangent>()) |
|||
binding |= slot.RequiresBitangent(); |
|||
return binding; |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireMeshUV>()) |
|||
{ |
|||
if (slot.RequiresMeshUV(channel)) |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public bool RequiresScreenPosition() |
|||
{ |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireScreenPosition>()) |
|||
{ |
|||
if (slot.RequiresScreenPosition()) |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public bool RequiresVertexColor() |
|||
{ |
|||
foreach (var slot in GetInputSlots<MaterialSlot>().OfType<IMayRequireVertexColor>()) |
|||
{ |
|||
if (slot.RequiresVertexColor()) |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public abstract class CodeFunctionNode : AbstractMaterialNode |
|||
, IGeneratesBodyCode |
|||
, IGeneratesFunction |
|||
, IMayRequireNormal |
|||
, IMayRequireTangent |
|||
, IMayRequireBitangent |
|||
, IMayRequireMeshUV |
|||
, IMayRequireScreenPosition |
|||
, IMayRequireViewDirection |
|||
, IMayRequirePosition |
|||
, IMayRequireVertexColor |
|||
{ |
|||
[NonSerialized] |
|||
private List<SlotAttribute> m_Slots = new List<SlotAttribute>(); |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected CodeFunctionNode() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected struct Vector1 |
|||
{} |
|||
|
|||
protected struct Texture2D |
|||
{} |
|||
|
|||
protected struct SamplerState |
|||
{} |
|||
|
|||
protected struct DynamicDimensionVector |
|||
{} |
|||
|
|||
protected enum Binding |
|||
{ |
|||
None, |
|||
ObjectSpaceNormal, |
|||
ObjectSpaceTangent, |
|||
ObjectSpaceBitangent, |
|||
ObjectSpacePosition, |
|||
ViewSpaceNormal, |
|||
ViewSpaceTangent, |
|||
ViewSpaceBitangent, |
|||
ViewSpacePosition, |
|||
WorldSpaceNormal, |
|||
WorldSpaceTangent, |
|||
WorldSpaceBitangent, |
|||
WorldSpacePosition, |
|||
TangentSpaceNormal, |
|||
TangentSpaceTangent, |
|||
TangentSpaceBitangent, |
|||
TangentSpacePosition, |
|||
MeshUV0, |
|||
MeshUV1, |
|||
MeshUV2, |
|||
MeshUV3, |
|||
ScreenPosition, |
|||
ObjectSpaceViewDirection, |
|||
ViewSpaceViewDirection, |
|||
WorldSpaceViewDirection, |
|||
TangentSpaceViewDirection, |
|||
VertexColor, |
|||
} |
|||
|
|||
private static string BindChannelToShaderName(Binding channel) |
|||
{ |
|||
switch (channel) |
|||
{ |
|||
case Binding.None: |
|||
return "ERROR!"; |
|||
case Binding.ObjectSpaceNormal: |
|||
return CoordinateSpace.Object.ToVariableName(InterpolatorType.Normal); |
|||
case Binding.ObjectSpaceTangent: |
|||
return CoordinateSpace.Object.ToVariableName(InterpolatorType.Tangent); |
|||
case Binding.ObjectSpaceBitangent: |
|||
return CoordinateSpace.Object.ToVariableName(InterpolatorType.BiTangent); |
|||
case Binding.ObjectSpacePosition: |
|||
return CoordinateSpace.Object.ToVariableName(InterpolatorType.Position); |
|||
case Binding.ViewSpaceNormal: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.Normal); |
|||
case Binding.ViewSpaceTangent: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.Tangent); |
|||
case Binding.ViewSpaceBitangent: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.BiTangent); |
|||
case Binding.ViewSpacePosition: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.Position); |
|||
case Binding.WorldSpaceNormal: |
|||
return CoordinateSpace.World.ToVariableName(InterpolatorType.Normal); |
|||
case Binding.WorldSpaceTangent: |
|||
return CoordinateSpace.World.ToVariableName(InterpolatorType.Tangent); |
|||
case Binding.WorldSpaceBitangent: |
|||
return CoordinateSpace.World.ToVariableName(InterpolatorType.BiTangent); |
|||
case Binding.WorldSpacePosition: |
|||
return CoordinateSpace.World.ToVariableName(InterpolatorType.Position); |
|||
case Binding.TangentSpaceNormal: |
|||
return CoordinateSpace.Tangent.ToVariableName(InterpolatorType.Normal); |
|||
case Binding.TangentSpaceTangent: |
|||
return CoordinateSpace.Tangent.ToVariableName(InterpolatorType.Tangent); |
|||
case Binding.TangentSpaceBitangent: |
|||
return CoordinateSpace.Tangent.ToVariableName(InterpolatorType.BiTangent); |
|||
case Binding.TangentSpacePosition: |
|||
return CoordinateSpace.Tangent.ToVariableName(InterpolatorType.Position); |
|||
case Binding.MeshUV0: |
|||
return UVChannel.uv0.GetUVName(); |
|||
case Binding.MeshUV1: |
|||
return UVChannel.uv1.GetUVName(); |
|||
case Binding.MeshUV2: |
|||
return UVChannel.uv2.GetUVName(); |
|||
case Binding.MeshUV3: |
|||
return UVChannel.uv3.GetUVName(); |
|||
case Binding.ScreenPosition: |
|||
return ShaderGeneratorNames.ScreenPosition; |
|||
case Binding.ObjectSpaceViewDirection: |
|||
return CoordinateSpace.Object.ToVariableName(InterpolatorType.ViewDirection); |
|||
case Binding.ViewSpaceViewDirection: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.ViewDirection); |
|||
case Binding.WorldSpaceViewDirection: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.ViewDirection); |
|||
case Binding.TangentSpaceViewDirection: |
|||
return CoordinateSpace.View.ToVariableName(InterpolatorType.ViewDirection); |
|||
case Binding.VertexColor: |
|||
return ShaderGeneratorNames.VertexColor; |
|||
default: |
|||
throw new ArgumentOutOfRangeException("channel", channel, null); |
|||
} |
|||
} |
|||
|
|||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] |
|||
protected class SlotAttribute : Attribute |
|||
{ |
|||
public int slotId { get; private set; } |
|||
public Binding binding { get; private set; } |
|||
public bool hidden { get; private set; } |
|||
public Vector4? defaultValue { get; private set; } |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
defaultValue = null; |
|||
} |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding, bool mHidden) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
hidden = mHidden; |
|||
defaultValue = null; |
|||
} |
|||
|
|||
public SlotAttribute(int mSlotId, Binding mImplicitBinding, float defaultX, float defaultY, float defaultZ, float defaultW) |
|||
{ |
|||
slotId = mSlotId; |
|||
binding = mImplicitBinding; |
|||
defaultValue = new Vector4(defaultX, defaultY, defaultZ, defaultW); |
|||
} |
|||
} |
|||
|
|||
protected static MethodInfo GetMethodInfo(LambdaExpression expression) |
|||
{ |
|||
MethodCallExpression outermostExpression = expression.Body as MethodCallExpression; |
|||
|
|||
if (outermostExpression == null) |
|||
{ |
|||
throw new ArgumentException("Invalid Expression. Expression should consist of a Method call only."); |
|||
} |
|||
|
|||
return outermostExpression.Method; |
|||
} |
|||
|
|||
protected abstract MethodInfo GetFunctionToConvert(); |
|||
|
|||
private static SlotValueType ConvertTypeToSlotValueType(ParameterInfo p) |
|||
{ |
|||
Type t = p.ParameterType; |
|||
if (p.ParameterType.IsByRef) |
|||
t = p.ParameterType.GetElementType(); |
|||
|
|||
if (t == typeof(Vector1)) |
|||
{ |
|||
return SlotValueType.Vector1; |
|||
} |
|||
if (t == typeof(Vector2)) |
|||
{ |
|||
return SlotValueType.Vector2; |
|||
} |
|||
if (t == typeof(Vector3)) |
|||
{ |
|||
return SlotValueType.Vector3; |
|||
} |
|||
if (t == typeof(Vector4)) |
|||
{ |
|||
return SlotValueType.Vector4; |
|||
} |
|||
if (t == typeof(Texture2D)) |
|||
{ |
|||
return SlotValueType.Texture2D; |
|||
} |
|||
if (t == typeof(SamplerState)) |
|||
{ |
|||
return SlotValueType.SamplerState; |
|||
} |
|||
if (t == typeof(DynamicDimensionVector)) |
|||
{ |
|||
return SlotValueType.Dynamic; |
|||
} |
|||
if (t == typeof(Matrix4x4)) |
|||
{ |
|||
return SlotValueType.Matrix4; |
|||
} |
|||
throw new ArgumentException("Unsupported type " + t); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
var method = GetFunctionToConvert(); |
|||
|
|||
if (method == null) |
|||
throw new ArgumentException("Mapped method is null on node" + this); |
|||
|
|||
if (method.ReturnType != typeof(string)) |
|||
throw new ArgumentException("Mapped function should return string"); |
|||
|
|||
// validate no duplicates
|
|||
var slotAtributes = method.GetParameters().Select(GetSlotAttribute).ToList(); |
|||
if (slotAtributes.Any(x => x == null)) |
|||
throw new ArgumentException("Missing SlotAttribute on " + method.Name); |
|||
|
|||
if (slotAtributes.GroupBy(x => x.slotId).Any(x => x.Count() > 1)) |
|||
throw new ArgumentException("Duplicate SlotAttribute on " + method.Name); |
|||
|
|||
List<MaterialSlot> slots = new List<MaterialSlot>(); |
|||
foreach (var par in method.GetParameters()) |
|||
{ |
|||
var attribute = GetSlotAttribute(par); |
|||
|
|||
slots.Add(MaterialSlot.CreateMaterialSlot(ConvertTypeToSlotValueType(par), attribute.slotId, par.Name, par.Name, par.IsOut ? SlotType.Output : SlotType.Input, |
|||
attribute.defaultValue ?? Vector4.zero, hidden: attribute.hidden)); |
|||
|
|||
m_Slots.Add(attribute); |
|||
} |
|||
foreach (var slot in slots) |
|||
{ |
|||
AddSlot(slot); |
|||
} |
|||
RemoveSlotsNameNotMatching(slots.Select(x => x.id)); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var outSlot in GetOutputSlots<MaterialSlot>()) |
|||
{ |
|||
visitor.AddShaderChunk(GetParamTypeName(outSlot) + " " + GetVariableNameForSlot(outSlot.id) + ";", true); |
|||
} |
|||
|
|||
string call = GetFunctionName() + "("; |
|||
bool first = true; |
|||
foreach (var arg in GetSlots<MaterialSlot>().OrderBy(x => x.id)) |
|||
{ |
|||
if (!first) |
|||
{ |
|||
call += ", "; |
|||
} |
|||
first = false; |
|||
|
|||
if (arg.isInputSlot) |
|||
{ |
|||
var inEdges = owner.GetEdges(arg.slotReference); |
|||
if (!inEdges.Any()) |
|||
{ |
|||
var info = m_Slots.FirstOrDefault(x => x.slotId == arg.id); |
|||
if (info != null) |
|||
{ |
|||
var bindingInfo = info.binding; |
|||
if (bindingInfo != Binding.None) |
|||
{ |
|||
call += BindChannelToShaderName(bindingInfo); |
|||
continue; |
|||
} |
|||
} |
|||
} |
|||
|
|||
call += GetSlotValue(arg.id, generationMode); |
|||
} |
|||
else |
|||
call += GetVariableNameForSlot(arg.id); |
|||
} |
|||
call += ");"; |
|||
|
|||
visitor.AddShaderChunk(call, true); |
|||
} |
|||
|
|||
private string GetParamTypeName(MaterialSlot slot) |
|||
{ |
|||
return ConvertConcreteSlotValueTypeToString(precision, slot.concreteValueType); |
|||
} |
|||
|
|||
private string GetFunctionName() |
|||
{ |
|||
var function = GetFunctionToConvert(); |
|||
return function.Name + "_" + (function.IsStatic ? string.Empty : GuidEncoder.Encode(guid) + "_") + precision; |
|||
} |
|||
|
|||
private string GetFunctionHeader() |
|||
{ |
|||
string header = "void " + GetFunctionName() + "("; |
|||
|
|||
var first = true; |
|||
foreach (var slot in GetSlots<MaterialSlot>().OrderBy(x => x.id)) |
|||
{ |
|||
if (!first) |
|||
header += ", "; |
|||
|
|||
first = false; |
|||
|
|||
if (slot.isOutputSlot) |
|||
header += "out "; |
|||
|
|||
header += GetParamTypeName(slot) + " " + slot.shaderOutputName; |
|||
} |
|||
|
|||
header += ")"; |
|||
return header; |
|||
} |
|||
|
|||
private static object GetDefault(Type type) |
|||
{ |
|||
return type.IsValueType ? Activator.CreateInstance(type) : null; |
|||
} |
|||
|
|||
private string GetFunctionBody(MethodInfo info) |
|||
{ |
|||
var args = new List<object>(); |
|||
foreach (var param in info.GetParameters()) |
|||
args.Add(GetDefault(param.ParameterType)); |
|||
|
|||
var result = info.Invoke(this, args.ToArray()) as string; |
|||
|
|||
if (string.IsNullOrEmpty(result)) |
|||
return string.Empty; |
|||
|
|||
result = result.Replace("{precision}", precision.ToString()); |
|||
foreach (var slot in GetSlots<MaterialSlot>()) |
|||
{ |
|||
var toReplace = string.Format("{{slot{0}dimension}}", slot.id); |
|||
var replacement = GetSlotDimension(slot.concreteValueType); |
|||
result = result.Replace(toReplace, replacement); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
public virtual void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string function = GetFunctionHeader() + GetFunctionBody(GetFunctionToConvert()); |
|||
visitor.AddShaderChunk(function, true); |
|||
} |
|||
|
|||
private bool NodeRequiresBinding(Binding channel) |
|||
{ |
|||
foreach (var slot in GetSlots<MaterialSlot>()) |
|||
{ |
|||
if (SlotRequiresBinding(channel, slot)) |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
private bool SlotRequiresBinding(Binding channel, [NotNull] MaterialSlot slot) |
|||
{ |
|||
if (slot.isOutputSlot) |
|||
return false; |
|||
|
|||
var inEdges = owner.GetEdges(slot.slotReference); |
|||
if (inEdges.Any()) |
|||
return false; |
|||
|
|||
var slotAttr = m_Slots.FirstOrDefault(x => x.slotId == slot.id); |
|||
if (slotAttr != null && slotAttr.binding == channel) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private static SlotAttribute GetSlotAttribute([NotNull] ParameterInfo info) |
|||
{ |
|||
var attrs = info.GetCustomAttributes(typeof(SlotAttribute), false).OfType<SlotAttribute>().ToList(); |
|||
return attrs.FirstOrDefault(); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
if (NodeRequiresBinding(Binding.ObjectSpaceNormal)) |
|||
binding |= NeededCoordinateSpace.Object; |
|||
if (NodeRequiresBinding(Binding.ViewSpaceNormal)) |
|||
binding |= NeededCoordinateSpace.View; |
|||
if (NodeRequiresBinding(Binding.WorldSpaceNormal)) |
|||
binding |= NeededCoordinateSpace.World; |
|||
if (NodeRequiresBinding(Binding.TangentSpaceNormal)) |
|||
binding |= NeededCoordinateSpace.Tangent; |
|||
|
|||
return binding; |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
switch (channel) |
|||
{ |
|||
case UVChannel.uv0: |
|||
return NodeRequiresBinding(Binding.MeshUV0); |
|||
case UVChannel.uv1: |
|||
return NodeRequiresBinding(Binding.MeshUV1); |
|||
case UVChannel.uv2: |
|||
return NodeRequiresBinding(Binding.MeshUV2); |
|||
case UVChannel.uv3: |
|||
return NodeRequiresBinding(Binding.MeshUV3); |
|||
default: |
|||
throw new ArgumentOutOfRangeException("channel", channel, null); |
|||
} |
|||
} |
|||
|
|||
public bool RequiresScreenPosition() |
|||
{ |
|||
return NodeRequiresBinding(Binding.ScreenPosition); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
if (NodeRequiresBinding(Binding.ObjectSpaceViewDirection)) |
|||
binding |= NeededCoordinateSpace.Object; |
|||
if (NodeRequiresBinding(Binding.ViewSpaceViewDirection)) |
|||
binding |= NeededCoordinateSpace.View; |
|||
if (NodeRequiresBinding(Binding.WorldSpaceViewDirection)) |
|||
binding |= NeededCoordinateSpace.World; |
|||
if (NodeRequiresBinding(Binding.TangentSpaceNormal)) |
|||
binding |= NeededCoordinateSpace.Tangent; |
|||
|
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresPosition() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
if (NodeRequiresBinding(Binding.ObjectSpacePosition)) |
|||
binding |= NeededCoordinateSpace.Object; |
|||
if (NodeRequiresBinding(Binding.ViewSpacePosition)) |
|||
binding |= NeededCoordinateSpace.View; |
|||
if (NodeRequiresBinding(Binding.WorldSpacePosition)) |
|||
binding |= NeededCoordinateSpace.World; |
|||
if (NodeRequiresBinding(Binding.TangentSpacePosition)) |
|||
binding |= NeededCoordinateSpace.Tangent; |
|||
|
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
if (NodeRequiresBinding(Binding.ObjectSpaceTangent)) |
|||
binding |= NeededCoordinateSpace.Object; |
|||
if (NodeRequiresBinding(Binding.ViewSpaceTangent)) |
|||
binding |= NeededCoordinateSpace.View; |
|||
if (NodeRequiresBinding(Binding.WorldSpaceTangent)) |
|||
binding |= NeededCoordinateSpace.World; |
|||
if (NodeRequiresBinding(Binding.TangentSpaceTangent)) |
|||
binding |= NeededCoordinateSpace.Tangent; |
|||
|
|||
return binding; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
var binding = NeededCoordinateSpace.None; |
|||
if (NodeRequiresBinding(Binding.ObjectSpaceBitangent)) |
|||
binding |= NeededCoordinateSpace.Object; |
|||
if (NodeRequiresBinding(Binding.ViewSpaceBitangent)) |
|||
binding |= NeededCoordinateSpace.View; |
|||
if (NodeRequiresBinding(Binding.WorldSpaceBitangent)) |
|||
binding |= NeededCoordinateSpace.World; |
|||
if (NodeRequiresBinding(Binding.TangentSpaceBitangent)) |
|||
binding |= NeededCoordinateSpace.Tangent; |
|||
|
|||
return binding; |
|||
} |
|||
|
|||
public bool RequiresVertexColor() |
|||
{ |
|||
return NodeRequiresBinding(Binding.VertexColor); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue