浏览代码

Added nodes

-Ceil
-Exponential
-Floor
-Frac
-HSVtoRGB
-Hue
-InverseLerp
-OneMinus
-Remap
-RGBtoHCV
-RGBtoHSV
-Round
-Sign
-SquareRoot
-Step
-Trunc
-FMod
-Log

WIP Nodes
-ComponentSplitNode
-Cubemap
-Function1in3out
/main
Andre McGrail 8 年前
当前提交
2dbd4aa3
共有 91 个文件被更改,包括 9477 次插入0 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewProperty.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs
  4. 9
      MaterialGraphProject/Assets/NewNodes.meta
  5. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CubemapNodePresenter.cs
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CubemapNodePresenter.cs.meta
  7. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/CubemapPropertyChunk.cs
  8. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/CubemapPropertyChunk.cs.meta
  9. 1001
      MaterialGraphProject/Assets/NewNodes/DreTest.ShaderGraph
  10. 9
      MaterialGraphProject/Assets/NewNodes/DreTest.ShaderGraph.meta
  11. 9
      MaterialGraphProject/Assets/NewNodes/Maths.meta
  12. 9
      MaterialGraphProject/Assets/NewNodes/Maths/Advance.meta
  13. 17
      MaterialGraphProject/Assets/NewNodes/Maths/Advance/FmodNode.cs
  14. 12
      MaterialGraphProject/Assets/NewNodes/Maths/Advance/FmodNode.cs.meta
  15. 14
      MaterialGraphProject/Assets/NewNodes/Maths/Advance/LogNode.cs
  16. 12
      MaterialGraphProject/Assets/NewNodes/Maths/Advance/LogNode.cs.meta
  17. 13
      MaterialGraphProject/Assets/NewNodes/Maths/CeilNode.cs
  18. 12
      MaterialGraphProject/Assets/NewNodes/Maths/CeilNode.cs.meta
  19. 181
      MaterialGraphProject/Assets/NewNodes/Maths/DepthTexture.cs
  20. 12
      MaterialGraphProject/Assets/NewNodes/Maths/DepthTexture.cs.meta
  21. 17
      MaterialGraphProject/Assets/NewNodes/Maths/ExponentialNode.cs
  22. 12
      MaterialGraphProject/Assets/NewNodes/Maths/ExponentialNode.cs.meta
  23. 14
      MaterialGraphProject/Assets/NewNodes/Maths/FloorNode.cs
  24. 12
      MaterialGraphProject/Assets/NewNodes/Maths/FloorNode.cs.meta
  25. 15
      MaterialGraphProject/Assets/NewNodes/Maths/FractionNode.cs
  26. 12
      MaterialGraphProject/Assets/NewNodes/Maths/FractionNode.cs.meta
  27. 45
      MaterialGraphProject/Assets/NewNodes/Maths/HSVtoRGBNode.cs
  28. 12
      MaterialGraphProject/Assets/NewNodes/Maths/HSVtoRGBNode.cs.meta
  29. 45
      MaterialGraphProject/Assets/NewNodes/Maths/HueNode.cs
  30. 12
      MaterialGraphProject/Assets/NewNodes/Maths/HueNode.cs.meta
  31. 29
      MaterialGraphProject/Assets/NewNodes/Maths/InverseLerpNode.cs
  32. 12
      MaterialGraphProject/Assets/NewNodes/Maths/InverseLerpNode.cs.meta
  33. 29
      MaterialGraphProject/Assets/NewNodes/Maths/OneMinus.cs
  34. 8
      MaterialGraphProject/Assets/NewNodes/Maths/OneMinus.cs.meta
  35. 47
      MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHCVNode.cs
  36. 12
      MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHCVNode.cs.meta
  37. 48
      MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHSVNode.cs
  38. 12
      MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHSVNode.cs.meta
  39. 146
      MaterialGraphProject/Assets/NewNodes/Maths/RemapNode.cs
  40. 12
      MaterialGraphProject/Assets/NewNodes/Maths/RemapNode.cs.meta
  41. 13
      MaterialGraphProject/Assets/NewNodes/Maths/RoundNode.cs
  42. 12
      MaterialGraphProject/Assets/NewNodes/Maths/RoundNode.cs.meta
  43. 13
      MaterialGraphProject/Assets/NewNodes/Maths/SignNode.cs
  44. 12
      MaterialGraphProject/Assets/NewNodes/Maths/SignNode.cs.meta
  45. 17
      MaterialGraphProject/Assets/NewNodes/Maths/SquareRootNode.cs
  46. 12
      MaterialGraphProject/Assets/NewNodes/Maths/SquareRootNode.cs.meta
  47. 15
      MaterialGraphProject/Assets/NewNodes/Maths/StepNode.cs
  48. 12
      MaterialGraphProject/Assets/NewNodes/Maths/StepNode.cs.meta
  49. 9
      MaterialGraphProject/Assets/NewNodes/Maths/Templates.meta
  50. 624
      MaterialGraphProject/Assets/NewNodes/Maths/Templates/AbstractNode.cs
  51. 12
      MaterialGraphProject/Assets/NewNodes/Maths/Templates/AbstractNode.cs.meta
  52. 228
      MaterialGraphProject/Assets/NewNodes/Maths/Templates/TestFunctionWithVariableNode.cs
  53. 12
      MaterialGraphProject/Assets/NewNodes/Maths/Templates/TestFunctionWithVariableNode.cs.meta
  54. 15
      MaterialGraphProject/Assets/NewNodes/Maths/TruncNode.cs
  55. 12
      MaterialGraphProject/Assets/NewNodes/Maths/TruncNode.cs.meta
  56. 20
      MaterialGraphProject/Assets/NewNodes/Maths/_blank.ShaderGraph
  57. 9
      MaterialGraphProject/Assets/NewNodes/Maths/_blank.ShaderGraph.meta
  58. 1001
      MaterialGraphProject/Assets/NewNodes/Maths/_test.ShaderGraph
  59. 9
      MaterialGraphProject/Assets/NewNodes/Maths/_test.ShaderGraph.meta
  60. 9
      MaterialGraphProject/Assets/NewNodes/TestAssets.meta
  61. 460
      MaterialGraphProject/Assets/NewNodes/TestAssets/Clouds.png
  62. 68
      MaterialGraphProject/Assets/NewNodes/TestAssets/Clouds.png.meta
  63. 1001
      MaterialGraphProject/Assets/NewNodes/TestAssets/ColorGuide.tif
  64. 76
      MaterialGraphProject/Assets/NewNodes/TestAssets/ColorGuide.tif.meta
  65. 84
      MaterialGraphProject/Assets/NewNodes/TestAssets/Depth.mat
  66. 9
      MaterialGraphProject/Assets/NewNodes/TestAssets/Depth.mat.meta
  67. 171
      MaterialGraphProject/Assets/NewNodes/TestAssets/Gradient.png
  68. 76
      MaterialGraphProject/Assets/NewNodes/TestAssets/Gradient.png.meta
  69. 1001
      MaterialGraphProject/Assets/NewNodes/TestAssets/Scene.unity
  70. 8
      MaterialGraphProject/Assets/NewNodes/TestAssets/Scene.unity.meta
  71. 434
      MaterialGraphProject/Assets/NewNodes/TestAssets/Sky1.jpg
  72. 85
      MaterialGraphProject/Assets/NewNodes/TestAssets/Sky1.jpg.meta
  73. 1001
      MaterialGraphProject/Assets/NewNodes/TestAssets/normal.png
  74. 76
      MaterialGraphProject/Assets/NewNodes/TestAssets/normal.png.meta
  75. 32
      MaterialGraphProject/Assets/NewNodes/TestAssets/sfn_vertexcolor.png
  76. 76
      MaterialGraphProject/Assets/NewNodes/TestAssets/sfn_vertexcolor.png.meta
  77. 9
      MaterialGraphProject/Assets/NewNodes/WIP.meta
  78. 205
      MaterialGraphProject/Assets/NewNodes/WIP/ComponentSplitNode.cs
  79. 12
      MaterialGraphProject/Assets/NewNodes/WIP/ComponentSplitNode.cs.meta
  80. 227
      MaterialGraphProject/Assets/NewNodes/WIP/CubemapNode.cs
  81. 8
      MaterialGraphProject/Assets/NewNodes/WIP/CubemapNode.cs.meta
  82. 126
      MaterialGraphProject/Assets/NewNodes/WIP/CustomInput.cs
  83. 12
      MaterialGraphProject/Assets/NewNodes/WIP/CustomInput.cs.meta
  84. 146
      MaterialGraphProject/Assets/NewNodes/WIP/Function1In3Out.cs
  85. 12
      MaterialGraphProject/Assets/NewNodes/WIP/Function1In3Out.cs.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
typeMapper[typeof(UVNode)] = typeof(UVNodePresenter);
typeMapper[typeof(Vector1Node)] = typeof(Vector1NodePresenter);
typeMapper[typeof(Vector2Node)] = typeof(Vector2NodePresenter);

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewProperty.cs


public Color m_Color;
public Texture2D m_Texture;
public Cubemap m_Cubemap;
public Vector4 m_Vector4;
public float m_Float;
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs


{
Color,
Texture2D,
Cubemap,
Float,
Vector2,
Vector3,

9
MaterialGraphProject/Assets/NewNodes.meta


fileFormatVersion: 2
guid: 5e38909e3b20f43b28137daed5bd62bf
folderAsset: yes
timeCreated: 1495449911
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CubemapNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class CubeContolPresenter : GraphControlPresenter
{
//private string[] m_TextureTypeNames;
//private string[] textureTypeNames
/* {
get
{
if (m_TextureTypeNames == null)
m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}*/
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.CubemapNode;
if (tNode == null)
return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultCube = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Cubemap"), tNode.defaultCube, typeof(Cubemap), null) as Cubemap;
//tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class CubeNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<CubeContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CubemapNodePresenter.cs.meta


fileFormatVersion: 2
guid: fc62d7d14c85243dca60985fa3d87d64
timeCreated: 1476707366
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

56
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/CubemapPropertyChunk.cs


using System;
using System.Text;
namespace UnityEngine.MaterialGraph
{
public class CubemapPropertyChunk : PropertyChunk
{
public enum ModifiableState
{
Modifiable,
NonModifiable
}
private readonly Cubemap m_DefaultCube;
private readonly ModifiableState m_Modifiable;
public CubemapPropertyChunk(string propertyName, string propertyDescription, Cubemap defaultTexture, HideState hidden, ModifiableState modifiableState)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultCube = defaultTexture;
m_Modifiable = modifiableState;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
if (hideState == HideState.Hidden)
result.Append("[HideInInspector] ");
if (m_Modifiable == ModifiableState.NonModifiable)
result.Append("[NonModifiableTextureData] ");
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);
result.Append("\", Cube) = \"");
result.Append("");
result.Append("\" {}");
return result.ToString();
}
public Texture defaultCube
{
get
{
return m_DefaultCube;
}
}
public ModifiableState modifiableState
{
get
{
return m_Modifiable;
}
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/CubemapPropertyChunk.cs.meta


fileFormatVersion: 2
guid: acd2330628610436abee804f8846e725
timeCreated: 1469695793
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
MaterialGraphProject/Assets/NewNodes/DreTest.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/NewNodes/DreTest.ShaderGraph.meta


fileFormatVersion: 2
guid: 604328ec39a1c436885c322585efac83
timeCreated: 1490973914
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewNodes/Maths.meta


fileFormatVersion: 2
guid: 15a153bc3a820b44395068190b4799d2
folderAsset: yes
timeCreated: 1490739783
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewNodes/Maths/Advance.meta


fileFormatVersion: 2
guid: d8cd59bbd05694da0aaaf5d1a1df30f7
folderAsset: yes
timeCreated: 1490803627
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

17
MaterialGraphProject/Assets/NewNodes/Maths/Advance/FmodNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Advanced/Fmod")]
public class FmodNode : Function2Input
{
public FmodNode ()
{
name = "Fmod";
}
protected override string GetFunctionName ()
{
return "fmod";
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/Advance/FmodNode.cs.meta


fileFormatVersion: 2
guid: 058897be65bcd42f6ba05a4918c46629
timeCreated: 1490745697
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
MaterialGraphProject/Assets/NewNodes/Maths/Advance/LogNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Log")]
public class LogNode : Function1Input
{
public LogNode()
{
name = "Log";
}
protected override string GetFunctionName() { return "log"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/Advance/LogNode.cs.meta


fileFormatVersion: 2
guid: a8880ad54646f8b469de662f4f0785c9
timeCreated: 1490740341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
MaterialGraphProject/Assets/NewNodes/Maths/CeilNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Ceil")]
public class CeilNode : Function1Input
{
public CeilNode()
{
name = "Ceil";
}
protected override string GetFunctionName() { return "ceil"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/CeilNode.cs.meta


fileFormatVersion: 2
guid: ab2601bf38a580a46945e707fecb7943
timeCreated: 1490744931
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

181
MaterialGraphProject/Assets/NewNodes/Maths/DepthTexture.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Depth Texture")]
public class DepthTextureNode : PropertyNode, IGeneratesBodyCode
{
protected const string kUVSlotName = "UV";
protected const string kOutputSlotName = "Output";
public const int UvSlotId = 0;
public const int OutputSlotId = 1;
public override bool hasPreview { get { return true; } }
/*[SerializeField]
private string m_SerializedTexture;
[SerializeField]
private TextureType m_TextureType;
[Serializable]
private class TextureHelper
{
public Texture2D texture;
}
#if UNITY_EDITOR
public Texture2D defaultTexture
{
get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
}
set
{
if (defaultTexture == value)
return;
var tex = new TextureHelper();
tex.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
public Texture2D defaultTexture {get; set; }
#endif
public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}*/
public Texture2D defaultTexture { get; set; }
public DepthTextureNode()
{
name = "DepthTexture";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, UvSlotId }; }
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
string body = "tex2D (_CameraDepthTexture, " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
/*visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));*/
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D _CameraDepthTexture;", true);
//visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = defaultTexture
};
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
//return propertyName;
}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/DepthTexture.cs.meta


fileFormatVersion: 2
guid: cb01a07941c890648943fc712415a101
timeCreated: 1490975413
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
MaterialGraphProject/Assets/NewNodes/Maths/ExponentialNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Basic/Exponential")]
public class ExponentialNode : Function1Input
{
public ExponentialNode ()
{
name = "Exponential";
}
protected override string GetFunctionName ()
{
return "exp";
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/ExponentialNode.cs.meta


fileFormatVersion: 2
guid: 2caea2ece6d6b4cbebf8bd122b11258a
timeCreated: 1490745697
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
MaterialGraphProject/Assets/NewNodes/Maths/FloorNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Floor")]
public class FloorNode : Function1Input
{
public FloorNode()
{
name = "Floor";
}
protected override string GetFunctionName() { return "floor"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/FloorNode.cs.meta


fileFormatVersion: 2
guid: 8d1b4bf99b86c474f8a0bcb2015cf3da
timeCreated: 1490745697
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
MaterialGraphProject/Assets/NewNodes/Maths/FractionNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/Fraction")]
public class FractionNode : Function1Input
{
public FractionNode()
{
name = "Fraction";
}
protected override string GetFunctionName() { return "frac"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/FractionNode.cs.meta


fileFormatVersion: 2
guid: 4229c656c10cc1c43aa631f8f6357764
timeCreated: 1490780593
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

45
MaterialGraphProject/Assets/NewNodes/Maths/HSVtoRGBNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/HSVtoRGB")]
public class HSVtoRGBNode : Function1Input, IGeneratesFunction
{
public HSVtoRGBNode ()
{
name = "HSVtoRGB";
}
protected override string GetFunctionName ()
{
return "unity_hsvtorgb_" + precision;
}
protected override MaterialSlot GetInputSlot ()
{
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot ()
{
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
//TODO:Externalize
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk (precision + "4 K = " + precision + "4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);", false);
outputString.AddShaderChunk (precision + "3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - K.www);", false);
outputString.AddShaderChunk ("return arg1.z * lerp(K.xxx, saturate(P - K.xxx), arg1.y);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/HSVtoRGBNode.cs.meta


fileFormatVersion: 2
guid: e3b0a3eacac60414c9f7594fc5286799
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

45
MaterialGraphProject/Assets/NewNodes/Maths/HueNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Color/Hue")]
public class HueNode : Function1Input, IGeneratesFunction
{
public HueNode()
{
name = "Hue";
}
protected override string GetFunctionName()
{
return "unity_hue_" + precision;
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
//TODO:Externalize
//Reference code from:https://github.com/Unity-Technologies/PostProcessing/blob/master/PostProcessing/Resources/Shaders/ColorGrading.cginc#L175
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + "4 K = " + precision + "4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);", false);
outputString.AddShaderChunk(precision + "3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - K.www);", false);
outputString.AddShaderChunk("return 1 * lerp(K.xxx, saturate(P - K.xxx), 1);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/HueNode.cs.meta


fileFormatVersion: 2
guid: 083caf0fe7ff62f438e121e934355461
timeCreated: 1490973460
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

29
MaterialGraphProject/Assets/NewNodes/Maths/InverseLerpNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Interpolation/InverseLerp")]
public class InverseLerpNode : Function3Input, IGeneratesFunction
{
public InverseLerpNode ()
{
name = "InverseLerp";
}
protected override string GetFunctionName ()
{
return "unity_inverselerp_" + precision;
}
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2", "arg3"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk ("return (arg3 - arg1)/(arg2 - arg1);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/InverseLerpNode.cs.meta


fileFormatVersion: 2
guid: 25857c1c6903f40f382b8857bba28668
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

29
MaterialGraphProject/Assets/NewNodes/Maths/OneMinus.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Range/OneMinus")]
public class OneMinusNode : Function1Input, IGeneratesFunction
{
public OneMinusNode ()
{
name = "OneMinus";
}
protected override string GetFunctionName ()
{
return "unity_oneminus_" + precision;
}
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk ("return arg1 * -1 + 1;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

8
MaterialGraphProject/Assets/NewNodes/Maths/OneMinus.cs.meta


fileFormatVersion: 2
guid: ea3f39b56fc9544ff80cbe84aa0753d0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

47
MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHCVNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/RGBtoHCV")]
public class RGBtoHCVNode : Function1Input, IGeneratesFunction
{
public RGBtoHCVNode ()
{
name = "RGBtoHCV";
}
protected override string GetFunctionName ()
{
return "unity_rgbtohcv_" + precision;
}
protected override MaterialSlot GetInputSlot ()
{
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot ()
{
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
//TODO:Externalize
//Reference code from:http://www.chilliant.com/rgb2hsv.html
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk (precision + "4 P = (arg1.g < arg1.b)?" + precision + "4(arg1.bg, -1.0, 2.0/3.0):" + precision + "4(arg1.gb, 0.0, -1.0/3.0);", false);
outputString.AddShaderChunk (precision + "4 Q = (arg1.r < P.x)?" + precision + "4(P.xyw, arg1.r):" + precision + "4(arg1.r, P.yzx);", false);
outputString.AddShaderChunk (precision + " C = Q.x - min(Q.w, Q.y);", false);
outputString.AddShaderChunk (precision + " H = abs((Q.w - Q.y)/(6 * C + 1e-10)+Q.z);", false);
outputString.AddShaderChunk ("return " + precision + "3(H,C,Q.x);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHCVNode.cs.meta


fileFormatVersion: 2
guid: 74003f5fdec034579a435cdeb6219999
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

48
MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHSVNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/RGBtoHSV")]
public class RGBtoHSVNode : Function1Input, IGeneratesFunction
{
public RGBtoHSVNode ()
{
name = "RGBtoHSV";
}
protected override string GetFunctionName ()
{
return "unity_rgbtohsv_" + precision;
}
protected override MaterialSlot GetInputSlot ()
{
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot ()
{
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
}
//TODO:Externalize
//Reference code from:http://www.chilliant.com/rgb2hsv.html
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk (precision + "4 K = " + precision + "4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);", false);
outputString.AddShaderChunk (precision + "4 P = lerp(" + precision + "4(arg1.bg, K.wz), " + precision + "4(arg1.gb, K.xy), step(arg1.b, arg1.g));", false);
outputString.AddShaderChunk (precision + "4 Q = lerp(" + precision + "4(P.xyw, arg1.r), " + precision + "4(arg1.r, P.yzx), step(P.x, arg1.r));", false);
outputString.AddShaderChunk (precision + " D = Q.x - min(Q.w, Q.y);", false);
outputString.AddShaderChunk (precision + " E = 1e-10;", false);
outputString.AddShaderChunk ("return " + precision + "3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/RGBtoHSVNode.cs.meta


fileFormatVersion: 2
guid: 5fd9fa04ca1054c9c9a5bdd6984f0ee4
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

146
MaterialGraphProject/Assets/NewNodes/Maths/RemapNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Range/Remap")]
public class RemapNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "InMin";
protected const string kInputSlot3ShaderName = "InMax";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int InputSlot3Id = 2;
public const int OutputSlotId = 3;
[SerializeField]
private Vector4 m_Value;
public override bool hasPreview
{
get { return true; }
}
public RemapNode ()
{
name = "Remap";
//UpdateNodeAfterDeserialization ();
}
public string GetFunctionName ()
{
return "unity_remap_" + precision;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetInputSlot3());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] {InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId}; }
}
protected virtual MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected virtual MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return "Input";
}
protected virtual string GetInputSlot2Name()
{
return "InMin/Max";
}
protected virtual string GetInputSlot3Name()
{
return "OutMin/Max";
}
protected virtual string GetOutputSlotName()
{
return "Output";
}
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)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
string input3Value = GetSlotValue(InputSlot3Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator ();
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2", "arg3"), false);
outputString.AddShaderChunk ("{", false);
outputString.Indent ();
outputString.AddShaderChunk ("return arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3)
{
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public string input3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot3Id).concreteValueType); }
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/RemapNode.cs.meta


fileFormatVersion: 2
guid: 1d2a789d52c4340c98278ca90d8563fe
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
MaterialGraphProject/Assets/NewNodes/Maths/RoundNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Round")]
public class RoundNode : Function1Input
{
public RoundNode()
{
name = "Round";
}
protected override string GetFunctionName() { return "round"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/RoundNode.cs.meta


fileFormatVersion: 2
guid: 03c297b39ff293f4ebc923eb7e60a565
timeCreated: 1490745167
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
MaterialGraphProject/Assets/NewNodes/Maths/SignNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Sign")]
public class SignNode : Function1Input
{
public SignNode()
{
name = "Sign";
}
protected override string GetFunctionName() { return "sign"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/SignNode.cs.meta


fileFormatVersion: 2
guid: 670ee9966f3a13d4e91477e4fb3ff1dd
timeCreated: 1490741386
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
MaterialGraphProject/Assets/NewNodes/Maths/SquareRootNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Basic/SquareRoot")]
public class SquareRootNode : Function1Input
{
public SquareRootNode ()
{
name = "SquareRoot";
}
protected override string GetFunctionName ()
{
return "sqrt";
}
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/SquareRootNode.cs.meta


fileFormatVersion: 2
guid: de49bddaf105fe34483c97b6546e54d7
timeCreated: 1490740146
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
MaterialGraphProject/Assets/NewNodes/Maths/StepNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Step")]
public class StepNode : Function2Input
{
public StepNode()
{
name = "Step";
}
protected override string GetFunctionName() { return "step"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/StepNode.cs.meta


fileFormatVersion: 2
guid: af47cc48edd11514ba0c965aae166f2f
timeCreated: 1490780593
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewNodes/Maths/Templates.meta


fileFormatVersion: 2
guid: d72965c80974e054a8aad1c75ee637a7
folderAsset: yes
timeCreated: 1490871410
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

624
MaterialGraphProject/Assets/NewNodes/Maths/Templates/AbstractNode.cs


using System; // Need?
using System.Collections.Generic; // Need?
using System.Linq; // Need?
#if UNITY_EDITOR // Need?
using UnityEditor; // Need?
#endif // Need?
using UnityEngine.Graphing;
/// <summary>
/// EXAMPLE ABSTRACT NODE
///
/// Does:
/// - Split Vector 4 to 4 individual channels (Input(0) > Uniform (0) > OutputR & OutputG & OutputB & OutputA)
/// - Combine 4 individual channels to Vector4 (InputR & InputG & InputB & InputA > Uniform1 > Output(0)
/// - Perform Gamma correction [just example maths] within a function (Input1 > Function > Output1)
/// </summary>
namespace UnityEngine.MaterialGraph
{
[Title("Templates/Absract")] //Hierarchy position in node menu
public class AbsractNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction //One interface for generating body (uniforms) and one for generating functions
{
//// Initiatize the node?
public AbsractNode()
{
name = "Absract"; // Name it (all functions and variables use this, no spaces)
UpdateNodeAfterDeserialization(); // Add/remove slots after deserialize
}
/// <summary>
/// Define slots (Start)
///
/// Each must have:
///
/// - Slot name [protected string]
/// - Slot ID [public int]
/// - Initialization in UpdateNodeAfterDeserialization()
/// - Entry in valid slot check int[]
///
/// This example contains multiple input and output slots to demonstrate Uniform usage and channel split/combine, remove/add as necessary
/// </summary>
//// Slot names
// Inputs
protected const string kInputSlotName = "Input";
protected const string kInputSlot1Name = "Input1";
// Input components
protected const string kInputSlotRName = "R";
protected const string kInputSlotGName = "G";
protected const string kInputSlotBName = "B";
protected const string kInputSlotAName = "A";
// Outputs
protected const string kOutputSlotName = "Output";
protected const string kOutputSlot1Name = "Output1";
// Output components
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
//// Slot IDs (Adjust ints when adding/removing IDs)
// Inputs
public const int InputSlotId = 0;
public const int InputSlot1Id = 1;
// Input components
public const int InputSlotRId = 2;
public const int InputSlotGId = 3;
public const int InputSlotBId = 4;
public const int InputSlotAId = 5;
// Outputs
public const int OutputSlotId = 6;
public const int OutputSlot1Id = 7;
// Output components
public const int OutputSlotRId = 8;
public const int OutputSlotGId = 9;
public const int OutputSlotBId = 10;
public const int OutputSlotAId = 11;
//// Add/remove slots after deserialize
public sealed override void UpdateNodeAfterDeserialization()
{
//// Add slots
// Inputs
AddSlot(new MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, SlotValueType.Vector4, Vector4.zero)); // Per slot: References to slot display name, shader output name, Id, In/Out, Type and Initial value
AddSlot(new MaterialSlot(InputSlot1Id, kInputSlot1Name, kInputSlot1Name, SlotType.Input, SlotValueType.Vector4, Vector4.zero));
// Input components
AddSlot(new MaterialSlot(InputSlotRId, kInputSlotRName, kInputSlotRName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(InputSlotGId, kInputSlotGName, kInputSlotGName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(InputSlotBId, kInputSlotBName, kInputSlotBName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(InputSlotAId, kInputSlotAName, kInputSlotAName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// Outputs
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
// Output components
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
// Remove invalid slots
RemoveSlotsNameNotMatching(validSlots);
}
//// Check for valid slots
protected int[] validSlots
{
get { return new[] { InputSlotId, InputSlot1Id, InputSlotRId, InputSlotGId, InputSlotBId, InputSlotAId, OutputSlotId, OutputSlot1Id, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId }; } //Remove/add as needed
}
/// <summary>
/// Define slots (End)
/// </summary>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Slot Functions (Start)
///
/// - Requirements based on intended use of the slot.
/// - Examples given below
/// </summary>
// Get Slot
// Used to get a MaterialSlot type reference of a slot
// Get be used to get current value, default value etc to be used when generating shader code
// One Instance needed per slot needing to access
protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
// Slot Dimension
// Convert value type to string
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
public string output1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType); }
}
// Get Input Slot Name
// Used to get the name of a slot needed to access the slot (see GetInputSlot())
protected virtual string GetInputSlotName() { return "Input"; }
// Used to get individual channels as slots
// Heavily modified (complicated) to allow accessing channels when using more than one Uniform
// See commented version below when using a single Uniform
public override string GetVariableNameForSlot(int slotId)
{
string prop; // Need a temporary string to get the Uniform name as dependant on slot
string slotOutput;
MaterialSlot slot = FindSlot<MaterialSlot>(slotId); //Get reference to this slot (used when not creating a Uniform)
MaterialSlot slot1 = FindSlot<MaterialSlot>(GetOutputSlot().id); //Get reference to output slot(0) (Used to combine channels into output(0) without a Uniform)
switch (slotId)
{
// Inputs
case InputSlotId: //
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot.shaderOutputName;
slotOutput = "";
break;
case InputSlot1Id:
prop = propertyName1;
slotOutput = "";
break;
case InputSlotRId:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot1.shaderOutputName;
slotOutput = ".r";
break;
case InputSlotGId:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot1.shaderOutputName;
slotOutput = ".g";
break;
case InputSlotBId:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot1.shaderOutputName;
slotOutput = ".b";
break;
case InputSlotAId:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot.shaderOutputName;
slotOutput = ".a";
break;
// Outputs
case OutputSlotId:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot.shaderOutputName;
slotOutput = "";
break;
case OutputSlot1Id:
// Taken from AbstractMaterialNode (used to send data through node without defining a Uniform)
if (slot == null)
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
prop = GetVariableNameForNode() + "_" + slot.shaderOutputName;
//prop = propertyName1;
slotOutput = "";
break;
case OutputSlotRId:
prop = propertyName;
slotOutput = ".r";
break;
case OutputSlotGId:
prop = propertyName;
slotOutput = ".g";
break;
case OutputSlotBId:
prop = propertyName;
slotOutput = ".b";
break;
case OutputSlotAId:
prop = propertyName;
slotOutput = ".a";
break;
default:
prop = propertyName;
slotOutput = "";
break;
}
return prop + slotOutput;
}
// Simplified version for a single Uniform
// When using a single Uniform the slot outputs will always be a single channel of that Uniform or that full Uniform
// By appending channels (.r etc) after the "propertyName" variable on specific slot IDs we can control the outputs
/*public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
case OutputSlotRId:
propertyName =
slotOutput = ".r"; // Return only red channel
break;
case OutputSlotGId:
slotOutput = ".g"; // Return only green channel
break;
case OutputSlotBId:
slotOutput = ".b"; // Return only blue channel
break;
case OutputSlotAId:
slotOutput = ".a"; // Return only alpha channel
break;
default:
slotOutput = ""; // Return full Uniform
break;
}
return propertyName + slotOutput; //Return Uniform name with appended channel name (or blank)
}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Variables for shader Uniforms (Start)
///
/// Each must have:
///
/// - Property name [serialized private & public get/set]
/// - Description [serialized private & public get/set]
/// - Property type (of the desired uniform) [public get]
/// - Value (of type of desired uniform) [serialized private & public get/set]
/// - Exposed state [serialized private & public get/set]
///
/// For changes needed for each new Uniform check comments on Uniform 2
/// </summary>
//// Uniform 1 (Input Vector 4 > Output 4 individual channels)
// PropertyName
// The name of the generated Uniform (note that it includes name [node name], guid [unique identifier] and "_Uniform" suffix)
[SerializeField]
private string m_PropertyName = string.Empty;
public string propertyName
{
get
{
if (exposedState == PropertyNode.ExposedState.NotExposed || string.IsNullOrEmpty(m_PropertyName))
return string.Format("{0}_{1}_Uniform", name, guid.ToString().Replace("-", "_"));
return m_PropertyName + "_Uniform";
}
set { m_PropertyName = value; }
}
// Description
// The ShaderGUI label of exposed properties (used when not exposed?)
[SerializeField]
private string m_Description = string.Empty;
public string description
{
get
{
if (string.IsNullOrEmpty(m_Description))
return m_PropertyName;
return m_Description;
}
set { m_Description = value; }
}
// Property type
// Defines the concrete type of the Uniform
public PropertyType propertyType
{
get
{
return PropertyType.Vector4; //Set Uniform type here
}
}
// Value
// The C# side variable for the Uniforms value
[SerializeField]
private Vector4 m_Value; //Set Uniform type here
public Vector4 value //Set Uniform type here
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null) //What is this variable?
onModified(this, ModificationScope.Node); //And what is this?
}
}
// Exposed state
// Determines whether the Uniform is exposed to the shader GUI (creates Shader Property)
[SerializeField]
private PropertyNode.ExposedState m_Exposed = PropertyNode.ExposedState.NotExposed;
public PropertyNode.ExposedState exposedState
{
get
{
return PropertyNode.ExposedState.NotExposed;
/*if (owner is SubGraph)
return PropertyNode.ExposedState.NotExposed;
return m_Exposed;*/
}
set
{
m_Exposed = PropertyNode.ExposedState.NotExposed;
/*if (m_Exposed == value)
return;
m_Exposed = value;*/
}
}
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------///
//// Uniform 1 (because no number = 0)
// PropertyName
// The name of the generated Uniform (note that it includes name [node name], guid [unique identifier] and "_Uniform" suffix)
[SerializeField]
private string m_PropertyName1 = string.Empty;
public string propertyName1
{
get
{
if (exposedState1 == PropertyNode.ExposedState.NotExposed || string.IsNullOrEmpty(m_PropertyName1))
return string.Format("{0}_{1}_Uniform1", name, guid.ToString().Replace("-", "_")); //Add 1 to shader side Uniform name in string here
return m_PropertyName1 + "_Uniform1"; //Add 1 to shader side Uniform name in string here
}
set { m_PropertyName1 = value; }
}
// Description
// What does this actually do? Seems to always contain the name...
[SerializeField]
private string m_Description1 = string.Empty;
public string description1
{
get
{
if (string.IsNullOrEmpty(m_Description1))
return m_PropertyName1;
return m_Description1;
}
set { m_Description1 = value; }
}
// Property type
// Defines the concrete type of the Uniform
public PropertyType propertyType1
{
get
{
return PropertyType.Vector4; //Set Uniform type here
}
}
// Value
// The C# side variable for the Uniforms value
[SerializeField]
private Vector4 m_Value1; //Set Uniform type here
public Vector4 value1 //Set Uniform type here
{
get { return m_Value1; }
set
{
if (m_Value1 == value)
return;
m_Value1 = value;
if (onModified != null) //What is this variable?
onModified(this, ModificationScope.Node); //And what is this?
}
}
// Exposed state
// Determines whether the Uniform is exposed to the shader GUI (creates Shader Property)
[SerializeField]
private PropertyNode.ExposedState m_Exposed1 = PropertyNode.ExposedState.NotExposed;
public PropertyNode.ExposedState exposedState1
{
get
{
return PropertyNode.ExposedState.NotExposed;
/*if (owner is SubGraph)
return PropertyNode.ExposedState.NotExposed;
return m_Exposed1;*/
}
set
{
m_Exposed1 = PropertyNode.ExposedState.NotExposed;
/*if (m_Exposed1 == value)
return;
m_Exposed1 = value;*/
}
}
/// <summary>
/// Variables for shader Uniforms (End)
/// </summary>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Add Uniforms & Properties to Shader (Start)
/// </summary>
// Generate a block of Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
//// Uniform 0
if (exposedState == PropertyNode.ExposedState.Exposed) // If exposed
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible)); // Add a property
//// Uniform 1
if (exposedState1 == PropertyNode.ExposedState.Exposed) // If exposed
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName1, description1, m_Value1, PropertyChunk.HideState.Visible)); // Add a property
}
// Generate Uniforms for exposed Properties
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
//// Uniform 0
if (exposedState == PropertyNode.ExposedState.Exposed) // If exposed
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true); // Add a Uniform
//// Uniform 1
if (exposedState1 == PropertyNode.ExposedState.Exposed) // If exposed
visitor.AddShaderChunk(precision + "4 " + propertyName1 + ";", true); // Add a Uniform
}
// Generate Frgament Function (?) code
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//// Uniform 0
if (exposedState == PropertyNode.ExposedState.Exposed) //If exposed
return; // Return (because already added in GeneratePropertyUsages())
var inputValue = GetSlotValue(InputSlotId, generationMode); // Get the input (0) slot value
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false); // Add a Uniform as = input (0) slot value
//// Uniform 1
if (exposedState1 == PropertyNode.ExposedState.Exposed) //If exposed
return; // Return (because already added in GeneratePropertyUsages())
var inputValue1 = GetSlotValue(InputSlot1Id, generationMode); // Get the input (0) slot value
visitor.AddShaderChunk(precision + "4 " + propertyName1 + " = " + inputValue1 + ";", false); // Add a Uniform as = input (0) slot value
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
visitor.AddShaderChunk(precision + output1Dimension + " " + GetVariableNameForSlot(OutputSlot1Id) + " = " + GetFunctionCallBody(input1Value) + ";", true);
/*string inputRValue = GetSlotValue(InputSlotRId, generationMode);
string inputGValue = GetSlotValue(InputSlotGId, generationMode);
string inputBValue = GetSlotValue(InputSlotBId, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(inputRValue, inputGValue, inputBValue) + ";", true);*/
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Function (Start)
/// </summary>
/// <returns></returns>
protected string GetFunctionName()
{
return "unity_abstractfunction_" + precision + "4";
}
protected virtual string GetFunctionPrototype(string arg1Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ")";
}
protected virtual string GetFunctionCallBody(string input1Value)
{
return GetFunctionName() + " (" + input1Value + ")";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return pow(arg1, 2.2);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
/*protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ", "
+ precision + input2Dimension + " " + arg3Name + ")";
}*/
/*protected virtual string GetFunctionCallBody(string input1Value, string input2Value, string input3Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ", " +input2Value + ")";
}*/
/*public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2", "arg3"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return "+precision+"3 (arg1, arg2, arg3);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}*/
/// <summary>
/// Function (End)
/// </summary>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Preview (Start)
/// Doesnt seem to work properly
/// Investigate
/// </summary>
public PreviewProperty GetPreviewProperty() // Override when inheriting from PropertyNode
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
/// <summary>
/// Preview (End)
/// </summary>
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/Templates/AbstractNode.cs.meta


fileFormatVersion: 2
guid: d1e71619c5d8ed94f892d9d9ec85e173
timeCreated: 1490920245
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

228
MaterialGraphProject/Assets/NewNodes/Maths/Templates/TestFunctionWithVariableNode.cs


using UnityEngine.Graphing;
using System.Collections.Generic;
namespace UnityEngine.MaterialGraph
{
[Title("Test/Function With Variable")]
public class TestFunctionWithVariableNode : AbstractMaterialNode, IGeneratesFunction, IGeneratesBodyCode
{
public TestFunctionWithVariableNode()
{
name = "FunctionWithVariable";
UpdateNodeAfterDeserialization(); //from helper
}
protected string GetFunctionName() //was override from helper
{
return "unity_functionwithvariable_" + precision;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
/// <summary>
/// START FROM PROPERTY NODE
/// </summary>
[SerializeField]
private Vector2 m_Value;
public PropertyType propertyType
{
get { return PropertyType.Vector2; }
}
[SerializeField]
private string m_PropertyName = string.Empty;
[SerializeField]
private string m_Description = string.Empty;
public override bool hasPreview { get { return true; } }
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(GetPreviewProperty());
}
public Vector2 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Nothing);
}
}
public string description
{
get
{
if (string.IsNullOrEmpty(m_Description))
return m_PropertyName;
return m_Description;
}
set { m_Description = value; }
}
public string propertyName
{
get
{
if (exposedState == PropertyNode.ExposedState.NotExposed || string.IsNullOrEmpty(m_PropertyName))
return string.Format("{0}_{1}_Uniform", name, guid.ToString().Replace("-", "_"));
return m_PropertyName + "_Uniform";
}
set { m_PropertyName = value; }
}
/// <summary>
/// START GENERATE MATERIAL PROPERTY
/// </summary>
[SerializeField]
private PropertyNode.ExposedState m_Exposed = PropertyNode.ExposedState.NotExposed;
public PropertyNode.ExposedState exposedState
{
get
{
if (owner is SubGraph)
return PropertyNode.ExposedState.NotExposed;
return m_Exposed;
}
set
{
if (m_Exposed == value)
return;
m_Exposed = value;
}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == PropertyNode.ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == PropertyNode.ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
}
public PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};
}
/// <summary>
/// END GENERATE MATERIAL PROPERTY
/// </summary>
///
void IGeneratesBodyCode.GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + "2 " + "THETHING" + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true); //This generates a local variable in the fragment function
}
/*void IGeneratesFunction.GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotId });
var inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(inputValue) + ";", true);
///
}*/
/// <summary>
/// END FROM PROPERTY NODE
/// </summary>
/// <summary>
/// START COPY FROM FUNCTION HELPER
/// </summary>
protected const string kInputSlotShaderName = "Input";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlotId = 0;
public const int OutputSlotId = 1;
protected string GetFunctionPrototype(string argName)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + inputDimension + " " + argName + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
public string inputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); }
}
protected string GetFunctionCallBody(string inputValue)
{
return GetFunctionName() + " (" + inputValue + ")";
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlotName() { return "Input"; }
protected virtual string GetOutputSlotName() { return "Output"; }
/// <summary>
/// END COPY FROM FUNCTION HELPER
/// </summary>
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/Templates/TestFunctionWithVariableNode.cs.meta


fileFormatVersion: 2
guid: 7267ec1e54399ed42846e79132c421a5
timeCreated: 1490868647
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
MaterialGraphProject/Assets/NewNodes/Maths/TruncNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Round/Truncate")]
public class TruncateNode : Function1Input
{
public TruncateNode()
{
name = "Truncate";
}
protected override string GetFunctionName() { return "truncate"; }
}
}

12
MaterialGraphProject/Assets/NewNodes/Maths/TruncNode.cs.meta


fileFormatVersion: 2
guid: b9b4b0e1cbbca934a8bb06144cf84730
timeCreated: 1490745905
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

20
MaterialGraphProject/Assets/NewNodes/Maths/_blank.ShaderGraph


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 562bd27a5e73fc64d80a1d9d936ffbd5, type: 3}
m_Name: _blank
m_EditorClassIdentifier:
m_DrawingData:
m_SerializableSelection: []
m_MaterialGraph:
m_SerializableNodes: []
m_SerializableEdges: []
m_ActiveMasterNodeGUIDSerialized: e1fe32e8-d786-4516-9370-86abdaf447ee
m_GeneratedShader: {fileID: 0}

9
MaterialGraphProject/Assets/NewNodes/Maths/_blank.ShaderGraph.meta


fileFormatVersion: 2
guid: 0a795d7056a5b8849ace08a9a57999d4
timeCreated: 1490871710
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

1001
MaterialGraphProject/Assets/NewNodes/Maths/_test.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/NewNodes/Maths/_test.ShaderGraph.meta


fileFormatVersion: 2
guid: b6b0bc8162b4fa941b802cd5a3aa03e5
timeCreated: 1490876285
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewNodes/TestAssets.meta


fileFormatVersion: 2
guid: f65c08d6acb9e794699bb04e8db778f3
folderAsset: yes
timeCreated: 1490784346
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

460
MaterialGraphProject/Assets/NewNodes/TestAssets/Clouds.png

之前 之后
宽度: 512  |  高度: 512  |  大小: 90 KiB

68
MaterialGraphProject/Assets/NewNodes/TestAssets/Clouds.png.meta


fileFormatVersion: 2
guid: 225a31f233f5b82488f996901413908d
timeCreated: 1490784346
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1001
MaterialGraphProject/Assets/NewNodes/TestAssets/ColorGuide.tif
文件差异内容过多而无法显示
查看文件

76
MaterialGraphProject/Assets/NewNodes/TestAssets/ColorGuide.tif.meta


fileFormatVersion: 2
guid: 9c50a18d04437449b86568cfcbb668a7
timeCreated: 1490800222
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

84
MaterialGraphProject/Assets/NewNodes/TestAssets/Depth.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Depth
m_Shader: {fileID: 48016340901358006, guid: b6b0bc8162b4fa941b802cd5a3aa03e5, type: 2}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Texture_1f625d09_998f_4b1c_999c_9d9b9480240c_Uniform:
m_Texture: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_d2171d4e_4d65_4369_9961_4451a161ca39_Uniform:
m_Texture: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- V4Node_1cacf324_04c7_4645_bd82_29633dc2c01d_Uniform: {r: 0, g: 1, b: 0, a: 0.1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

9
MaterialGraphProject/Assets/NewNodes/TestAssets/Depth.mat.meta


fileFormatVersion: 2
guid: 90f0a6e5e54aa494f9119a79d1071c65
timeCreated: 1490977286
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

171
MaterialGraphProject/Assets/NewNodes/TestAssets/Gradient.png

之前 之后
宽度: 512  |  高度: 512  |  大小: 16 KiB

76
MaterialGraphProject/Assets/NewNodes/TestAssets/Gradient.png.meta


fileFormatVersion: 2
guid: 543701356bb512c4cbd1e20cceb22ebb
timeCreated: 1490973774
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1001
MaterialGraphProject/Assets/NewNodes/TestAssets/Scene.unity
文件差异内容过多而无法显示
查看文件

8
MaterialGraphProject/Assets/NewNodes/TestAssets/Scene.unity.meta


fileFormatVersion: 2
guid: 939d670ecd2da174e8d96189a2164415
timeCreated: 1490975341
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

434
MaterialGraphProject/Assets/NewNodes/TestAssets/Sky1.jpg
文件差异内容过多而无法显示
查看文件

85
MaterialGraphProject/Assets/NewNodes/TestAssets/Sky1.jpg.meta


fileFormatVersion: 2
guid: f7111c407ddfe4109af9703cb740eaf9
timeCreated: 1495464172
licenseType: Pro
TextureImporter:
fileIDToRecycleName:
8900000: generatedCubemap
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 2
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1001
MaterialGraphProject/Assets/NewNodes/TestAssets/normal.png
文件差异内容过多而无法显示
查看文件

76
MaterialGraphProject/Assets/NewNodes/TestAssets/normal.png.meta


fileFormatVersion: 2
guid: cbf8f30fb344d2c48b8c6739b327ac7d
timeCreated: 1490631619
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 1
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

32
MaterialGraphProject/Assets/NewNodes/TestAssets/sfn_vertexcolor.png

之前 之后
宽度: 96  |  高度: 96  |  大小: 9.9 KiB

76
MaterialGraphProject/Assets/NewNodes/TestAssets/sfn_vertexcolor.png.meta


fileFormatVersion: 2
guid: ed6958aa821014dc9bc55ee355394931
timeCreated: 1490797376
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewNodes/WIP.meta


fileFormatVersion: 2
guid: c45e3faeaae50c6468a707d69f9895cd
folderAsset: yes
timeCreated: 1490744492
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

205
MaterialGraphProject/Assets/NewNodes/WIP/ComponentSplitNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Channels/Component Split")]
public class ComponentSplitNode : PropertyNode, IGeneratesBodyCode
{
protected const string kInputSlotName = "Input";
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
public const int InputSlotId = 0;
public const int OutputSlotRId = 1;
public const int OutputSlotGId = 2;
public const int OutputSlotBId = 3;
public const int OutputSlotAId = 4;
public ComponentSplitNode()
{
name = "ComponentSplit";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId }; }
}
[SerializeField]
private Vector4 m_Value;
public Vector4 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public override PropertyType propertyType { get { return PropertyType.Vector4; } }
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
var inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false);
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlotName() { return "Input"; }
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
default:
slotOutput = "";
break;
}
return propertyName + slotOutput;
//return GetVariableNameForNode() + slotOutput;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
/* TEXTURE
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
string body = "tex2D (" + propertyName + ", " + uvName + ")";
if (m_TextureType == TextureType.Bump)
body = precision + "4(UnpackNormal(" + body + "), 0)";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_Texture = defaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}*/
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/ComponentSplitNode.cs.meta


fileFormatVersion: 2
guid: 892fc353b154d0347854e3bebf1b49e7
timeCreated: 1490896965
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

227
MaterialGraphProject/Assets/NewNodes/WIP/CubemapNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Cubemap")]
public class CubemapNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "Refl";
protected const string kOutputSlotRGBAName = "RGBA";
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
public const int UvSlotId = 0;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId = 2;
public const int OutputSlotGId = 3;
public const int OutputSlotBId = 4;
public const int OutputSlotAId = 5;
[SerializeField]
private string m_SerializedCube;
//[SerializeField]
//private TextureType m_TextureType;
[Serializable]
private class CubemapHelper
{
public Cubemap cube;
}
public override bool hasPreview { get { return true; } }
#if UNITY_EDITOR
public Cubemap defaultCube
{
get
{
if (string.IsNullOrEmpty(m_SerializedCube))
return null;
var tex = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCube, tex);
return tex.cube;
}
set
{
if (defaultCube == value)
return;
var tex = new CubemapHelper();
tex.cube = value;
m_SerializedCube = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
public Cubemap defaultCube {get; set; }
#endif
/*public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}*/
public CubemapNode()
{
name = "Cubemap";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; }
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xyz", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector3, true);
}
string body = "texCUBE (" + propertyName + ", " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
default:
slotOutput = "";
break;
}
return GetVariableNameForNode() + slotOutput;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new CubemapPropertyChunk(
propertyName,
description,
defaultCube,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
CubemapPropertyChunk.ModifiableState.Modifiable
: CubemapPropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("samplerCUBE " + propertyName + ";", true);
}
/*
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot)
{
var uvSlot = FindInputSlot(kUVSlotName);
if (uvSlot != inputSlot)
return base.DrawSlotDefaultInput(rect, inputSlot);
var rectXmax = rect.xMax;
rect.x = rectXmax - 70;
rect.width = 70;
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
GUI.Label(rect, "From Mesh");
return false;
}
*/
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Cubemap,
m_Cubemap = defaultCube
};
}
public override PropertyType propertyType { get { return PropertyType.Cubemap; } }
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}

8
MaterialGraphProject/Assets/NewNodes/WIP/CubemapNode.cs.meta


fileFormatVersion: 2
guid: c184bca342bb146daa708a7ecda424fc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

126
MaterialGraphProject/Assets/NewNodes/WIP/CustomInput.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
//Custom version of FunctionXInput
public abstract class CustomInput : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kInputSlot3ShaderName = "Input3";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int InputSlot3Id = 2;
public const int OutputSlotId = 3;
public override bool hasPreview
{
get { return true; }
}
protected CustomInput()
{
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetInputSlot3());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, 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)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
string input3Value = GetSlotValue(InputSlot3Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true);
}
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3)
{
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public string input3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot3Id).concreteValueType); }
}
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/CustomInput.cs.meta


fileFormatVersion: 2
guid: a0dde0f118ff41c4d8aac08dda38de3d
timeCreated: 1490643385
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

146
MaterialGraphProject/Assets/NewNodes/WIP/Function1In3Out.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
//Custom version of FunctionXInput
public abstract class Function1In3Out : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlotShaderName = "Input";
protected const string kOutputSlot0ShaderName = "Output0";
protected const string kOutputSlot1ShaderName = "Output1";
protected const string kOutputSlot2ShaderName = "Output2";
protected const string kOutputSlot3ShaderName = "Output3";
public const int InputSlotId = 0;
public const int OutputSlot0Id = 1;
public const int OutputSlot1Id = 2;
public const int OutputSlot2Id = 3;
public const int OutputSlot3Id = 4;
public override bool hasPreview
{
get { return true; }
}
protected Function1In3Out()
{
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot());
AddSlot(GetOutputSlot0());
AddSlot(GetOutputSlot1());
AddSlot(GetOutputSlot2());
AddSlot(GetOutputSlot3());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlot0Id, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id }; }
//get { return new[] { InputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id }; }
}
protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot0()
{
return new MaterialSlot(OutputSlot0Id, GetOutputSlot0Name(), kOutputSlot0ShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot1()
{
return new MaterialSlot(OutputSlot1Id, GetOutputSlot1Name(), kOutputSlot1ShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot2()
{
return new MaterialSlot(OutputSlot2Id, GetOutputSlot2Name(), kOutputSlot2ShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot3()
{
return new MaterialSlot(OutputSlot3Id, GetOutputSlot3Name(), kOutputSlot3ShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlotName()
{
return "Input";
}
protected virtual string GetOutputSlot0Name()
{
return "Output0";
}
protected virtual string GetOutputSlot1Name()
{
return "Output1";
}
protected virtual string GetOutputSlot2Name()
{
return "Output2";
}
protected virtual string GetOutputSlot3Name()
{
return "Output3";
}
protected abstract string GetFunctionName();
//Need more args?
protected virtual string GetFunctionPrototype(string arg1Name)
{
return "inline " + precision + output1Dimension + " " + GetFunctionName() + " ("
+ precision + inputDimension + " " + arg1Name + ") ";
//+ "out " + precision + output2Dimension + " " + arg2Name + ", "
// + "out " + precision + output3Dimension + " " + arg3Name + ")";
}
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlot0Id, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id });
//NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlot1Id, OutputSlot2Id, OutputSlot3Id });
string inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlot0Id) + " = " + GetFunctionCallBody(inputValue) + ";", true);
//visitor.AddShaderChunk(precision + output1Dimension + " " + GetVariableNameForSlot(OutputSlot1Id) + " = " + GetFunctionCallBody(inputValue) + ";", true);
}
protected virtual string GetFunctionCallBody(string inputValue)
{
return GetFunctionName() + " (" + inputValue + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlot0Id).concreteValueType); }
}
public string output1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType); }
}
public string output2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlot2Id).concreteValueType); }
}
public string output3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlot3Id).concreteValueType); }
}
private string inputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); }
}
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/Function1In3Out.cs.meta


fileFormatVersion: 2
guid: 8ea55c52eee922d4198e9593ad861773
timeCreated: 1490741509
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存