浏览代码
Merge branch 'node-validation' of https://github.com/Unity-Technologies/ShaderGraph into node-validation
/main
Merge branch 'node-validation' of https://github.com/Unity-Technologies/ShaderGraph into node-validation
/main
当前提交
11e072f9
共有 98 个文件被更改,包括 2554 次插入 和 1620 次删除
-
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
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
-
493MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerStateShaderProperty.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableTexture.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
-
27MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Art/Filters/ConvolutionFilterNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/GradientNodeOld.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/SamplerStateNode.cs
-
45MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
14MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ProjectSpecificMasterNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
-
219MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/TextureNode.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
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs.meta
-
58MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.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
-
439MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
81MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/Gradient2DNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/Gradient2DNode.cs.meta
-
156MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/GradientAssetNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/GradientAssetNode.cs.meta
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete.meta
-
67MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/TextureAssetNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/TextureAssetNode.cs.meta
-
55MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/TextureControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/TextureControl.cs.meta
-
34MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc
-
9MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc.meta
-
507MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/HLSLNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/GradientNodeOld.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient/GradientNodeOld.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/TextureNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/TextureLODNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/CubemapNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/SamplerAssetNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/SamplerAssetNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/TextureNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/CubemapNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete/TextureLODNode.cs
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: |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class GradientMaterialSlot : MaterialSlot |
|||
{ |
|||
public GradientMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public GradientMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
public static readonly string DefaultGradientName = "ShaderGraph_DefaultGradient()"; |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Gradient; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Gradient; } } |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
} |
|||
|
|||
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 DefaultGradientName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0aac1b4e9fc8a1e4999e9069cf862832 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class GradientShaderProperty : AbstractShaderProperty<Gradient> |
|||
{ |
|||
[SerializeField] |
|||
private bool m_Modifiable = true; |
|||
|
|||
public GradientShaderProperty() |
|||
{ |
|||
value = new Gradient(); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Gradient; } |
|||
} |
|||
|
|||
public bool modifiable |
|||
{ |
|||
get { return m_Modifiable; } |
|||
set { m_Modifiable = value; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString() |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override string GetInlinePropertyDeclarationString() |
|||
{ |
|||
return "Gradient ShaderGraph_DefaultGradient;"; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return new PreviewProperty() |
|||
{ |
|||
m_Name = referenceName, |
|||
m_PropType = PropertyType.Gradient |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 186ecc17664ca614d9663a3fa18dede9 |
|||
timeCreated: 1505346949 |
|
|||
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 struct Gradient |
|||
{} |
|||
|
|||
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(Gradient)) |
|||
{ |
|||
return SlotValueType.Gradient; |
|||
} |
|||
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.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Gradient/Gradient 2D")] |
|||
public class Gradient2DNode : CodeFunctionNode, IGeneratesBodyCode |
|||
{ |
|||
public Gradient2DNode() |
|||
{ |
|||
name = "Gradient 2D"; |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_Gradient2D", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
//visitor.AddShaderChunk("Gradient ShaderGraph_DefaultGradient;", true);
|
|||
//visitor.AddShaderChunk("DefaultGradient(ShaderGraph_DefaultGradient);", true);
|
|||
|
|||
static string Unity_Gradient2D( |
|||
[Slot(0, Binding.None)] Gradient Gradient, |
|||
[Slot(1, Binding.None)] Vector1 Time, |
|||
[Slot(2, Binding.None)] out Vector4 Out) |
|||
{ |
|||
Out = Vector4.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
int colorKey1 = 0; |
|||
int colorKey2 = Gradient.colorsLength-1; |
|||
|
|||
for(int c1 = 0; c1 < Gradient.colorsLength; c1++) |
|||
{ |
|||
if(Gradient.colors[c1].w <= Time) |
|||
colorKey1 = c1; |
|||
else |
|||
break; |
|||
} |
|||
for(int c2 = Gradient.colorsLength-1; c2 >= 0; c2--) |
|||
{ |
|||
if(Gradient.colors[c2].w >= Time) |
|||
colorKey2 = c2; |
|||
else |
|||
break; |
|||
} |
|||
|
|||
int alphaKey1 = 0; |
|||
int alphaKey2 = Gradient.alphasLength-1; |
|||
|
|||
for(int a1 = 0; a1 < Gradient.alphasLength; a1++) |
|||
{ |
|||
if(Gradient.alphas[a1].y <= Time) |
|||
alphaKey1 = a1; |
|||
else |
|||
break; |
|||
} |
|||
for(int a2 = Gradient.alphasLength-1; a2 >= 0; a2--) |
|||
{ |
|||
if(Gradient.alphas[a2].y >= Time) |
|||
alphaKey2 = a2; |
|||
else |
|||
break; |
|||
} |
|||
|
|||
float colorPos = (Time - Gradient.colors[colorKey1].w) / (Gradient.colors[colorKey2].w - Gradient.colors[colorKey1].w); |
|||
float3 color = lerp(Gradient.colors[colorKey1].rgb, Gradient.colors[colorKey2].rgb, colorPos); |
|||
float alphaPos = (Time - Gradient.alphas[alphaKey1].y) / (Gradient.alphas[alphaKey2].y - Gradient.alphas[alphaKey1].y); |
|||
float alpha = lerp(Gradient.alphas[alphaKey1].r, Gradient.alphas[alphaKey2].r, alphaPos); |
|||
Out = float4(color, alpha); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a74d6bcb761144a2492e3c46e09d2689 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Gradient/Gradient Asset")] |
|||
public class GradientAssetNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
[SerializeField] |
|||
private float m_Value; |
|||
|
|||
public const int OutputSlotId = 0; |
|||
private const string kOutputSlotName = "Out"; |
|||
|
|||
public GradientAssetNode() |
|||
{ |
|||
name = "Gradient Asset"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
Gradient m_Gradient = new Gradient(); |
|||
|
|||
[SerializeField] |
|||
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), }; |
|||
|
|||
[SerializeField] |
|||
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) }; |
|||
|
|||
[GradientControl("")] |
|||
public Gradient gradient |
|||
{ |
|||
get |
|||
{ |
|||
return m_Gradient; |
|||
} |
|||
set |
|||
{ |
|||
var scope = ModificationScope.Nothing; |
|||
|
|||
var currentColorKeys = m_Gradient.colorKeys; |
|||
var currentAlphaKeys = m_Gradient.alphaKeys; |
|||
|
|||
var newColorKeys = value.colorKeys; |
|||
var newAlphaKeys = value.alphaKeys; |
|||
|
|||
if (currentColorKeys.Length != newColorKeys.Length || currentAlphaKeys.Length != newAlphaKeys.Length) |
|||
{ |
|||
scope = scope < ModificationScope.Graph ? ModificationScope.Graph : scope; |
|||
} |
|||
else |
|||
{ |
|||
for (var i = 0; i < currentColorKeys.Length; i++) |
|||
{ |
|||
if (currentColorKeys[i].color != newColorKeys[i].color || Mathf.Abs(currentColorKeys[i].time - newColorKeys[i].time) > 1e-9) |
|||
scope = scope < ModificationScope.Node ? ModificationScope.Node : scope; |
|||
} |
|||
|
|||
for (var i = 0; i < currentAlphaKeys.Length; i++) |
|||
{ |
|||
if (Mathf.Abs(currentAlphaKeys[i].alpha - newAlphaKeys[i].alpha) > 1e-9 || Mathf.Abs(currentAlphaKeys[i].time - newAlphaKeys[i].time) > 1e-9) |
|||
scope = scope < ModificationScope.Node ? ModificationScope.Node : scope; |
|||
} |
|||
} |
|||
|
|||
if (scope > ModificationScope.Nothing) |
|||
{ |
|||
gradient.SetKeys(newColorKeys, newAlphaKeys); |
|||
if (onModified != null) |
|||
onModified(this, scope); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void OnAfterDeserialize() |
|||
{ |
|||
base.OnAfterDeserialize(); |
|||
m_Gradient = new Gradient(); |
|||
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray(); |
|||
var alphaKeys = m_SerializableAlphaKeys.Select(k => new GradientAlphaKey(k.x, k.y)).ToArray(); |
|||
m_SerializableAlphaKeys = null; |
|||
m_SerializableColorKeys = null; |
|||
m_Gradient.SetKeys(colorKeys, alphaKeys); |
|||
} |
|||
|
|||
public override void OnBeforeSerialize() |
|||
{ |
|||
base.OnBeforeSerialize(); |
|||
m_SerializableColorKeys = gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray(); |
|||
m_SerializableAlphaKeys = gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray(); |
|||
} |
|||
|
|||
public override bool hasPreview { get { return false; } } |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new GradientMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output,0)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("Gradient " + GetVariableNameForNode() + ";", true); |
|||
visitor.AddShaderChunk(string.Format("Unity_{0} ({0});", GetVariableNameForNode()), true); |
|||
} |
|||
|
|||
string GetColorKey(int index, Color color, float time) |
|||
{ |
|||
return string.Format("g.colors[{0}] = float4({1}, {2}, {3}, {4});", index, color.r, color.g, color.b, time); |
|||
} |
|||
|
|||
string GetAlphaKey(int index, float alpha, float time) |
|||
{ |
|||
return string.Format("g.alphas[{0}] = float2({1}, {2});", index, alpha, time); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string[] colors = new string[8]; |
|||
for(int i = 0; i < colors.Length; i++) |
|||
colors[i] = string.Format("g.colors[{0}] = float4(0, 0, 0, 0);", i.ToString()); |
|||
for(int i = 0; i < m_Gradient.colorKeys.Length; i++) |
|||
colors[i] = GetColorKey(i, m_Gradient.colorKeys[i].color, m_Gradient.colorKeys[i].time); |
|||
|
|||
string[] alphas = new string[8]; |
|||
for(int i = 0; i < colors.Length; i++) |
|||
alphas[i] = string.Format("g.alphas[{0}] = float2(0, 0);", i.ToString()); |
|||
for(int i = 0; i < m_Gradient.alphaKeys.Length; i++) |
|||
alphas[i] = GetAlphaKey(i, m_Gradient.alphaKeys[i].alpha, m_Gradient.alphaKeys[i].time); |
|||
|
|||
visitor.AddShaderChunk(string.Format("void Unity_{0} (out Gradient Out)", GetVariableNameForNode()), true); |
|||
visitor.AddShaderChunk("{", true); |
|||
visitor.AddShaderChunk("Gradient g;", true); |
|||
visitor.AddShaderChunk("g.type = 0;", true); |
|||
visitor.AddShaderChunk(string.Format("g.colorsLength = {0};", m_Gradient.colorKeys.Length), true); |
|||
visitor.AddShaderChunk(string.Format("g.alphasLength = {0};", m_Gradient.alphaKeys.Length), true); |
|||
|
|||
for(int i = 0; i < colors.Length; i++) |
|||
visitor.AddShaderChunk(colors[i], true); |
|||
|
|||
for(int i = 0; i < alphas.Length; i++) |
|||
visitor.AddShaderChunk(alphas[i], true); |
|||
|
|||
visitor.AddShaderChunk("Out = g;", true); |
|||
visitor.AddShaderChunk("}", true); |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
return GetVariableNameForNode(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8a8144c53ee5f4f479dc46b7c8eabc78 |
|||
timeCreated: 1445864587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 394a8fe944cfd6b488bf5491e4622c7b |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Texture/Texture Asset")] |
|||
public class TextureAssetNode : AbstractMaterialNode |
|||
{ |
|||
public const int OutputSlotId = 0; |
|||
|
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public TextureAssetNode() |
|||
{ |
|||
name = "Texture Asset"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Texture2DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
[SerializeField] |
|||
private SerializableTexture m_Texture = new SerializableTexture(); |
|||
|
|||
[TextureControl("")] |
|||
public Texture texture |
|||
{ |
|||
get { return m_Texture.texture; } |
|||
set |
|||
{ |
|||
if (m_Texture.texture == value) |
|||
return; |
|||
m_Texture.texture = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
properties.AddShaderProperty(new TextureShaderProperty() |
|||
{ |
|||
overrideReferenceName = GetVariableNameForSlot(OutputSlotId), |
|||
generatePropertyBlock = true, |
|||
value = m_Texture, |
|||
modifiable = false |
|||
}); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(new PreviewProperty |
|||
{ |
|||
m_Name = GetVariableNameForSlot(OutputSlotId), |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = texture |
|||
}); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9c629b78a2ec57749ab4f76f4f42f423 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class TextureControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public TextureControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new TextureControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class TextureControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
public TextureControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Texture)) |
|||
throw new ArgumentException("Property must be of type Texture.", "propertyInfo"); |
|||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); |
|||
|
|||
if (!string.IsNullOrEmpty(label)) |
|||
Add(new Label(label)); |
|||
|
|||
var textureField = new ObjectField { value = (Texture) m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture) }; |
|||
textureField.OnValueChanged(OnChange); |
|||
Add(textureField); |
|||
} |
|||
|
|||
void OnChange(ChangeEvent<UnityEngine.Object> evt) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change"); |
|||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null); |
|||
Dirty(ChangeType.Repaint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 12334ec97337f32408251974c4077033 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Gradient Type |
|||
struct Gradient |
|||
{ |
|||
int type; |
|||
int colorsLength; |
|||
int alphasLength; |
|||
float4 colors[8]; |
|||
float2 alphas[8]; |
|||
}; |
|||
|
|||
Gradient ShaderGraph_DefaultGradient() |
|||
{ |
|||
Gradient g; |
|||
g.type = 0; |
|||
g.colorsLength = 2; |
|||
g.alphasLength = 2; |
|||
g.colors[0] = float4(0, 0, 0, 0); |
|||
g.colors[1] = float4(1, 1, 1, 1); |
|||
g.colors[2] = float4(0, 0, 0, 0); |
|||
g.colors[3] = float4(0, 0, 0, 0); |
|||
g.colors[4] = float4(0, 0, 0, 0); |
|||
g.colors[5] = float4(0, 0, 0, 0); |
|||
g.colors[6] = float4(0, 0, 0, 0); |
|||
g.colors[7] = float4(0, 0, 0, 0); |
|||
g.alphas[0] = float2(1, 0); |
|||
g.alphas[1] = float2(1, 1); |
|||
g.alphas[2] = float2(0, 0); |
|||
g.alphas[3] = float2(0, 0); |
|||
g.alphas[4] = float2(0, 0); |
|||
g.alphas[5] = float2(0, 0); |
|||
g.alphas[6] = float2(0, 0); |
|||
g.alphas[7] = float2(0, 0); |
|||
return g; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2a7388374397c47f1a598ae9ea3f2069 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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