浏览代码

Merge branch 'master' into blackboard

/main
Peter Bay Bastian 7 年前
当前提交
d00ca780
共有 67 个文件被更改,包括 1255 次插入206 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
  3. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PreviewProperty.cs
  4. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs
  5. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableTexture.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs
  9. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs
  10. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Implementation/NodeUtils.cs
  11. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
  12. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
  13. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/PBRMasterNode.cs
  14. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/UnlitMasterNode.cs
  15. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  16. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
  17. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector1Node.cs
  18. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector2Node.cs
  19. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector3Node.cs
  20. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector4Node.cs
  21. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
  22. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/MasterNode.cs
  23. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs
  24. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
  25. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/GraphUtil.cs
  26. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
  27. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  28. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
  29. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  30. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  31. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PreviewSceneResources.cs
  32. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
  33. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  34. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template
  35. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightUnlitPass.template
  36. 91
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanMaterialSlot.cs
  37. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanMaterialSlot.cs.meta
  38. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanShaderProperty.cs
  39. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanShaderProperty.cs.meta
  40. 84
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/BooleanNode.cs
  41. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/BooleanNode.cs.meta
  42. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic.meta
  43. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs
  44. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs.meta
  45. 51
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Shaders/BlitNoAlpha.shader
  46. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Shaders/BlitNoAlpha.shader.meta
  47. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/ComparisonNode.cs.meta
  48. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/BranchNode.cs.meta
  49. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AllNode.cs
  50. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AllNode.cs.meta
  51. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AnyNode.cs
  52. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AnyNode.cs.meta
  53. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsInfiniteNode.cs
  54. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsInfiniteNode.cs.meta
  55. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs
  56. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs.meta
  57. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AndNode.cs
  58. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AndNode.cs.meta
  59. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/BranchNode.cs
  60. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NandNode.cs
  61. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NandNode.cs.meta
  62. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/OrNode.cs
  63. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/OrNode.cs.meta
  64. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NotNode.cs
  65. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NotNode.cs.meta
  66. 145
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/ComparisonNode.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
var values = value.x.ToString();
string values = NodeUtils.FloatToShaderValue(value.x);
if (channelCount == 1)
return values;
for (var i = 1; i < channelCount; i++)

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs


return "(3)";
case ConcreteSlotValueType.Vector4:
return "(4)";
case ConcreteSlotValueType.Boolean:
return "(B)";
case ConcreteSlotValueType.Matrix2:
return "(2x2)";
case ConcreteSlotValueType.Matrix3:

return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
case SlotValueType.Vector1:
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden);
case SlotValueType.Boolean:
return new BooleanMaterialSlot(slotId, displayName, shaderOutputName, slotType, false, shaderStage, hidden);
}
throw new ArgumentOutOfRangeException("type", type, null);

|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Boolean:
return inputType == SlotValueType.Boolean;
}
return false;
}

return PropertyType.Texture;
case ConcreteSlotValueType.Cubemap:
return PropertyType.Cubemap;
case ConcreteSlotValueType.Boolean:
return PropertyType.Boolean;
case ConcreteSlotValueType.Vector1:
return PropertyType.Float;
case ConcreteSlotValueType.Vector2:

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PreviewProperty.cs


public Vector4 vector4Value;
[FieldOffset(0)]
public float floatValue;
[FieldOffset(0)]
public bool booleanValue;
}
Data m_Data;

}
}
public bool booleanValue
{
get
{
if (propType != PropertyType.Boolean)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Boolean, propType));
return m_Data.booleanValue;
}
set
{
if (propType != PropertyType.Boolean)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Boolean, propType));
m_Data.booleanValue = value;
}
}
const string k_SetErrorMessage = "Cannot set a {0} property on a PreviewProperty with type {1}.";
const string k_GetErrorMessage = "Cannot get a {0} property on a PreviewProperty with type {1}.";

block.SetVector(name, m_Data.vector4Value);
else if (propType == PropertyType.Float)
block.SetFloat(name, m_Data.floatValue);
else if (propType == PropertyType.Boolean)
block.SetFloat(name, m_Data.booleanValue ? 1 : 0);
}
}

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs


namespace UnityEditor.ShaderGraph
{
[Serializable]
public class SerializableCubemap : ISerializationCallbackReceiver
public class SerializableCubemap
{
[SerializeField]
private string m_SerializedCubemap;

public Cubemap cubemap;
}
Cubemap m_Cubemap;
if (m_Cubemap == null && !string.IsNullOrEmpty(m_SerializedCubemap))
{
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
m_Cubemap = cube.cubemap;
m_SerializedCubemap = null;
}
return m_Cubemap;
}
set { m_Cubemap = value; }
}
if (string.IsNullOrEmpty(m_SerializedCubemap))
return null;
public void OnBeforeSerialize()
{
var cube = new CubemapHelper { cubemap = cubemap };
m_SerializedCubemap = EditorJsonUtility.ToJson(cube, true);
}
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
return cube.cubemap;
}
set
{
if(cubemap == value)
return;
public void OnAfterDeserialize()
{
var cubemapHelper = new CubemapHelper();
cubemapHelper.cubemap = value;
m_SerializedCubemap = EditorJsonUtility.ToJson(cubemapHelper, true);
}
}
}
}

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableTexture.cs


namespace UnityEditor.ShaderGraph
{
[Serializable]
public class SerializableTexture : ISerializationCallbackReceiver
public class SerializableTexture
{
[SerializeField]
private string m_SerializedTexture;

public Texture texture;
}
Texture m_Texture;
if (m_Texture == null && !string.IsNullOrEmpty(m_SerializedTexture))
{
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
m_Texture = tex.texture;
m_SerializedTexture = null;
}
return m_Texture;
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
set { m_Texture = value; }
}
set
{
if (texture == value)
return;
public void OnBeforeSerialize()
{
var tex = new TextureHelper { texture = texture };
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
}
public void OnAfterDeserialize()
{
var textureHelper = new TextureHelper();
textureHelper.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(textureHelper, true);
}
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return value.ToString();
return NodeUtils.FloatToShaderValue(value);
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "2 (" + value.x + "," + value.y + ")";
return precision + "2 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "3 (" + value.x + "," + value.y + "," + value.z + ")";
return precision + "3 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + "," + NodeUtils.FloatToShaderValue(value.z) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")";
return precision + "4 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + "," + NodeUtils.FloatToShaderValue(value.z) + "," + NodeUtils.FloatToShaderValue(value.w) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

22
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Implementation/NodeUtils.cs


using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace UnityEditor.Graphing
{

{
switch (slotValue)
{
case ConcreteSlotValueType.Boolean:
return p.ToString();
case ConcreteSlotValueType.Vector1:
return p.ToString();
case ConcreteSlotValueType.Vector2:

char[] arr = input.ToCharArray();
arr = Array.FindAll<char>(arr, (c => (Char.IsLetterOrDigit(c))));
return new string(arr);
}
public static string FloatToShaderValue(float value)
{
if (Single.IsPositiveInfinity(value))
return "1.#INF";
else if (Single.IsNegativeInfinity(value))
return "-1.#INF";
else if (Single.IsNaN(value))
return "NAN";
else
{
decimal amount;
if( decimal.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out amount) )
return amount.ToString();
else
return value.ToString();
}
}
}
}

68
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs


}
};
private static void GenerateApplicationVertexInputs(ShaderGraphRequirements graphRequiements, ShaderGenerator vertexInputs)
{
vertexInputs.AddShaderChunk("struct GraphVertexInput", false);
vertexInputs.AddShaderChunk("{", false);
vertexInputs.Indent();
vertexInputs.AddShaderChunk("float4 vertex : POSITION;", false);
vertexInputs.AddShaderChunk("float3 normal : NORMAL;", false);
vertexInputs.AddShaderChunk("float4 tangent : TANGENT;", false);
if (graphRequiements.requiresVertexColor)
{
vertexInputs.AddShaderChunk("float4 color : COLOR;", false);
}
foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
vertexInputs.AddShaderChunk(string.Format("float4 texcoord{0} : TEXCOORD{0};", (int)channel), false);
vertexInputs.AddShaderChunk("UNITY_VERTEX_INPUT_INSTANCE_ID", true);
vertexInputs.Deindent();
vertexInputs.AddShaderChunk("};", false);
}
private static string GetShaderPassFromTemplate(string template, PBRMasterNode masterNode, Pass pass, GenerationMode mode, SurfaceMaterialOptions materialOptions)
{
var builder = new ShaderStringBuilder();

modelRequiements.requiresViewDir |= NeededCoordinateSpace.World;
modelRequiements.requiresMeshUVs.Add(UVChannel.UV1);
GenerateApplicationVertexInputs(requirements.Union(modelRequiements), vertexInputs);
GraphUtil.GenerateApplicationVertexInputs(requirements.Union(modelRequiements), vertexInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs);

if (masterNode.model == PBRMasterNode.Model.Specular)
defines.AddShaderChunk("#define _SPECULAR_SETUP 1", true);
switch (masterNode.alphaMode)
{
case PBRMasterNode.AlphaMode.AlphaBlend:
case PBRMasterNode.AlphaMode.AdditiveBlend:
defines.AddShaderChunk("#define _AlphaOut 1", true);
break;
}
defines.AddShaderChunk("#define _AlphaClip 1", true);
defines.AddShaderChunk("#define _AlphaClip 1", true);
var templateLocation = ShaderGenerator.GetTemplatePath(template);

resultPass = resultPass.Replace("${SurfaceInputs}", localSurfaceInputs.GetShaderString(3));
resultPass = resultPass.Replace("${SurfaceOutputRemap}", surfaceOutputRemap.GetShaderString(3));
resultPass = resultPass.Replace("${Tags}", string.Empty);
resultPass = resultPass.Replace("${Blending}", blendingVisitor.GetShaderString(2));
resultPass = resultPass.Replace("${Culling}", cullingVisitor.GetShaderString(2));

subShader.Indent();
subShader.AddShaderChunk("Tags{ \"RenderPipeline\" = \"LightweightPipeline\"}", true);
var materialOptions = new SurfaceMaterialOptions();
switch (masterNode.alphaMode)
{
case PBRMasterNode.AlphaMode.Opaque:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.On;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Geometry;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Opaque;
break;
case PBRMasterNode.AlphaMode.AlphaBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case PBRMasterNode.AlphaMode.AdditiveBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
}
var materialOptions = MasterNode.GetMaterialOptionsFromAlphaMode(masterNode.alphaMode);
var tagsVisitor = new ShaderGenerator();
materialOptions.GetTags(tagsVisitor);
subShader.AddShaderChunk(tagsVisitor.GetShaderString(0), true);

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs


PixelShaderSlots = new List<int>()
{
UnlitMasterNode.ColorSlotId,
UnlitMasterNode.AlphaSlotId
UnlitMasterNode.AlphaSlotId,
UnlitMasterNode.AlphaThresholdSlotId
}
};

public List<int> PixelShaderSlots;
}
private static string GetShaderPassFromTemplate(string template, UnlitMasterNode masterNode, Pass pass, GenerationMode mode)
private static string GetShaderPassFromTemplate(
string template,
UnlitMasterNode masterNode,
Pass pass,
GenerationMode mode,
SurfaceMaterialOptions materialOptions)
{
var builder = new ShaderStringBuilder();
builder.IncreaseIndent();

graph.AddShaderChunk(surfaceVertexShader.GetShaderString(2), false);
graph.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false);
var tagsVisitor = new ShaderGenerator();
var materialOptions = new SurfaceMaterialOptions();
materialOptions.GetTags(tagsVisitor);
materialOptions.GetBlend(blendingVisitor);
materialOptions.GetCull(cullingVisitor);
materialOptions.GetDepthTest(zTestVisitor);

var surfaceOutputRemap = new ShaderGenerator();
var reqs = ShaderGraphRequirements.none;
reqs.requiresNormal |= NeededCoordinateSpace.World;
reqs.requiresTangent |= NeededCoordinateSpace.World;
reqs.requiresBitangent |= NeededCoordinateSpace.World;
reqs.requiresPosition |= NeededCoordinateSpace.World;
reqs.requiresViewDir |= NeededCoordinateSpace.World;
ShaderGenerator.GenerateStandardTransforms(
3,

CoordinateSpace.World);
ShaderGenerator defines = new ShaderGenerator();
if (masterNode.IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId))
defines.AddShaderChunk("#define _AlphaClip 1", true);
var templateLocation = ShaderGenerator.GetTemplatePath(template);
foreach (var slot in usedSlots)

resultPass = resultPass.Replace("${SurfaceInputs}", localSurfaceInputs.GetShaderString(3));
resultPass = resultPass.Replace("${SurfaceOutputRemap}", surfaceOutputRemap.GetShaderString(3));
resultPass = resultPass.Replace("${Tags}", tagsVisitor.GetShaderString(2));
resultPass = resultPass.Replace("${Tags}", string.Empty);
resultPass = resultPass.Replace("${LOD}", "" + materialOptions.lod);
return resultPass;
}

subShader.Indent();
subShader.AddShaderChunk("Tags{ \"RenderType\" = \"Opaque\" \"RenderPipeline\" = \"LightweightPipeline\"}", true);
var materialOptions = MasterNode.GetMaterialOptionsFromAlphaMode(masterNode.alphaMode);
var tagsVisitor = new ShaderGenerator();
materialOptions.GetTags(tagsVisitor);
subShader.AddShaderChunk(tagsVisitor.GetShaderString(0), true);
mode),
mode,
materialOptions),
true);
subShader.Deindent();

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/PBRMasterNode.cs


namespace UnityEditor.ShaderGraph
{
public enum AlphaMode
{
Opaque,
AlphaBlend,
AdditiveBlend
}
[Serializable]
[Title("Master", "PBR")]
public class PBRMasterNode : MasterNode

Metallic
}
public enum AlphaMode
{
Opaque,
AlphaBlend,
AdditiveBlend
}
[SerializeField]
private Model m_Model = Model.Metallic;

public PBRMasterNode()
{
UpdateNodeAfterDeserialization();
}
public bool IsSlotConnected(int slotId)
{
var slot = FindSlot<MaterialSlot>(slotId);
return slot != null && owner.GetEdges(slot.slotReference).Any();
}
public sealed override void UpdateNodeAfterDeserialization()

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/UnlitMasterNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
namespace UnityEditor.ShaderGraph

{
public const string ColorSlotName = "Color";
public const string AlphaSlotName = "Alpha";
public const string AlphaClipThresholdSlotName = "AlphaClipThreshold";
public const int AlphaThresholdSlotId = 8;
[SerializeField]
private AlphaMode m_AlphaMode;
[EnumControl("")]
public AlphaMode alphaMode
{
get { return m_AlphaMode; }
set
{
if (m_AlphaMode == value)
return;
m_AlphaMode = value;
Dirty(ModificationScope.Graph);
}
}
public UnlitMasterNode()
{

name = "Unlit Master";
AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0f, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

ColorSlotId,
AlphaSlotId
AlphaSlotId,
AlphaThresholdSlotId
});
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


public virtual void UpdateNodeAfterDeserialization()
{}
public bool IsSlotConnected(int slotId)
{
var slot = FindSlot<MaterialSlot>(slotId);
return slot != null && owner.GetEdges(slot.slotReference).Any();
}
}
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs


UpdateNodeAfterDeserialization();
}
protected struct Boolean
{}
protected struct Vector1
{}

if (p.ParameterType.IsByRef)
t = p.ParameterType.GetElementType();
if (t == typeof(Boolean))
{
return SlotValueType.Boolean;
}
if (t == typeof(Vector1))
{
return SlotValueType.Vector1;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector1Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + NodeUtils.FloatToShaderValue(m_Value) + ";", true);
}
public override string GetVariableNameForSlot(int slotId)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector2Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForNode() + " = " + precision + "2" + m_Value + ";", true);
visitor.AddShaderChunk(string.Format("{0}2 {1} = {0}2({2},{3});", precision, GetVariableNameForNode(), NodeUtils.FloatToShaderValue(m_Value.x), NodeUtils.FloatToShaderValue(m_Value.y)), true);
}
public override string GetVariableNameForSlot(int slotId)

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector3Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "3 " + GetVariableNameForNode() + " = " + precision + "3" + m_Value + ";", true);
var s = string.Format("{0}3 {1} = {0}3({2},{3},{4});",
precision,
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z));
visitor.AddShaderChunk(s, true);
}
public override string GetVariableNameForSlot(int slotId)

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector4Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + precision + "4" + m_Value + ";", true);
var s = string.Format("{0}4 {1} = {0}4({2},{3},{4},{5});",
precision,
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z),
NodeUtils.FloatToShaderValue(m_Value.w));
visitor.AddShaderChunk(s, true);
}
public override string GetVariableNameForSlot(int slotId)

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs


AddSlot(new CubemapMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
else if (property is BooleanShaderProperty)
{
AddSlot(new BooleanMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

else if (property is ColorShaderProperty)
{
var result = string.Format("{0}4 {1} = {2};"
, precision
, GetVariableNameForSlot(OutputSlotId)
, property.referenceName);
visitor.AddShaderChunk(result, true);
}
else if (property is BooleanShaderProperty)
{
var result = string.Format("{0} {1} = {2};"
, precision
, GetVariableNameForSlot(OutputSlotId)
, property.referenceName);

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/MasterNode.cs


}
public abstract string GetShader(GenerationMode mode, string name, out List<PropertyCollector.TextureInfo> configuredTextures);
public static SurfaceMaterialOptions GetMaterialOptionsFromAlphaMode(AlphaMode alphaMode)
{
var materialOptions = new SurfaceMaterialOptions();
switch (alphaMode)
{
case AlphaMode.Opaque:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.On;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Geometry;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Opaque;
break;
case AlphaMode.AlphaBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.AdditiveBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
}
return materialOptions;
}
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs


Color,
Texture,
Cubemap,
Boolean,
Float,
Vector2,
Vector3,

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs


Vector4,
Vector3,
Vector2,
Vector1
Vector1,
Boolean
}
public enum ConcreteSlotValueType

Vector4,
Vector3,
Vector2,
Vector1
Vector1,
Boolean
}
public static class SlotValueHelper

"typeFloat4",
"typeFloat3",
"typeFloat2",
"typeFloat1"
"typeFloat1",
"typeBoolean"
};
public static string ToClassName(this ConcreteSlotValueType type)

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/GraphUtil.cs


foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
vertexInputs.AddShaderChunk(string.Format("float4 texcoord{0} : TEXCOORD{0};", (int)channel), false);
vertexInputs.AddShaderChunk("UNITY_VERTEX_INPUT_INSTANCE_ID", true);
vertexInputs.Deindent();
vertexInputs.AddShaderChunk("};", false);
}

finalBuilder.AppendLine(@"#include ""CoreRP/ShaderLibrary/Common.hlsl""");
finalBuilder.AppendLine(@"#include ""CoreRP/ShaderLibrary/Packing.hlsl""");
finalBuilder.AppendLine(@"#include ""CoreRP/ShaderLibrary/Color.hlsl""");
finalBuilder.AppendLine(@"#include ""CoreRP/ShaderLibrary/UnityInstancing.hlsl""");
finalBuilder.AppendLine(@"#include ""CoreRP/ShaderLibrary/EntityLighting.hlsl""");
finalBuilder.AppendLine(@"#include ""ShaderGraphLibrary/ShaderVariables.hlsl""");
finalBuilder.AppendLine(@"#include ""ShaderGraphLibrary/ShaderVariablesFunctions.hlsl""");

var foundEdges = graph.GetEdges(input.slotReference).ToArray();
if (foundEdges.Any())
{
var outputRef = foundEdges[0].outputSlot;
var fromNode = graph.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", NodeUtils.GetHLSLSafeName(input.shaderOutputName), fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", NodeUtils.GetHLSLSafeName(input.shaderOutputName), masterNode.GetSlotValue(input.id, mode)), true);
}
else
{

else if (masterNode.hasPreview)
{
foreach (var slot in masterNode.GetOutputSlots<MaterialSlot>())
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", NodeUtils.GetHLSLSafeName(slot.shaderOutputName), masterNode.GetVariableNameForSlot(slot.id)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", NodeUtils.GetHLSLSafeName(slot.shaderOutputName), masterNode.GetSlotValue(slot.id, mode)), true);
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs


private const string kErrorString = @"ERROR!";
public static string AdaptNodeOutput(AbstractMaterialNode node, int outputSlotId, ConcreteSlotValueType convertToType, bool textureSampleUVHack = false)
public static string AdaptNodeOutput(AbstractMaterialNode node, int outputSlotId, ConcreteSlotValueType convertToType)
{
var outputSlot = node.FindOutputSlot<MaterialSlot>(outputSlotId);

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


gm.AddItem(new GUIContent("Vector3"), false, () => AddProperty(new Vector3ShaderProperty()));
gm.AddItem(new GUIContent("Vector4"), false, () => AddProperty(new Vector4ShaderProperty()));
gm.AddItem(new GUIContent("Color"), false, () => AddProperty(new ColorShaderProperty()));
gm.AddItem(new GUIContent("Boolean"), false, () => AddProperty(new BooleanShaderProperty()));
gm.AddItem(new GUIContent("Texture"), false, () => AddProperty(new TextureShaderProperty()));
gm.AddItem(new GUIContent("Cubemap"), false, () => AddProperty(new CubemapShaderProperty()));
gm.ShowAsContext();

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs


m_ValueAction = Vector3Field;
else if (property is Vector4ShaderProperty)
m_ValueAction = Vector4Field;
else if (property is BooleanShaderProperty)
m_ValueAction = BooleanField;
if (m_ValueAction != null)
{

{
var fProp = (Vector4ShaderProperty)property;
fProp.value = EditorGUILayout.Vector4Field("", fProp.value);
}
void BooleanField()
{
var fProp = (BooleanShaderProperty)property;
fProp.value = EditorGUILayout.Toggle(fProp.value);
}
}
}

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


[NonSerialized]
bool m_HasError;
[NonSerialized]
public bool forceRedrawPreviews = false;
GraphEditorView m_GraphEditorView;
GraphEditorView graphEditorView

m_GraphEditorView.RemoveFromHierarchy();
m_GraphEditorView.Dispose();
}
m_GraphEditorView = value;
if (m_GraphEditorView != null)
{

graphEditorView = new GraphEditorView(this, materialGraph, asset.name) { persistenceKey = selectedGuid };
}
if (forceRedrawPreviews)
{
// Redraw all previews
foreach (INode node in m_GraphObject.graph.GetNodes<INode>())
node.Dirty(ModificationScope.Node);
forceRedrawPreviews = false;
}
graphEditorView.HandleGraphChanges();
graphObject.graph.ClearChanges();
}

Undo.ClearUndo(graphObject);
DestroyImmediate(graphObject);
}
graphEditorView = null;
}

var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
subGraph.Connect(outputSlotRef, inputSlotRef);
}
// one edge needs to go to outside world
else if (outputSlotExistsInSubgraph)
{

case ConcreteSlotValueType.Vector1:
prop = new FloatShaderProperty();
break;
case ConcreteSlotValueType.Boolean:
prop = new BooleanShaderProperty();
break;
default:
throw new ArgumentOutOfRangeException();
}

var graph = graphObject.graph as IShaderGraph;
if (graph == null)
return;
List<PropertyCollector.TextureInfo> configuredTextures;
graph.GetShader(Path.GetFileNameWithoutExtension(path), GenerationMode.ForReals, out configuredTextures);
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderGraphImporter;
if (shaderImporter == null)

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs


// Render 2D previews
m_SceneResources.camera.transform.position = -Vector3.forward * 2;
m_SceneResources.camera.transform.rotation = Quaternion.identity;
m_SceneResources.camera.orthographicSize = 1;
m_SceneResources.camera.orthographicSize = 0.5f;
m_SceneResources.camera.orthographic = true;
foreach (var renderData in m_RenderList2D)

m_PreviewPropertyBlock.SetFloat(m_OutputIdName, renderData.shaderData.node.tempId.index);
if (m_PreviewMaterial.shader != renderData.shaderData.shader)
m_PreviewMaterial.shader = renderData.shaderData.shader;
m_SceneResources.camera.targetTexture = renderData.renderTexture;
RenderTexture.active = renderData.renderTexture;
//Temp workaround for alpha previews...
var temp = RenderTexture.GetTemporary(renderData.renderTexture.descriptor);
RenderTexture.active = temp;
Graphics.Blit(Texture2D.whiteTexture, renderData.renderTexture, m_SceneResources.checkerboardMaterial);
Graphics.Blit(Texture2D.whiteTexture, temp, m_SceneResources.checkerboardMaterial);
m_SceneResources.camera.targetTexture = temp;
Graphics.DrawMesh(mesh, transform, m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;

Graphics.Blit(temp, renderData.renderTexture, m_SceneResources.blitNoAlphaMaterial);
RenderTexture.ReleaseTemporary(temp);
RenderTexture.active = previousRenderTexure;
renderData.texture = renderData.renderTexture;
}

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PreviewSceneResources.cs


public class PreviewSceneResources : IDisposable
{
readonly Scene m_Scene;
static Mesh s_Quad;
Material m_BlitNoAlphaMaterial;
static readonly Mesh[] s_Meshes = { null, null, null, null, null };
static readonly GUIContent[] s_MeshIcons = { null, null, null, null, null };

light1.color = new Color(.4f, .4f, .45f, 0f) * .7f;
m_CheckerboardMaterial = new Material(Shader.Find("Hidden/Checkerboard"));
m_BlitNoAlphaMaterial = new Material(Shader.Find("Hidden/BlitNoAlpha"));
blitNoAlphaMaterial.hideFlags = HideFlags.HideAndDontSave;
if (s_Meshes[0] == null)
{

Mesh quadMesh = Resources.GetBuiltinResource(typeof(Mesh), "Quad.fbx") as Mesh;
s_Meshes[4] = quadMesh;
}
if (s_Quad == null)
{
var vertices = new[]
{
new Vector3(-1f, -1f, 0f),
new Vector3(1f, 1f, 0f),
new Vector3(1f, -1f, 0f),
new Vector3(-1f, 1f, 0f)
};
var uvs = new[]
{
new Vector2(0f, 0f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 1f)
};
var indices = new[] { 0, 1, 2, 1, 0, 3 };
s_Quad = new Mesh
{
vertices = vertices,
uv = uvs,
triangles = indices
};
s_Quad.RecalculateNormals();
s_Quad.RecalculateBounds();
}
}
public Mesh sphere

public Mesh quad
{
get { return s_Quad; }
get { return s_Meshes[4]; }
}
public Material blitNoAlphaMaterial
{
get { return m_BlitNoAlphaMaterial; }
}
public Camera camera

{
UnityEngine.Object.DestroyImmediate(checkerboardMaterial, true);
m_CheckerboardMaterial = null;
}
if (blitNoAlphaMaterial != null)
{
UnityEngine.Object.DestroyImmediate(blitNoAlphaMaterial, true);
m_BlitNoAlphaMaterial = null;
}
EditorSceneManager.ClosePreviewScene(m_Scene);

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs


using System.Text;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing;
[ScriptedImporter(4, ShaderGraphImporter.ShaderGraphExtension)]
public class ShaderGraphImporter : ScriptedImporter

var text = GetShaderText<MaterialGraph>(ctx.assetPath, out configuredTextures);
if (text == null)
text = errorShader;
var name = Path.GetFileNameWithoutExtension(ctx.assetPath);
string shaderName = string.Format("graphs/{0}", name);
text = text.Replace("Hidden/GraphErrorShader2", shaderName);
var shader = ShaderUtil.CreateShaderAsset(text);

static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
MaterialGraphEditWindow[] windows = Resources.FindObjectsOfTypeAll<MaterialGraphEditWindow>();
foreach (var matGraphEditWindow in windows)
{
matGraphEditWindow.forceRedrawPreviews = true;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


}
MaterialGraphView {
background-color: rgb(20, 21, 21);
background-color: #202020;
}
MaterialNodeView.graphElement.node.MaterialNode {

width: 41;
margin-left: 0;
margin-right: 0;
}
BooleanSlotControlView {
flex-direction: row;
align-items: center;
}
BooleanSlotControlView > Toggle {
width: 20;
}
.edge.fromMatrix4, .edge.fromMatrix3, .edge.fromMatrix2 {

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template


#include "LWRP/ShaderLibrary/Core.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "CoreRP/ShaderLibrary/UnityInstancing.hlsl"
#include "ShaderGraphLibrary/Functions.hlsl"
${Graph}

half4 frag (GraphVertexOutput IN) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
${LocalPixelShader}

// Computes fog factor per-vertex
ApplyFog(color.rgb, IN.fogFactorAndVertexLight.x);
#if _AlphaOut
color.a = Alpha;
#else
color.a = 1;
#endif
#if _AlphaClip
clip(Alpha - AlphaClipThreshold);

26
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightUnlitPass.template


${ZTest}
${ZWrite}
HLSLPROGRAM
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature _SAMPLE_GI
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
#pragma multi_compile_instancing
#pragma vertex vert

#include "LWRP/ShaderLibrary/Core.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "LWRP/ShaderLibrary/InputSurface.hlsl"
#include "ShaderGraphLibrary/Functions.hlsl"
${Defines}

{
float4 position : POSITION;
${Interpolators}
UNITY_VERTEX_INPUT_INSTANCE_ID
};
GraphVertexOutput vert (GraphVertexInput v)

GraphVertexOutput o;
GraphVertexOutput o = (GraphVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
o.position = TransformObjectToHClip(v.vertex.xyz);
${VertexShader}
return o;

{
UNITY_SETUP_INSTANCE_ID(IN);
SurfaceInputs surfaceInput;
SurfaceInputs surfaceInput = (SurfaceInputs)0;
float3 Color = 0;
float Alpha = 0;
float3 Color = float3(0.5, 0.5, 0.5);
float Alpha = 1;
float AlphaClipThreshold = 0;
#if _AlphaClip
clip(Alpha - AlphaClipThreshold);
#endif
return half4(Color, Alpha);
}
ENDHLSL

91
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanMaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class BooleanMaterialSlot : MaterialSlot, IMaterialSlotHasValue<bool>
{
[SerializeField]
private bool m_Value;
[SerializeField]
private bool m_DefaultValue;
public BooleanMaterialSlot()
{}
public BooleanMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
bool value,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
m_DefaultValue = value;
m_Value = value;
}
public override VisualElement InstantiateControl()
{
return new BooleanSlotControlView(this);
}
public bool defaultValue { get { return m_DefaultValue; } }
public bool value
{
get { return m_Value; }
set { m_Value = value; }
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return (value ? 1 : 0).ToString();
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
var property = new BooleanShaderProperty()
{
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
generatePropertyBlock = false,
value = value
};
properties.AddShaderProperty(property);
}
public override SlotValueType valueType { get { return SlotValueType.Boolean; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Boolean; } }
public override PreviewProperty GetPreviewProperty(string name)
{
var pp = new PreviewProperty(PropertyType.Boolean)
{
name = name,
booleanValue = value
};
return pp;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as BooleanMaterialSlot;
if (slot != null)
value = slot.value;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanMaterialSlot.cs.meta


fileFormatVersion: 2
guid: efad93f5b8245a54fb4fee128fc0f3f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

58
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanShaderProperty.cs


using System;
using System.Text;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class BooleanShaderProperty : AbstractShaderProperty<bool>
{
public BooleanShaderProperty()
{
displayName = "Boolean";
}
public override PropertyType propertyType
{
get { return PropertyType.Boolean; }
}
public override Vector4 defaultValue
{
get { return new Vector4(); }
}
public override string GetPropertyBlockString()
{
var result = new StringBuilder();
result.Append("[Toggle] ");
result.Append(referenceName);
result.Append("(\"");
result.Append(displayName);
result.Append("\", Float) = ");
result.Append(value == true ? 1 : 0);
return result.ToString();
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("float {0}{1}", referenceName, delimiter);
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(PropertyType.Boolean)
{
name = referenceName,
booleanValue = value
};
}
public override INode ToConcreteNode()
{
return new BooleanNode { value = new Toggle(value) };
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BooleanShaderProperty.cs.meta


fileFormatVersion: 2
guid: 8891f9466e6b01c498c3f4b2c6abc0eb
timeCreated: 1505346922

84
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/BooleanNode.cs


using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Boolean")]
public class BooleanNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private bool m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public BooleanNode()
{
name = "Boolean";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new BooleanMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[ToggleControl("")]
public Toggle value
{
get { return new Toggle(m_Value); }
set
{
if (m_Value == value.isOn)
return;
m_Value = value.isOn;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new BooleanShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = m_Value
});
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + (m_Value ? 1 : 0) + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Boolean)
{
name = GetVariableNameForNode(),
booleanValue = m_Value
});
}
public IShaderProperty AsShaderProperty()
{
return new BooleanShaderProperty { value = m_Value };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/BooleanNode.cs.meta


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

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic.meta


fileFormatVersion: 2
guid: 1c5103f75b5ec7445bb4c7b5a36f6aec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs


using System;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class BooleanSlotControlView : VisualElement
{
BooleanMaterialSlot m_Slot;
public BooleanSlotControlView(BooleanMaterialSlot slot)
{
m_Slot = slot;
Action changedToggle = () => { OnChangeToggle(); };
var toggleField = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);
Add(toggleField);
}
void OnChangeToggle()
{
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Toggle Change");
var value = m_Slot.value;
value = !value;
m_Slot.value = value;
m_Slot.owner.Dirty(ModificationScope.Node);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs.meta


fileFormatVersion: 2
guid: 7fc29d436587748dcaaefd8669c3d946
timeCreated: 1510659384

51
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Shaders/BlitNoAlpha.shader


Shader "Hidden/BlitNoAlpha"
{
Properties
{
_MainTex ("Texture", any) = "" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
uniform float4 _MainTex_ST;
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return half4(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.texcoord).xyz, 1.0);
}
ENDCG
}
}
Fallback Off
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Shaders/BlitNoAlpha.shader.meta


fileFormatVersion: 2
guid: 50b406436c6214c49aaaa6011b71dde8
timeCreated: 1502007198
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/ComparisonNode.cs.meta


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

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/BranchNode.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AllNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "All")]
public class AllNode : CodeFunctionNode
{
public AllNode()
{
name = "All";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_All", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_All(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Boolean Out)
{
return
@"
{
Out = all(In);
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AllNode.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AnyNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Any")]
public class AnyNode : CodeFunctionNode
{
public AnyNode()
{
name = "Any";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Any", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Any(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Boolean Out)
{
return
@"
{
Out = any(In);
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AnyNode.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsInfiniteNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Is Infinite")]
public class IsInfiniteNode : CodeFunctionNode
{
public IsInfiniteNode()
{
name = "Is Infinite";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_IsInfinite", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_IsInfinite(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Boolean Out)
{
return
@"
{
Out = isinf(In);
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsInfiniteNode.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Is NaN")]
public class IsNanNode : CodeFunctionNode
{
public IsNanNode()
{
name = "Is NaN";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_IsNaN", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_IsNaN(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Boolean Out)
{
return
@"
{
Out = isnan(In);
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs.meta


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

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AndNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "And")]
public class AndNode : CodeFunctionNode
{
public AndNode()
{
name = "And";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_And", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_And(
[Slot(0, Binding.None)] Boolean A,
[Slot(1, Binding.None)] Boolean B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A && B;
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/AndNode.cs.meta


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

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/BranchNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Branch")]
public class BranchNode : CodeFunctionNode
{
public BranchNode()
{
name = "Branch";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Branch", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Branch(
[Slot(0, Binding.None)] Boolean Predicate,
[Slot(1, Binding.None, 1, 1, 1, 1)] DynamicDimensionVector True,
[Slot(2, Binding.None, 0, 0, 0, 0)] DynamicDimensionVector False,
[Slot(3, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = (Predicate * True) + abs((Predicate - 1) * False);
}
";
}
}
}

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NandNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Nand")]
public class NandNode : CodeFunctionNode
{
public NandNode()
{
name = "Nand";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Nand", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Nand(
[Slot(0, Binding.None)] Boolean A,
[Slot(1, Binding.None)] Boolean B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = !A && !B;
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NandNode.cs.meta


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

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/OrNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Or")]
public class OrNode : CodeFunctionNode
{
public OrNode()
{
name = "Or";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Or", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Or(
[Slot(0, Binding.None)] Boolean A,
[Slot(1, Binding.None)] Boolean B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A || B;
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/OrNode.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NotNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Utility", "Logic", "Not")]
public class NotNode : CodeFunctionNode
{
public NotNode()
{
name = "Not";
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Not", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Not(
[Slot(0, Binding.None)] Boolean In,
[Slot(1, Binding.None)] out Boolean Out)
{
return
@"
{
Out = !In;
}
";
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/NotNode.cs.meta


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

145
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/ComparisonNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
public enum ComparisonType
{
Equal,
NotEqual,
Less,
LessOrEqual,
Greater,
GreaterOrEqual
};
[Title("Utility", "Logic", "Comparison")]
public class ComparisonNode : CodeFunctionNode
{
public ComparisonNode()
{
name = "Comparison";
}
[SerializeField]
private ComparisonType m_ComparisonType = ComparisonType.Equal;
[EnumControl("")]
public ComparisonType comparisonType
{
get { return m_ComparisonType; }
set
{
if (m_ComparisonType == value)
return;
m_ComparisonType = value;
Dirty(ModificationScope.Graph);
}
}
public override bool hasPreview
{
get { return false; }
}
protected override MethodInfo GetFunctionToConvert()
{
switch(comparisonType)
{
case ComparisonType.NotEqual:
return GetType().GetMethod("Unity_Comparison_NotEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonType.Less:
return GetType().GetMethod("Unity_Comparison_Less", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonType.LessOrEqual:
return GetType().GetMethod("Unity_Comparison_LessOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonType.Greater:
return GetType().GetMethod("Unity_Comparison_Greater", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonType.GreaterOrEqual:
return GetType().GetMethod("Unity_Comparison_GreaterOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_Comparison_Equal", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_Comparison_Equal(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A == B ? 1 : 0;
}
";
}
static string Unity_Comparison_NotEqual(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A != B ? 1 : 0;
}
";
}
static string Unity_Comparison_Less(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A < B ? 1 : 0;
}
";
}
static string Unity_Comparison_LessOrEqual(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A <= B ? 1 : 0;
}
";
}
static string Unity_Comparison_Greater(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A > B ? 1 : 0;
}
";
}
static string Unity_Comparison_GreaterOrEqual(
[Slot(0, Binding.None)] Vector1 A,
[Slot(1, Binding.None)] Vector1 B,
[Slot(2, Binding.None)] out Boolean Out)
{
return
@"
{
Out = A >= B ? 1 : 0;
}
";
}
}
}
正在加载...
取消
保存