浏览代码
Readd all existing nodes.
Readd all existing nodes.
Most nodes are now correct. Some still need UI work (texture). Missing some of the 'art' nodes still./main
Tim Cooper
9 年前
当前提交
da4824f7
共有 105 个文件被更改,包括 2981 次插入 和 27 次删除
-
6MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
-
9MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs
-
14MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs
-
44MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs.meta
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs.meta
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs.meta
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs.meta
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs.meta
-
69MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs.meta
-
32MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ClampNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ClampNode.cs.meta
-
62MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs.meta
-
109MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs.meta
-
33MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DotNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DotNode.cs.meta
-
32MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FresnelNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FresnelNode.cs.meta
-
74MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function1Input.cs.meta
-
131MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function3Input.cs.meta
-
83MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FunctionMultiInput.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FunctionMultiInput.cs.meta
-
96MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/KaleidoscopeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/KaleidoscopeNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LerpNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LerpNode.cs.meta
-
101MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MandelbrotNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MandelbrotNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaxNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaxNode.cs.meta
-
16MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MinNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MinNode.cs.meta
-
34MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs.meta
-
37MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs.meta
-
105MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PerlinNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PerlinNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs.meta
-
37MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs.meta
-
44MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinNode.cs.meta
-
32MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinTimeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinTimeNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs.meta
-
41MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphIOBaseNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphIOBaseNode.cs.meta
-
79MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphInputsNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphInputsNode.cs.meta
-
208MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphNode.cs.meta
-
22MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphOutputsNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubGraphOutputsNode.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs.meta
-
63MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs.meta
-
204MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs.meta
-
56MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs.meta
-
33MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UnpackNormalNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UnpackNormalNode.cs.meta
-
66MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs.meta
-
66MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs.meta
-
66MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs
|
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(ColorNode))] |
|||
public class ColorNodeUI : ICustomNodeUi |
|||
{ |
|||
private ColorNode m_Node; |
|||
|
|||
public float GetNodeUiHeight(float width) |
|||
{ |
|||
return 2 * EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public GUIModificationType Render(Rect area) |
|||
{ |
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Node.color = EditorGUI.ColorField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), "Value", m_Node.color); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
return GUIModificationType.Repaint; |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
|
|||
public void SetNode(INode node) |
|||
{ |
|||
if (node is ColorNode) |
|||
m_Node = (ColorNode) node; |
|||
} |
|||
|
|||
public float GetNodeWidth() |
|||
{ |
|||
return 200; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1764879bbfb2621418d1c58fdf5b93fc |
|||
timeCreated: 1464957369 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(CombineNode))] |
|||
public class CombineNodeUI : AbstractMaterialNodeUI |
|||
{ |
|||
public float GetNodeUiHeight(float width) |
|||
{ |
|||
return base.GetNodeUiHeight(width) + EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override GUIModificationType Render(Rect area) |
|||
{ |
|||
var node = m_Node as CombineNode; |
|||
if (node == null) |
|||
return base.Render(area); |
|||
|
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
node.operation = (CombineNode.Operation)EditorGUI.EnumPopup(area, node.operation); |
|||
|
|||
var toReturn = GUIModificationType.None; |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
toReturn = GUIModificationType.Repaint; |
|||
} |
|||
|
|||
area.y += 2 * EditorGUIUtility.singleLineHeight; |
|||
area.height -= 2 * EditorGUIUtility.singleLineHeight; |
|||
toReturn |= base.Render(area); |
|||
return toReturn; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 699eabcc43767844f9558d3314df6b1b |
|||
timeCreated: 1464957369 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(Vector1Node))] |
|||
public class Vector1NodeUI : ICustomNodeUi |
|||
{ |
|||
private Vector1Node m_Node; |
|||
|
|||
public float GetNodeUiHeight(float width) |
|||
{ |
|||
return 2 * EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public GUIModificationType Render(Rect area) |
|||
{ |
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Node.value = EditorGUI.FloatField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), "Value", m_Node.value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
//TODO:tidy this shit.
|
|||
//EditorUtility.SetDirty(materialGraphOwner.owner);
|
|||
return GUIModificationType.Repaint; |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
|
|||
public void SetNode(INode node) |
|||
{ |
|||
if (node is Vector1Node) |
|||
m_Node = (Vector1Node) node; |
|||
} |
|||
|
|||
public float GetNodeWidth() |
|||
{ |
|||
return 200; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 384d8aee5b4f7be4986d433b2713a49a |
|||
timeCreated: 1464961768 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(Vector2Node))] |
|||
public class Vector2NodeUI : ICustomNodeUi |
|||
{ |
|||
private Vector2Node m_Node; |
|||
|
|||
public float GetNodeUiHeight(float width) |
|||
{ |
|||
return 2 * EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public GUIModificationType Render(Rect area) |
|||
{ |
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Node.value = EditorGUI.Vector2Field(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), "Value", m_Node.value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
//TODO:tidy this shit.
|
|||
//EditorUtility.SetDirty(materialGraphOwner.owner);
|
|||
return GUIModificationType.Repaint; |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
|
|||
public void SetNode(INode node) |
|||
{ |
|||
if (node is Vector2Node) |
|||
m_Node = (Vector2Node) node; |
|||
} |
|||
|
|||
public float GetNodeWidth() |
|||
{ |
|||
return 200; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9d3c3a11d71fc154d8d6c3c5a6ebfdfe |
|||
timeCreated: 1464961768 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(Vector3Node))] |
|||
public class Vector3NodeUI : ICustomNodeUi |
|||
{ |
|||
private Vector3Node m_Node; |
|||
|
|||
public float GetNodeUiHeight(float width) |
|||
{ |
|||
return 2 * EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public GUIModificationType Render(Rect area) |
|||
{ |
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Node.value = EditorGUI.Vector3Field(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), "Value", m_Node.value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
//TODO:tidy this shit.
|
|||
//EditorUtility.SetDirty(materialGraphOwner.owner);
|
|||
return GUIModificationType.Repaint; |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
|
|||
public void SetNode(INode node) |
|||
{ |
|||
if (node is Vector3Node) |
|||
m_Node = (Vector3Node) node; |
|||
} |
|||
|
|||
public float GetNodeWidth() |
|||
{ |
|||
return 200; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fb53610f494711741a3c0f528c5e9d87 |
|||
timeCreated: 1464961769 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Absolute Node")] |
|||
class AbsoluteNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public AbsoluteNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "AbsoluteNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_absolute_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_absolute_" + precision + " (" + precision + outputDimension + " arg1)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return abs(arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4b496ffd32c22d94bb525897d152da05 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Art/Blend Node")] |
|||
public class BlendNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public BlendNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "BlendNode"; |
|||
} |
|||
|
|||
public enum Operation |
|||
{ |
|||
Normal, |
|||
Additive, |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Operation m_Operation; |
|||
[SerializeField] |
|||
private float m_Blend = 0.5f; |
|||
|
|||
private static readonly string[] kOpNames = |
|||
{ |
|||
"normal", |
|||
"add" |
|||
}; |
|||
|
|||
public Operation operation |
|||
{ |
|||
get { return m_Operation; } |
|||
set { m_Operation = value; } |
|||
} |
|||
|
|||
public float blend |
|||
{ |
|||
get { return m_Blend; } |
|||
set { m_Blend = value; } |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "unity_blend_" + kOpNames[(int)m_Operation] + "_" + precision; } |
|||
protected override string GetFunctionCallBody(string input1Value, string input2Value) |
|||
{ |
|||
return GetFunctionName() + "(" + input1Value + ", " + input2Value + ", " + m_Blend + ")"; |
|||
} |
|||
|
|||
protected void AddOperationBody(ShaderGenerator visitor, string name, string body, string precision) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk("inline " + precision + outputDimension +" unity_blend_" + name + "_" + precision + " (" + precision + outputDimension + " arg1, " + precision + outputDimension + " arg2, " + precision + " blend)", false); |
|||
outputString.AddShaderChunk("{", false); outputString.Indent(); |
|||
outputString.AddShaderChunk(body, false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Normal], "return lerp(arg1, arg2, blend);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Additive], "return (arg1 + arg2) * blend;", precision); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 909ffbb62e82bfb4abbeeb93022c6e9b |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Clamp Node")] |
|||
public class ClampNode : Function3Input, IGeneratesFunction |
|||
{ |
|||
public ClampNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "ClampNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_clamp_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_clamp_" + precision + " (" + precision + "4 arg1, " + precision + "4 minval, " + precision + "4 maxval)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return clamp(arg1, minval, maxval);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b58e88ce87f05b241b7dc5d9a31bac69 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Color Node")] |
|||
public class ColorNode : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private Color m_Color; |
|||
|
|||
private const string kOutputSlotName = "Color"; |
|||
|
|||
public ColorNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "ColorNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] {kOutputSlotName}); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Color; } |
|||
} |
|||
|
|||
public Color color |
|||
{ |
|||
get { return m_Color; } |
|||
set { m_Color = value; } |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk("float4 " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
// we only need to generate node code if we are using a constant... otherwise we can just refer to the property :)
|
|||
if (exposed || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Color, |
|||
m_Color = m_Color |
|||
}; |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 325c0e24c20746345a5f90dc201973f8 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Art/Combine Node")] |
|||
public class CombineNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public CombineNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "CombineNode"; |
|||
} |
|||
|
|||
// Based on information from:
|
|||
// http://photoblogstop.com/photoshop/photoshop-blend-modes-explained
|
|||
// http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/
|
|||
// http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
|
|||
// http://dunnbypaul.net/blends/
|
|||
public enum Operation |
|||
{ |
|||
Darken, |
|||
Multiply, |
|||
ColorBurn, |
|||
LinearBurn, |
|||
// TODO: DarkerColor (Darken, but based on luminosity)
|
|||
Lighten, |
|||
Screen, |
|||
ColorDodge, |
|||
LinearDodge, |
|||
// TODO: LighterColor (Lighten, but based on luminosity)
|
|||
Overlay, |
|||
SoftLight, |
|||
HardLight, |
|||
VividLight, |
|||
LinearLight, |
|||
PinLight, |
|||
HardMix, |
|||
Difference, |
|||
Exclusion, |
|||
Subtract, |
|||
Divide, |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Operation m_Operation; |
|||
|
|||
private static readonly string[] kOpNames = { |
|||
"darken", "mul", "cburn", "lburn", |
|||
"lighten", "screen", "cdodge", "ldodge", |
|||
"overlay", "softl", "hardl", "vividl", "linearl", "pinl", "hardmix", |
|||
"diff", "excl", "sub", "div" |
|||
}; |
|||
|
|||
public Operation operation |
|||
{ |
|||
get { return m_Operation; } |
|||
set { m_Operation = value; } |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "unity_combine_" + kOpNames[(int)m_Operation] + "_" + precision; } |
|||
|
|||
protected void AddOperationBody(ShaderGenerator visitor, string combineName, string body, string combinePrecision) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk("inline " + combinePrecision + "4 unity_combine_" + combineName + "_" + combinePrecision + " (" + combinePrecision + "4 arg1, " + combinePrecision + "4 arg2)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(body, false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
// Darken group
|
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Darken], "return min(arg1, arg2);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Multiply], "return arg1 * arg2;", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.ColorBurn], "return 1 - (1-arg1)/(arg2+1e-5);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.LinearBurn], "return arg1 + arg2 - 1;", precision); |
|||
|
|||
// Lighten group
|
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Lighten], "return max(arg1, arg2);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Screen], "return 1- (1-arg1) * (1-arg2);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.ColorDodge], "return arg1/(1-arg2+1e-5);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.LinearDodge], "return arg1 + arg2;", precision); |
|||
|
|||
// Contrast group
|
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Overlay], "return (arg1 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.SoftLight], |
|||
"return (1-arg1)*arg1*arg2 + arg1*(1- (1-arg1)*(1-arg2));", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.HardLight], "return (arg2 < 0.5)? arg1*arg2*2: 1-(1-arg1)*(1-arg2)*2;", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.VividLight], |
|||
"return (arg2 < 0.5)? 1- (1-arg1)/(2*arg2+1e-5): arg1/(1-2*(arg2-0.5)+1e-5);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.LinearLight], "return (arg2 < 0.5)? arg1+(2*arg2)-1: arg1+2*(arg2-0.5);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.PinLight], "return (arg2 < 0.5)? min(arg1, 2*arg2): max(arg1, 2*(arg2-0.5));", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.HardMix], "return (arg2 < 1-arg1)? " + precision + "(0):" + precision + "(1);", precision); |
|||
|
|||
// Inversion group
|
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Difference], "return abs(arg2-arg1);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Exclusion], "return arg1 + arg2 - arg1*arg2*2;", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Subtract], "return max(arg2-arg1, 0.0);", precision); |
|||
AddOperationBody(visitor, kOpNames[(int)Operation.Divide], "return arg1 / (arg2+1e-5);", precision); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3738e97908dea1f4bbc5e5a7cf562ecc |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Div Node")] |
|||
public class DivNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public DivNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "DivNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_div_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_div_" + precision + " (" + precision + "4 arg1, " + precision + "4 arg2)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 / arg2;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8e9d13e64300d6942ad51651d39f9ac6 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Dot Node")] |
|||
public class DotNode : Function2Input |
|||
{ |
|||
public DotNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "DotNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "dot"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(GetInputSlot1Name(), GetInputSlot1Name(), SlotType.Input, 0, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(GetInputSlot2Name(), GetInputSlot2Name(), SlotType.Input, 1, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(GetOutputSlotName(), GetOutputSlotName(), SlotType.Output, 2, SlotValueType.Vector1, Vector4.zero); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 97e1d998eea5d644095671979ecf2e54 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Fresnel Node")] |
|||
class FresnelNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public FresnelNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "FresnelNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "unity_fresnel_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
|
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_fresnel_" + precision + " (" + precision + "4 arg1, " + precision + "4 arg2)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return (1.0 - dot (normalize (arg1.xyz), normalize (arg2.xyz))).xxxx;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 06ab35c1dfe05414787df3ea2772d507 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class Function1Input : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected Function1Input(IGraph owner) |
|||
: base(owner) |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected string[] validSlots |
|||
{ |
|||
get { return new[] {GetInputSlotName(), GetOutputSlotName()}; } |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(GetInputSlotName(), GetInputSlotName(), SlotType.Input, 0, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(GetOutputSlotName(), GetOutputSlotName(), SlotType.Output, 0, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlotName() {return "Input"; } |
|||
protected virtual string GetOutputSlotName() {return "Output"; } |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindMaterialOutputSlot(GetOutputSlotName()); |
|||
var inputSlot = FindMaterialInputSlot(GetInputSlotName()); |
|||
|
|||
if (inputSlot == null || outputSlot == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
var inputValue = GetSlotValue(inputSlot, generationMode); |
|||
visitor.AddShaderChunk(precision + outputDimension + " " + GetOutputVariableNameForSlot(outputSlot) + " = " + GetFunctionCallBody(inputValue) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ")"; |
|||
} |
|||
|
|||
public string outputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialOutputSlot(GetOutputSlotName()).concreteValueType); } |
|||
} |
|||
public string inputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialInputSlot(GetInputSlotName()).concreteValueType); } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e8ba3e80e4d9e947a9377e9e73fdca9 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class Function3Input : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
protected Function3Input(IGraph owner) |
|||
: base(owner) |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot1()); |
|||
AddSlot(GetInputSlot2()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected string[] validSlots |
|||
{ |
|||
get { return new[] {GetInputSlot1Name(), GetInputSlot2Name(), GetInputSlot3Name(), GetOutputSlotName()}; } |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(GetInputSlot1Name(), GetInputSlot1Name(), SlotType.Input, 0, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(GetInputSlot2Name(), GetInputSlot2Name(), SlotType.Input, 1, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected MaterialSlot GetInputSlot3() |
|||
{ |
|||
return new MaterialSlot(GetInputSlot3Name(), GetInputSlot3Name(), SlotType.Input, 2, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(GetOutputSlotName(), GetOutputSlotName(), SlotType.Output, 0, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlot1Name() |
|||
{ |
|||
return "Input1"; |
|||
} |
|||
|
|||
protected virtual string GetInputSlot2Name() |
|||
{ |
|||
return "Input2"; |
|||
} |
|||
|
|||
protected virtual string GetInputSlot3Name() |
|||
{ |
|||
return "Input3"; |
|||
} |
|||
|
|||
protected virtual string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name) |
|||
{ |
|||
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" |
|||
+ precision + input1Dimension + " " + arg1Name + ", " |
|||
+ precision + input2Dimension + " " + arg2Name + ", " |
|||
+ precision + input3Dimension + " " + arg3Name + ")"; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindMaterialOutputSlot(GetOutputSlotName()); |
|||
var inputSlot1 = FindMaterialInputSlot(GetInputSlot1Name()); |
|||
var inputSlot2 = FindMaterialInputSlot(GetInputSlot2Name()); |
|||
var inputSlot3 = FindMaterialInputSlot(GetInputSlot3Name()); |
|||
|
|||
if (inputSlot1 == null || inputSlot2 == null || inputSlot3 == null || outputSlot == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
string input1Value = GetSlotValue(inputSlot1, generationMode); |
|||
string input2Value = GetSlotValue(inputSlot2, generationMode); |
|||
string input3Value = GetSlotValue(inputSlot3, generationMode); |
|||
|
|||
visitor.AddShaderChunk(precision + outputDimension + " " + GetOutputVariableNameForSlot(outputSlot) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")"; |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string inputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ")"; |
|||
} |
|||
|
|||
public string outputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialOutputSlot(GetOutputSlotName()).concreteValueType); } |
|||
} |
|||
|
|||
public string input1Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialInputSlot(GetInputSlot1Name()).concreteValueType); } |
|||
} |
|||
|
|||
public string input2Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialInputSlot(GetInputSlot2Name()).concreteValueType); } |
|||
} |
|||
|
|||
public string input3Dimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindMaterialInputSlot(GetInputSlot3Name()).concreteValueType); } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e7d8fb926f570fb48b10d7d068d54123 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
/*public abstract class FunctionMultiInput : BaseMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "Output"; |
|||
private const string kBaseInputSlotName = "Input"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName)); |
|||
|
|||
AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(0))); |
|||
AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(1))); |
|||
} |
|||
|
|||
protected bool IsInputSlotConnected(int index) |
|||
{ |
|||
var inputSlot = GetValidInputSlots().FirstOrDefault(x => x.name == GetInputSlotName(index)); |
|||
if (inputSlot == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return false; |
|||
} |
|||
|
|||
return inputSlot.edges.Count > 0; |
|||
} |
|||
|
|||
private static string GetInputSlotName(int index) { return kBaseInputSlotName + (index); } |
|||
|
|||
public override void InputEdgeChanged(Edge e) |
|||
{ |
|||
base.InputEdgeChanged(e); |
|||
|
|||
int inputSlotCount = GetValidInputSlots().Count(); |
|||
|
|||
if (IsInputSlotConnected(inputSlotCount - 1)) |
|||
AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(inputSlotCount))); |
|||
else if (inputSlotCount > 2) |
|||
{ |
|||
var lastSlot = inputSlots.FirstOrDefault(x => x.name == GetInputSlotName(inputSlotCount - 1)); |
|||
if (lastSlot != null) |
|||
RemoveSlot(lastSlot); |
|||
} |
|||
} |
|||
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = outputSlots.FirstOrDefault(x => x.name == kOutputSlotName); |
|||
|
|||
if (outputSlot == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
var inputSlots = GetValidInputSlots(); |
|||
int inputSlotCount = inputSlots.Count(); |
|||
|
|||
// build up a list of the valid input connections
|
|||
var inputValues = new List<string>(inputSlotCount); |
|||
MaterialWindow.DebugMaterialGraph("Generating On Node: " + GetOutputVariableNameForNode() + " - Preview is: " + generationMode); |
|||
inputValues.AddRange(inputSlots.Select(inputSlot => GetSlotValue(inputSlot, generationMode))); |
|||
visitor.AddShaderChunk(precision + "4 " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(inputValues) + ";", true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(List<string> inputValues) |
|||
{ |
|||
string functionCall = inputValues[0]; |
|||
for (int q = 1; q < inputValues.Count; ++q) |
|||
functionCall = GetFunctionName() + " (" + functionCall + ", " + inputValues[q] + ")"; |
|||
return functionCall; |
|||
} |
|||
}*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 323a0eb1930dff241b4547716c8eb21f |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Kaleidoscope Node")] |
|||
class KaleidoscopeNode : BaseMaterialNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private int m_Iterations = 6; |
|||
|
|||
private const string kPointInputName = "Point"; |
|||
private const string kConstant1InputName = "Constant1"; |
|||
private const string kConstant2InputName = "Constant2"; |
|||
private const string kOutputSlotName = "Output"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "KaleidoscopeNode"; |
|||
base.OnCreate(); |
|||
// AddSlot(new Slot(SlotType.InputSlot, kPointInputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstant1InputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstant2InputName));
|
|||
//AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
|
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_kaleidoscope_" + precision + " (" + precision + "2 p, " + precision + "4 c1, " + precision + "4 c2, int iterations)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("c1 = c1 * 2 - 1;", false); |
|||
outputString.AddShaderChunk("c2 = c2 * 2 - 1;", false); |
|||
outputString.AddShaderChunk("for (int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("p = c1.xy + p * c1.zw + " + precision + "2(dot(p, c2.xy), dot(p, c2.zw));", false); |
|||
outputString.AddShaderChunk("if(p.x < p.y) p.xy = -p.yx;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return " + precision + "4(p, 1, 1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindOutputSlot(kOutputSlotName); |
|||
var pointInput = FindInputSlot(kPointInputName); |
|||
var constant1Input = FindInputSlot(kConstant1InputName); |
|||
var constant2Input = FindInputSlot(kConstant2InputName); |
|||
|
|||
if (outputSlot == null || pointInput == null || constant1Input == null || constant2Input == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
string pointInputValue = GetSlotValue(pointInput, generationMode); |
|||
string constant1InputValue = GetSlotValue(constant1Input, generationMode); |
|||
string constant2InputValue = GetSlotValue(constant2Input, generationMode); |
|||
|
|||
string outName = GetOutputVariableNameForSlot(outputSlot, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + outName + " = unity_kaleidoscope_" + precision + "(" + pointInputValue + ".xy, " + constant1InputValue + ", " + constant2InputValue + ", " + m_Iterations + ");", false); |
|||
} |
|||
|
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
|
|||
/*public override void NodeUI() |
|||
{ |
|||
base.NodeUI(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
} |
|||
*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: dfc00afcda39bfa4fbd9bd6176f53477 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Length Node")] |
|||
public class LengthNode : Function1Input |
|||
{ |
|||
public LengthNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "LengthNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "length"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 52afae1b1271e864c9c6965dc738c2dd |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Lerp Node")] |
|||
public class LerpNode : Function3Input, IGeneratesFunction |
|||
{ |
|||
public LerpNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "LerpNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_lerp_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk(GetFunctionPrototype("first", "second", "s"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return lerp(first, second, s);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a5622947be2d8cd48beb2362351ddf12 |
|||
timeCreated: 1444218016 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Mandelbrot Node")] |
|||
class MandelbrotNode : BaseMaterialNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private int m_Iterations = 6; |
|||
|
|||
private const string kPointInputName = "Point"; |
|||
private const string kConstantInputName = "Constant"; |
|||
private const string kOutputSlotName = "Output"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "MandelbrotNode"; |
|||
base.OnCreate(); |
|||
//AddSlot(new Slot(SlotType.InputSlot, kPointInputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstantInputName));
|
|||
//AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
|
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_mandelbrot_" + precision + " (" + precision + "2 p, " + precision + "2 c, float limit, float scale, int iterations)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + " zr = p.x * 4 - 2, zi = p.y * 4 - 2, dzr = 1, dzi = 0, r = 0, len2;", false); |
|||
outputString.AddShaderChunk("for (int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + " tmp1 = 2 * zr * zi + c.y; zr = zr * zr - zi * zi + c.x; zi = tmp1;", false); |
|||
outputString.AddShaderChunk(precision + " tmp2 = 2 * (dzr * zi + dzi * zr); dzr = 2 * (dzr * zr - dzi * zi) + 1; dzi = tmp2;", false); |
|||
outputString.AddShaderChunk("len2 = zr * zr + zi * zi;", false); |
|||
outputString.AddShaderChunk("if (len2 > 1000000 * limit) { r = n; break; }", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return scale * sqrt(len2 / (dzr * dzr + dzi * dzi)) * log(len2);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var validSlots = ListPool<Slot>.Get(); |
|||
GetValidInputSlots(validSlots); |
|||
|
|||
var outputSlot = outputSlots.FirstOrDefault(x => x.name == kOutputSlotName); |
|||
var pointInput = validSlots.FirstOrDefault(x => x.name == kPointInputName); |
|||
var constantInput = validSlots.FirstOrDefault(x => x.name == kConstantInputName); |
|||
|
|||
ListPool<Slot>.Release(validSlots); |
|||
|
|||
if (outputSlot == null || pointInput == null || constantInput == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
//TODO: This will break if there is NO input connected, use default in that case
|
|||
var pointProvider = pointInput.edges[0].fromSlot.node as BaseMaterialNode; |
|||
var pointName = pointProvider.GetOutputVariableNameForSlot(pointInput.edges[0].fromSlot, generationMode); |
|||
|
|||
var constantProvider = constantInput.edges[0].fromSlot.node as BaseMaterialNode; |
|||
var constantName = constantProvider.GetOutputVariableNameForSlot(constantInput.edges[0].fromSlot, generationMode); |
|||
|
|||
string outName = GetOutputVariableNameForSlot(outputSlot, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + outName + " = unity_mandelbrot_" + precision + "(" + pointName + ".xy, " + constantName + ".xy, " + constantName + ".z, " + constantName + ".w, " + m_Iterations + ");", false); |
|||
} |
|||
|
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
|
|||
/*public override void NodeUI() |
|||
{ |
|||
base.NodeUI(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 45896ba83118f8548bd9d2f9263bcde5 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Maximum Node")] |
|||
public class MaximumNode : Function2Input |
|||
{ |
|||
public MaximumNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "MaximumNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "max"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1de46e012f3608843978529b36704c2b |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Math/Minimum Node")] |
|||
public class MinimumNode : Function2Input |
|||
{ |
|||
public MinimumNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "MinimumNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "min"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 79ffed9a70f191f4c966a6eb3ae10d07 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Multiply Node")] |
|||
public class MultiplyNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public MultiplyNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "MultiplyNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_multiply_" + precision; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + outputDimension + " " + GetFunctionName() + " (" + precision + input1Dimension + " arg1, " + precision + input2Dimension + " arg2)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 * arg2;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 088fb5bde3ece0f4190136b3ab43f7c4 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Normal Node")] |
|||
public class NormalNode : AbstractMaterialNode |
|||
{ |
|||
public NormalNode(IGraph theOwner) : base(theOwner) |
|||
{ |
|||
name = "Normal"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector3, new Vector4(0,0,1,1))); |
|||
RemoveSlotsNameNotMatching(new[] {kOutputSlotName}); |
|||
} |
|||
|
|||
private const string kOutputSlotName = "Normal"; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get { return PreviewMode.Preview3D; } |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(MaterialSlot s) |
|||
{ |
|||
return "o.Normal"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5b34601661908b3499c4c5e2ecd61f75 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Normalize Node")] |
|||
class NormalizeNode : Function1Input |
|||
{ |
|||
public NormalizeNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "NormalizeNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "normalize"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7eb73d726827e2c41ae4d68018bc97e1 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine; |
|||
|
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Perlin Node")] |
|||
class PerlinNode : TextureNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
[SerializeField] |
|||
private int m_Iterations = 4; |
|||
|
|||
[SerializeField] |
|||
private float m_Decay = 0.5f; |
|||
|
|||
[SerializeField] |
|||
private float m_Frequency = 2.0f; |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "Perlin"; |
|||
base.OnCreate(); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_perlin_" + precision + " (" |
|||
+ "sampler2D textureID, " |
|||
+ "int iterations, " |
|||
+ precision + " decay, " |
|||
+ precision + " frequency, " |
|||
+ precision + "2 p" |
|||
+ ")", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + "4 sum = " + precision + "4(0, 0, 0, 0);", false); |
|||
outputString.AddShaderChunk(precision + " amp = 0.5;", false); |
|||
outputString.AddShaderChunk("for(int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("sum += amp * tex2D (textureID, p);", false); |
|||
outputString.AddShaderChunk("p *= frequency;", false); |
|||
outputString.AddShaderChunk("amp *= decay;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return sum;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
/* public override void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindOutputSlot(kOutputSlotName); |
|||
if (outputSlot == null) |
|||
return; |
|||
|
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var uvName = "IN.meshUV0"; |
|||
if (uvSlot.edges.Count > 0) |
|||
{ |
|||
var fromNode = uvSlot.edges[0].fromSlot.node as BaseMaterialNode; |
|||
uvName = fromNode.GetOutputVariableNameForSlot(uvSlot.edges[0].fromSlot, generationMode); |
|||
} |
|||
|
|||
string body = "unity_perlin_" + precision + "(" + GetPropertyName() + ", " + m_Iterations + ", " + m_Decay + ", " + m_Frequency + ", " + uvName + ".xy)"; |
|||
visitor.AddShaderChunk("float4 " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + body + ";", true); |
|||
} |
|||
* |
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
/* |
|||
public override float GetNodeUIHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override bool NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 8); |
|||
m_Decay = Slider("Decay", m_Decay, -1f, 1f); |
|||
m_Frequency = Slider("Frequency", m_Frequency, 0f, 5f); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 6388ec78711fae240b4d5c60bd70d36d |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Power Node")] |
|||
public class PowerNode : Function2Input |
|||
{ |
|||
public PowerNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "PowerNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "pow"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b2957c4e08e061444a7444a1a03fb584 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Quantize Node")] |
|||
class QuantizeNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public QuantizeNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "QuantizeNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_quantize_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_quantize_" + precision + " (" + precision + "4 input, " + precision + "4 stepsize)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return floor(input / stepsize) * stepsize;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4322ad8d0cd83df47afd741a6b97d57b |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Reflect Node")] |
|||
class ReflectNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public ReflectNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "ReflectNode"; |
|||
} |
|||
|
|||
protected override string GetInputSlot1Name() {return "Normal"; } |
|||
protected override string GetInputSlot2Name() {return "Direction"; } |
|||
protected override string GetOutputSlotName() {return "Reflection"; } |
|||
|
|||
protected override string GetFunctionName() {return "unity_reflect_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_reflect_" + precision + " (" + precision + "4 normal, " + precision + "4 direction)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + "3 vn = normalize(normal.xyz);", false); |
|||
outputString.AddShaderChunk(precision + "3 vd = normalize(direction.xyz);", false); |
|||
outputString.AddShaderChunk("return half4 (2 * dot(vn, vd) * vn - vd, 1.0);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6af2205640e32994db6fd7de8aebf1de |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Screen Pos Node")] |
|||
public class ScreenPosNode : AbstractMaterialNode, IGeneratesVertexToFragmentBlock |
|||
{ |
|||
public ScreenPosNode(IGraph theOwner) : base(theOwner) |
|||
{ |
|||
name = "ScreenPos"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
private const string kOutputSlotName = "ScreenPos"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
public override PreviewMode previewMode |
|||
{ |
|||
get { return PreviewMode.Preview3D; } |
|||
} |
|||
|
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
|
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotName }); |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(MaterialSlot slot) |
|||
{ |
|||
return "IN.screenPos"; |
|||
} |
|||
|
|||
public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string temp = precision + "4 screenPos"; |
|||
if (generationMode == GenerationMode.Preview2D) |
|||
temp += " : TEXCOORD1"; |
|||
temp += ";"; |
|||
visitor.AddShaderChunk(temp, true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e204c7999bfa0ee42a18d8a560a36244 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Sin Node")] |
|||
class SinNode : Function1Input |
|||
{ |
|||
public SinNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "SinNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "sin"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2b10d839969f5484cad9632519dc7324 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Sine Time Node")] |
|||
public class SinTimeNode : AbstractMaterialNode, IRequiresTime |
|||
{ |
|||
public SinTimeNode(IGraph theOwner) : base(theOwner) |
|||
{ |
|||
name = "Sine Time"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
private const string kOutputSlotName = "SinTime"; |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.one)); |
|||
RemoveSlotsNameNotMatching(new[] {kOutputSlotName}); |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(MaterialSlot s) |
|||
{ |
|||
return "_SinTime"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f80af444cd4235c419b356216d784b57 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/SmoothStep Node")] |
|||
class SmoothStepNode : Function3Input, IGeneratesFunction |
|||
{ |
|||
public SmoothStepNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "SmoothStepNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_smoothstep_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_smoothstep_" + precision + " (" + precision + "4 input, " + precision + "4 edge1, " + precision + "4 edge2)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return smoothstep(edge1, edge2, input);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a9ced96a233d64541b3c5d374a057d6b |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class SubGraphIOBaseNode : BaseMaterialNode |
|||
{ |
|||
GUIContent kTempContent = new GUIContent("+"); |
|||
|
|||
public virtual void AddSlot() |
|||
{ |
|||
} |
|||
|
|||
public void FooterUI(GraphGUI host) |
|||
{ |
|||
// TODO: make it pretty
|
|||
GUIStyle style = this is SubGraphOutputsNode ? |
|||
Styles.GetNodeStyle("shader in", Styles.Color.Aqua, false) : |
|||
Styles.GetNodeStyle("shader out", Styles.Color.Aqua, false); |
|||
var pos = GUILayoutUtility.GetRect(kTempContent, style); |
|||
int id = GUIUtility.GetControlID(FocusType.Passive); |
|||
|
|||
Event evt = Event.current; |
|||
if (evt.type == EventType.Layout || evt.type == EventType.Used) |
|||
return; |
|||
|
|||
switch (evt.GetTypeForControl(id)) |
|||
{ |
|||
case EventType.MouseUp: |
|||
if (pos.Contains(evt.mousePosition) && evt.button == 0) |
|||
{ |
|||
AddSlot(); |
|||
evt.Use(); |
|||
} |
|||
break; |
|||
case EventType.Repaint: |
|||
style.Draw(pos, kTempContent, id); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 329dc46f2903e364da6c6d6500b0cfee |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine; |
|||
using System.Collections.Generic; |
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class SubGraphInputsNode : SubGraphIOBaseNode, IGenerateProperties |
|||
{ |
|||
public override void OnCreate() |
|||
{ |
|||
name = "SubGraphInputs"; |
|||
title = "Inputs"; |
|||
// position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 4, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
|
|||
base.OnCreate(); |
|||
} |
|||
|
|||
public override void AddSlot() |
|||
{ |
|||
//AddSlot(new Slot(SlotType.OutputSlot, GenerateSlotName(SlotType.OutputSlot)));
|
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
base.GeneratePropertyBlock(visitor, generationMode); |
|||
|
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
foreach (var slot in outputSlots) |
|||
{ |
|||
if (slot.edges.Count == 0) |
|||
continue; |
|||
|
|||
var defaultValue = GetSlotDefaultValue(slot.name); |
|||
if (defaultValue != null) |
|||
defaultValue.GeneratePropertyBlock(visitor, generationMode); |
|||
} |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType) |
|||
{ |
|||
base.GeneratePropertyUsages(visitor, generationMode, slotValueType); |
|||
|
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
foreach (var slot in outputSlots) |
|||
{ |
|||
if (slot.edges.Count == 0) |
|||
continue; |
|||
|
|||
var defaultValue = GetSlotDefaultValue(slot.name); |
|||
if (defaultValue != null) |
|||
defaultValue.GeneratePropertyUsages(visitor, generationMode, slotValueType); |
|||
} |
|||
} |
|||
|
|||
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
foreach (var slot in outputSlots) |
|||
{ |
|||
if (slot.edges.Count == 0) |
|||
continue; |
|||
|
|||
var defaultOutput = GetSlotDefaultValue(slot.name); |
|||
if (defaultOutput == null) |
|||
continue; |
|||
|
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = defaultOutput.inputName, |
|||
m_PropType = PropertyType.Vector4, |
|||
m_Vector4 = defaultOutput.defaultValue |
|||
}; |
|||
properties.Add (pp); |
|||
} |
|||
} |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: af738716871e4a345ac8edc429a3b665 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
/*using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
//[Title("Sub-graph/Sub-graph Node")]
|
|||
public class SubGraphNode : BaseMaterialNode, IGeneratesBodyCode, IGeneratesVertexToFragmentBlock, IGeneratesFunction, IGeneratesVertexShaderBlock |
|||
{ |
|||
[SerializeField] |
|||
private MaterialSubGraph m_SubGraphAsset; |
|||
|
|||
public MaterialSubGraph subGraphAsset { get { return m_SubGraphAsset; } } |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
if (subGraphAsset == null) |
|||
return PreviewMode.Preview2D; |
|||
var nodes = ListPool<BaseMaterialNode>.Get(); |
|||
var preview3D = subGraphAsset.outputsNode.CollectChildNodesByExecutionOrder(nodes).Any(x => x.previewMode == PreviewMode.Preview3D); |
|||
ListPool <BaseMaterialNode >.Release(nodes); |
|||
return preview3D ? PreviewMode.Preview3D : PreviewMode.Preview2D; |
|||
} |
|||
} |
|||
|
|||
public const int kMaxSlots = 16; |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
name = "SubGraph"; |
|||
position = new Rect(position.x, position.y, Mathf.Max(300, position.width), position.height); |
|||
} |
|||
|
|||
static string GetInputSlotName(int n) |
|||
{ |
|||
return string.Format("I{0:00}", n); |
|||
} |
|||
|
|||
static string GetOutputSlotName(int n) |
|||
{ |
|||
return string.Format("O{0:00}", n); |
|||
} |
|||
|
|||
/* public override IEnumerable<Slot> GetValidInputSlots() |
|||
{ |
|||
// We only want to return the input slots that are internally wired to an output slot
|
|||
return base.GetValidInputSlots().Where(slot => m_SubGraphAsset.InputInternallyWired(slot.name, this)).ToList(); |
|||
}* |
|||
|
|||
public override void NodeUI(GraphGUI host) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
m_SubGraphAsset = (MaterialSubGraph)EditorGUILayout.ObjectField(GUIContent.none, m_SubGraphAsset, typeof(MaterialSubGraph), false); |
|||
if (EditorGUI.EndChangeCheck() && m_SubGraphAsset != null) |
|||
{ |
|||
SubGraphChanged(m_SubGraphAsset); |
|||
} |
|||
} |
|||
|
|||
private void SubGraphChanged(MaterialSubGraph sender) |
|||
{ |
|||
RefreshSlots(SlotType.InputSlot, inputSlots.ToList(), sender.inputsNode.slots, (s) => true); |
|||
RefreshSlots(SlotType.OutputSlot, outputSlots.ToList(), sender.outputsNode.slots, sender.OutputInternallyWired); |
|||
pixelGraph.RevalidateGraph(); |
|||
} |
|||
|
|||
private void RefreshSlots(SlotType type, IEnumerable<Slot> current, IEnumerable<Slot> updated, Func<string, bool> slotFilter) |
|||
{ |
|||
var innerOutputSlots = updated.Where(n => slotFilter(n.name)).ToArray(); |
|||
foreach (var slot in innerOutputSlots) |
|||
{ |
|||
var s = current.FirstOrDefault(n => n.name == slot.name); |
|||
if (s != null) |
|||
s.title = slot.title; |
|||
// else
|
|||
// AddSlot(new Slot(type, slot.name, slot.title));
|
|||
} |
|||
|
|||
var danglingSlots = current.Except(innerOutputSlots, (ls, rs) => ls.name == rs.name).ToArray(); |
|||
foreach (var slot in danglingSlots) |
|||
RemoveSlot(slot); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator shaderBodyVisitor, GenerationMode generationMode) |
|||
{ |
|||
if (m_SubGraphAsset == null) |
|||
return; |
|||
|
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk("// Subgraph for node " + GetOutputVariableNameForNode(), false); |
|||
|
|||
// Step 1...
|
|||
// find out which output slots are actually used
|
|||
//TODO: Be smarter about this and only output ones that are actually USED, not just connected
|
|||
//var validOutputSlots = NodeUtils.GetSlotsThatOutputToNodeRecurse(this, (graph as BaseMaterialGraph).masterNode);
|
|||
var validOutputSlots = outputSlots.Where(x => x.edges.Count > 0); |
|||
foreach (var slot in validOutputSlots) |
|||
{ |
|||
outputString.AddShaderChunk( |
|||
"float4 " |
|||
+ GetOutputVariableNameForSlot(slot, generationMode) |
|||
+ " = float4(0, 0, 0, 0);", false); |
|||
} |
|||
|
|||
// Step 2...
|
|||
// Go into the subgraph
|
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
// Step 3...
|
|||
// For each input that is used and connects through we want to generate code.
|
|||
// First we assign the input variables to the subgraph
|
|||
foreach (var slot in slots) |
|||
{ |
|||
if (!slot.isInputSlot) |
|||
continue; |
|||
|
|||
// see if the input connects all the way though to the output
|
|||
// if it does allow generation
|
|||
var inputWired = m_SubGraphAsset.InputInternallyWired(slot.name, this); |
|||
if (!inputWired) |
|||
continue; |
|||
|
|||
var varName = m_SubGraphAsset.GetInputVariableNameForSlotByName(slot.name, this, generationMode); |
|||
var varValue = "float4(0, 0, 0, 0);"; |
|||
var slotDefaultValue = GetSlotDefaultValue(slot.name); |
|||
if (slotDefaultValue != null) |
|||
{ |
|||
varValue = slotDefaultValue.GetDefaultValue(generationMode, concreteInputSlotValueTypes[slot.name]); |
|||
} |
|||
bool externallyWired = slot.edges.Count > 0; |
|||
if (externallyWired) |
|||
{ |
|||
var fromSlot = slot.edges[0].fromSlot; |
|||
var fromNode = slot.edges[0].fromSlot.node as BaseMaterialNode; |
|||
varValue = fromNode.GetOutputVariableNameForSlot(fromSlot, generationMode); |
|||
} |
|||
|
|||
outputString.AddShaderChunk("float4 " + varName + " = " + varValue + ";", false); |
|||
} |
|||
|
|||
// Step 4...
|
|||
// Using the inputs we can now generate the shader body :)
|
|||
var bodyGenerator = new ShaderGenerator(); |
|||
m_SubGraphAsset.GenerateNodeCode(bodyGenerator, this); |
|||
outputString.AddShaderChunk(bodyGenerator.GetShaderString(0), false); |
|||
|
|||
// Step 5...
|
|||
// Copy the outputs to the parent context name);
|
|||
foreach (var slot in validOutputSlots) |
|||
{ |
|||
bool internallyWired = m_SubGraphAsset.OutputInternallyWired(slot.name); |
|||
if (internallyWired) |
|||
{ |
|||
outputString.AddShaderChunk( |
|||
GetOutputVariableNameForSlot(slot, generationMode) |
|||
+ " = " |
|||
+ m_SubGraphAsset.GetOutputVariableNameForSlotByName(slot.name, this, generationMode) |
|||
+ ";", false); |
|||
} |
|||
} |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("// Subgraph ends", false); |
|||
|
|||
shaderBodyVisitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
m_SubGraphAsset.GenerateVertexToFragmentBlock(visitor, GenerationMode.SurfaceShader); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
m_SubGraphAsset.GenerateNodeFunction(visitor, GenerationMode.SurfaceShader); |
|||
} |
|||
|
|||
public void GenerateVertexShaderBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
m_SubGraphAsset.GenerateVertexShaderBlock(visitor, GenerationMode.SurfaceShader); |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
base.GeneratePropertyBlock(visitor, generationMode); |
|||
m_SubGraphAsset.GeneratePropertyBlock(visitor, GenerationMode.SurfaceShader); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType) |
|||
{ |
|||
base.GeneratePropertyUsages(visitor, generationMode, slotValueType); |
|||
m_SubGraphAsset.GeneratePropertyUsages(visitor, GenerationMode.SurfaceShader, slotValueType); |
|||
} |
|||
|
|||
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
properties.AddRange(m_SubGraphAsset.GetPreviewProperties()); |
|||
} |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 047e0841c1476e041935baac6d7bb652 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
/*using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class SubGraphOutputsNode : SubGraphIOBaseNode |
|||
{ |
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
name = "SubGraphOutputs"; |
|||
title = "Outputs"; |
|||
//position = new Rect(BaseMaterialGraphGUI.kDefaultNodeWidth * 8, BaseMaterialGraphGUI.kDefaultNodeHeight * 2, Mathf.Max(300, position.width), position.height);
|
|||
} |
|||
|
|||
public override void AddSlot() |
|||
{ |
|||
//AddSlot(new Slot(SlotType.InputSlot, GenerateSlotName(SlotType.InputSlot)));
|
|||
} |
|||
} |
|||
} |
|||
*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 12f42b98cfc8a394ca51a63cdd53d2cb |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Subtract Node")] |
|||
class SubtractNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public SubtractNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "SubtractNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() {return "unity_subtract_" + precision; } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 - arg2;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b251c305a044f49438dff356f1e7bb84 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEditor; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Channels/Swizzle Node")] |
|||
public class SwizzleNode : Function2Input |
|||
{ |
|||
[SerializeField] |
|||
private int[] m_SwizzleChannel = new int[4]; |
|||
|
|||
public SwizzleNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "SwizzleNode"; |
|||
} |
|||
/* |
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override GUIModificationType NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
string[] channelNames = {"X", "Y", "Z", "W"}; |
|||
string[] values = {"0", "1", "Input1.x", "Input1.y", "Input1.z", "Input1.w", "Input2.x", "Input2.y", "Input2.z", "Input2.w"}; |
|||
EditorGUI.BeginChangeCheck(); |
|||
for (int n = 0; n < 4; n++) |
|||
m_SwizzleChannel[n] = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), channelNames[n] + "=", m_SwizzleChannel[n], values); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
pixelGraph.RevalidateGraph(); |
|||
return GUIModificationType.Repaint; |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
*/ |
|||
protected override string GetFunctionName() |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
protected override string GetFunctionCallBody(string inputValue1, string inputValue2) |
|||
{ |
|||
string[] inputValues = { inputValue1, inputValue2 }; |
|||
string[] channelNames = { "x", "y", "z", "w" }; |
|||
string s = precision + "4("; |
|||
for (int n = 0; n < 4; n++) |
|||
{ |
|||
int c = m_SwizzleChannel[n]; |
|||
if (c < 2) |
|||
s += c; |
|||
else |
|||
{ |
|||
c -= 2; |
|||
s += inputValues[c >> 2] + "." + channelNames[c & 3]; |
|||
} |
|||
s += (n == 3) ? ")" : ","; |
|||
} |
|||
return s; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 408ee761513fda7449bb3e428095726a |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Texture Node")] |
|||
public class TextureNode : PropertyNode, IGeneratesBodyCode, IGeneratesVertexShaderBlock, IGeneratesVertexToFragmentBlock |
|||
{ |
|||
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"; |
|||
protected const string kUVSlotName = "UV"; |
|||
|
|||
[SerializeField] |
|||
public Texture2D m_DefaultTexture; |
|||
|
|||
[SerializeField] |
|||
public TextureType m_TextureType; |
|||
|
|||
private List<string> m_TextureTypeNames; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public TextureNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "Texture"; |
|||
LoadTextureTypes(); |
|||
} |
|||
|
|||
public override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
LoadTextureTypes(); |
|||
|
|||
AddSlot(new MaterialSlot(kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotRName, kOutputSlotRName, SlotType.Output, 1, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotGName, kOutputSlotGName, SlotType.Output, 2, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotBName, kOutputSlotBName, SlotType.Output, 3, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotAName, kOutputSlotAName, SlotType.Output, 4, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
AddSlot(new MaterialSlot(kUVSlotName, kUVSlotName, SlotType.Input, 0, SlotValueType.Vector2, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
|
|||
protected string[] validSlots |
|||
{ |
|||
get { return new[] {kOutputSlotRGBAName, kOutputSlotRName, kOutputSlotGName, kOutputSlotBName, kOutputSlotAName, kUVSlotName}; } |
|||
} |
|||
|
|||
private void LoadTextureTypes() |
|||
{ |
|||
if (m_TextureTypeNames == null) |
|||
m_TextureTypeNames = new List<string>(Enum.GetNames(typeof(TextureType))); |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var uvName = "IN.meshUV0.xy"; |
|||
|
|||
var edges = owner.GetEdges(GetSlotReference(uvSlot.name)).ToList(); |
|||
|
|||
if (edges.Count > 0) |
|||
{ |
|||
var edge = edges[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
var slot = fromNode.FindMaterialOutputSlot(edge.outputSlot.slotName); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, slot, generationMode, ConcreteSlotValueType.Vector2, true); |
|||
|
|||
} |
|||
|
|||
string body = "tex2D (" + propertyName + ", " + uvName + ")"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
visitor.AddShaderChunk("float4 " + GetVariableNameForNode() + " = " + body + ";", true); |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(MaterialSlot s) |
|||
{ |
|||
string slotOutput; |
|||
switch (s.name) |
|||
{ |
|||
case kOutputSlotRName: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case kOutputSlotGName: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case kOutputSlotBName: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case kOutputSlotAName: |
|||
slotOutput = ".a"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return GetVariableNameForNode() + slotOutput; |
|||
} |
|||
|
|||
public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var edges = owner.GetEdges(GetSlotReference(uvSlot.name)); |
|||
if (edges.Any()) |
|||
UVNode.StaticGenerateVertexToFragmentBlock(visitor, generationMode); |
|||
} |
|||
|
|||
public void GenerateVertexShaderBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var edges = owner.GetEdges(GetSlotReference(uvSlot.name)); |
|||
if (edges.Any()) |
|||
UVNode.GenerateVertexShaderBlock(visitor); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty(new TexturePropertyChunk(propertyName, description, m_DefaultTexture, m_TextureType, false, exposed)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType slotValueType) |
|||
{ |
|||
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true); |
|||
} |
|||
|
|||
/* |
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight * 2; |
|||
} |
|||
|
|||
public override GUIModificationType NodeUI(Rect drawArea) |
|||
{ |
|||
LoadTextureTypes(); |
|||
|
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_DefaultTexture = EditorGUI.MiniThumbnailObjectField( new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), new GUIContent("Texture"), m_DefaultTexture, typeof(Texture2D), null) as Texture2D; |
|||
var texureChanged = EditorGUI.EndChangeCheck(); |
|||
|
|||
drawArea.y += EditorGUIUtility.singleLineHeight; |
|||
EditorGUI.BeginChangeCheck(); |
|||
m_TextureType = (TextureType) EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), (int) m_TextureType, m_TextureTypeNames.ToArray(), EditorStyles.popup); |
|||
var typeChanged = EditorGUI.EndChangeCheck(); |
|||
|
|||
if (typeChanged) |
|||
{ |
|||
pixelGraph.RevalidateGraph(); |
|||
return GUIModificationType.Repaint; |
|||
} |
|||
|
|||
return texureChanged ? GUIModificationType.Repaint : GUIModificationType.None; |
|||
} |
|||
|
|||
|
|||
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.Texture2D, |
|||
m_Texture = m_DefaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture2D; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5defdf1d05185a343bfebb2cdd827bd6 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Time Node")] |
|||
public class TimeNode : AbstractMaterialNode, IRequiresTime |
|||
{ |
|||
private const string kOutputSlotName = "Time"; |
|||
private const string kOutputSlotNameX = "Time.x"; |
|||
private const string kOutputSlotNameY = "Time.y"; |
|||
private const string kOutputSlotNameZ = "Time.z"; |
|||
private const string kOutputSlotNameW = "Time.w"; |
|||
|
|||
public TimeNode(IGraph theOwner) : base(theOwner) |
|||
{ |
|||
name = "Time"; |
|||
} |
|||
|
|||
public override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, 1, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, 2, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, 3, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, 4, SlotValueType.Vector1, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected string[] validSlots |
|||
{ |
|||
get { return new[] {kOutputSlotName, kOutputSlotNameX, kOutputSlotNameY, kOutputSlotNameZ, kOutputSlotName}; } |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(MaterialSlot s) |
|||
{ |
|||
switch (s.name) |
|||
{ |
|||
case kOutputSlotNameX: |
|||
return "_Time.x"; |
|||
case kOutputSlotNameY: |
|||
return "_Time.y"; |
|||
case kOutputSlotNameZ: |
|||
return "_Time.z"; |
|||
case kOutputSlotNameW: |
|||
return "_Time.w"; |
|||
default: |
|||
return "_Time"; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a4ad33d64aec32840b61126b0fbb17e1 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/UV Node")] |
|||
public class UVNode : AbstractMaterialNode, IGeneratesVertexToFragmentBlock, IGeneratesVertexShaderBlock, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "UV"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public UVNode(IGraph theOwner) : base(theOwner) |
|||
{ |
|||
name = "UV"; |
|||
} |
|||
|
|||
public override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector4, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] {kOutputSlotName}); |
|||
} |
|||
|
|||
public static void StaticGenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string temp = "half4 meshUV0"; |
|||
if (generationMode == GenerationMode.Preview2D) |
|||
temp += " : TEXCOORD0"; |
|||
temp += ";"; |
|||
visitor.AddShaderChunk(temp, true); |
|||
} |
|||
|
|||
public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
StaticGenerateVertexToFragmentBlock(visitor, generationMode); |
|||
} |
|||
|
|||
public static void GenerateVertexShaderBlock(ShaderGenerator visitor) |
|||
{ |
|||
visitor.AddShaderChunk("o.meshUV0 = v.texcoord;", true); |
|||
} |
|||
|
|||
public void GenerateVertexShaderBlock(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
GenerateVertexShaderBlock(visitor); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindMaterialOutputSlot(kOutputSlotName); |
|||
|
|||
string uvValue = "IN.meshUV0"; |
|||
visitor.AddShaderChunk(precision + "4 " + GetOutputVariableNameForSlot(outputSlot) + " = " + uvValue + ";", true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1c05002dbfc8cd14cb3b544630cf1017 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System; |
|||
using UnityEngine.Graphing; |
|||
|
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Channels/Unpack Normal Node")] |
|||
internal class UnpackNormalNode : Function1Input |
|||
{ |
|||
public UnpackNormalNode(IGraph owner) : base(owner) |
|||
{ |
|||
name = "UnpackNormalNode"; |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
protected override string GetInputSlotName() {return "PackedNormal"; } |
|||
protected override string GetOutputSlotName() {return "Normal"; } |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "UnpackNormal"; |
|||
} |
|||
|
|||
protected override string GetFunctionCallBody(string inputValue) |
|||
{ |
|||
return precision + "4(" + GetFunctionName() + " (" + inputValue + ")" + ", 0)"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1295ed68a1115a64088fc9298766fde8 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Vector 1 Node")] |
|||
public class Vector1Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private float m_Value; |
|||
|
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
public Vector1Node(IGraph owner) : base(owner) |
|||
{ |
|||
name = "V1Node"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector1, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotName }); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float; } |
|||
} |
|||
|
|||
public float value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed) |
|||
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, false)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk("float " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + " " + propertyName + " = " + m_Value + ";", true); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Float, |
|||
m_Float = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 87c4299b09d95d64c99884296038ceeb |
|||
timeCreated: 1445864587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Vector 2 Node")] |
|||
public class Vector2Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
[SerializeField] |
|||
private Vector2 m_Value; |
|||
|
|||
public Vector2Node(IGraph owner) : base(owner) |
|||
{ |
|||
name = "V2Node"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector2, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotName }); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Vector2; } |
|||
} |
|||
|
|||
public Vector2 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed) |
|||
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk("float2 " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Vector2, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8361d1f9d12a489438c0b1e2e48c8542 |
|||
timeCreated: 1446473341 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Vector 3 Node")] |
|||
public class Vector3Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
[SerializeField] |
|||
private Vector3 m_Value; |
|||
|
|||
public Vector3Node(IGraph owner) : base(owner) |
|||
{ |
|||
name = "V3Node"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, 0, SlotValueType.Vector3, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotName }); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Vector3; } |
|||
} |
|||
|
|||
public Vector3 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed) |
|||
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, false)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk("float3 " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposed || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + "3 " + propertyName + " = " + precision + "3 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ");", true); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Vector3, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue