浏览代码

[shader graph]more support for multiple correct channeling.

/main
Tim Cooper 9 年前
当前提交
70760866
共有 28 个文件被更改,包括 4166 次插入297 次删除
  1. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 5
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  3. 38
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeAnchor.cs
  4. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AbsoluteNode.cs
  5. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs
  6. 42
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  7. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs
  8. 19
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/DotNode.cs
  9. 16
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function1Input.cs
  10. 14
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function2Input.cs
  11. 44
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function3Input.cs
  12. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/LerpNode.cs
  13. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MultiplyNode.cs
  14. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/NormalNode.cs
  15. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  16. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SlotValue.cs
  17. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubtractNode.cs
  18. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ViewDirectionNode.cs
  19. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
  20. 178
      UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph
  21. 988
      UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph
  22. 993
      UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph
  23. 992
      UnityProject/Assets/UnityShaderEditor/Graphs/SimpleGraph.ShaderGraph
  24. 980
      UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph
  25. 30
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeOutputAnchor.cs
  26. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeOutputAnchor.cs.meta
  27. 62
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs
  28. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs.meta

6
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs


base.RemoveEdge(edge);
}
var newEdge = base.Connect(fromSlot, toSlot);
var newEdge = base.Connect(outputSlot, inputSlot);
var toNode = toSlot.node as BaseMaterialNode;
var fromNode = fromSlot.node as BaseMaterialNode;
var toNode = inputSlot.node as BaseMaterialNode;
var fromNode = outputSlot.node as BaseMaterialNode;
if (fromNode == null || toNode == null)
return newEdge;

5
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs


using System;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.MaterialGraph

foreach (var slot in node.inputSlots)
{
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof (Vector4), slot, data));
AddChild(new NodeAnchor(pos, typeof (Vector4), slot, data, Direction.eInput));
}
var inputYMax = pos.y + 22;

foreach (var slot in node.outputSlots)
{
pos.y += 22;
AddChild(new NodeOutputAnchor(pos, typeof (Vector4), slot, data));
AddChild(new NodeAnchor(pos, typeof (Vector4), slot, data, Direction.eOutput));
}
pos.y += 22;

38
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeAnchor.cs


private MaterialGraphDataSource m_Data;
public Slot m_Slot;
public NodeAnchor(Vector3 position, Type type, Slot slot, MaterialGraphDataSource data)
public NodeAnchor(Vector3 position, Type type, Slot slot, MaterialGraphDataSource data, Direction direction)
m_Direction = Direction.eInput;
m_Direction = direction;
Type genericClass = typeof (PortSource<>);
Type constructedClass = genericClass.MakeGenericType(type);

}
private static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
{
switch (type)
{
case ConcreteSlotValueType.Vector1:
return "(1)";
case ConcreteSlotValueType.Vector2:
return "(2)";
case ConcreteSlotValueType.Vector3:
return "(3)";
case ConcreteSlotValueType.Vector4:
return "(4)";
default:
return "(E)";
}
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var anchorColor = Color.yellow;

Rect labelRect = new Rect(translation.x + scale.x + 10.0f, translation.y, parentRect.width, 20.0f);
GUI.Label(labelRect, m_Slot.name);
string text = m_Slot.name;
Rect labelRect;
if (m_Direction == Direction.eInput)
{
text += " " + ConcreteSlotValueTypeAsString(((BaseMaterialNode) m_Slot.node).GetConcreteInputSlotValueType(m_Slot));
labelRect = new Rect(translation.x + scale.x + 10.0f, translation.y, parentRect.width, 20.0f);
}
else
{
text += " " + ConcreteSlotValueTypeAsString(((BaseMaterialNode) m_Slot.node).GetConcreteOutputSlotValueType(m_Slot));
Vector2 sizeOfText = GUIStyle.none.CalcSize(new GUIContent(text));
labelRect = new Rect(translation.x - sizeOfText.x - 4.0f, translation.y, sizeOfText.x + 4.0f, sizeOfText.y + 4.0f);
}
GUI.Label(labelRect, text);
}
// IConnect

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AbsoluteNode.cs


var outputString = new ShaderGenerator();
foreach (var precision in m_PrecisionNames)
{
outputString.AddShaderChunk("inline " + precision + "4 unity_absolute_" + precision + " (" + precision + "4 arg1)", false);
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_absolute_" + precision + " (" + precision + outputDimension + " arg1)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return abs(arg1);", false);

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs


[Title("Math/Add Node")]
public class AddNode : Function2Input, IGeneratesFunction
{
[SerializeField] private float m_DefaultValue = 0.0f;
[SerializeField] private float m_DefaultValue;
public override void OnCreate()
{

var outputString = new ShaderGenerator();
foreach (var precision in m_PrecisionNames)
{
outputString.AddShaderChunk("inline " + precision + "4 unity_add_" + precision + " (" + precision + "4 arg1, " + precision + "4 arg2)", false);
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_add_" + precision + " (" + precision + outputDimension +" arg1, " + precision + outputDimension + " arg2)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 + arg2;", false);

42
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor.Graphs;
using UnityEditorInternal;
using UnityEngine;

{
get
{
UpdateConcreteSlotValueTypes();
if (m_Material == null)
{
m_Material = new Material(defaultPreviewShader) {hideFlags = HideFlags.DontSave};

get { return kPreviewHeight; }
}
public bool errorsCalculated { get; set; }
[NonSerialized]
private bool m_ErrorsCalculated;
public bool errorsCalculated
{
get { return m_ErrorsCalculated; }
set { m_ErrorsCalculated = value; }
}
[NonSerialized]
private bool m_HasError;
public bool hasError
{

get
{
if (!errorsCalculated)
UpdateConcreteSlotValueTypes();
UpdateConcreteSlotValueTypes();
return m_ConcreteInputSlotValueTypes;
}
}

public ConcreteSlotValueType GetConcreteOutputSlotValueType(Slot slot)
{
return m_ConcreteOutputSlotValueTypes[slot.name];
return concreteOutputSlotValueTypes[slot.name];
return m_ConcreteInputSlotValueTypes[slot.name];
return concreteInputSlotValueTypes[slot.name];
private ConcreteSlotValueType MaximumChannels(ConcreteSlotValueType @from, ConcreteSlotValueType to)
private ConcreteSlotValueType FindCommonChannelType(ConcreteSlotValueType @from, ConcreteSlotValueType to)
// if we have a singe channel input
// return the other channel.
if (@from == ConcreteSlotValueType.Vector1 || to == ConcreteSlotValueType.Vector1)
return @from > to ? @from : to;
if (ImplicitConversionExists(@from, to))
return to;

return ConcreteSlotValueType.Vector1;
case 1:
return inputTypesDistinct.FirstOrDefault();
case 2:
return MaximumChannels(inputTypesDistinct[0], inputTypesDistinct[1]);
return ConcreteSlotValueType.Error;
// find the 'minumum' channel width excluding 1 as it can promote
inputTypesDistinct.RemoveAll(x => x == ConcreteSlotValueType.Vector1);
var ordered = inputTypesDistinct.OrderBy(x => x);
if (ordered.Any())
return ordered.FirstOrDefault();
break;
return ConcreteSlotValueType.Error;
}
public void UpdateConcreteSlotValueTypes()

// if there is a connection
if (inputSlot.edges.Count == 0)
{
if (inputType != SlotValueType.Vector4Dynamic)
if (inputType != SlotValueType.Dynamic)
m_ConcreteInputSlotValueTypes.Add(inputSlot.name, ToConcreteType(inputType));
else
skippedDynamicSlots.Add(inputSlot);

var outputConcreteType = outputNode.GetConcreteOutputSlotValueType(outputSlot);
// if we have a standard connection... just check the types work!
if (inputType != SlotValueType.Vector4Dynamic)
if (inputType != SlotValueType.Dynamic)
m_ConcreteInputSlotValueTypes.Add(inputSlot.name, MaximumChannels (outputConcreteType, inputConcreteType));
m_ConcreteInputSlotValueTypes.Add(inputSlot.name, FindCommonChannelType (outputConcreteType, inputConcreteType));
continue;
}

continue;
}
if (m_SlotValueTypes[outputSlot.name] == SlotValueType.Vector4Dynamic)
if (m_SlotValueTypes[outputSlot.name] == SlotValueType.Dynamic)
{
m_ConcreteOutputSlotValueTypes.Add(outputSlot.name, dynamicType);
continue;

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs


[SerializeField]
private float m_Blend = 0.5f;
private static readonly string[] kOpNames = new[]
{
private static readonly string[] kOpNames = {
"normal",
"add"
};

protected void AddOperationBody(ShaderGenerator visitor, string name, string body, string precision)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk("inline " + precision + "4 unity_blend_" + name + "_" + precision + " (" + precision + "4 arg1, " + precision + "4 arg2, " + precision + " blend)", false);
outputString.AddShaderChunk("inline " + precision + outputDimension +" unity_blend_" + name + "_" + precision + " (" + precision + outputDimension + " arg1, " + precision + outputDimension + " arg2, " + precision + " blend)", false);
outputString.Deindent(); outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}

19
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/DotNode.cs


using UnityEditor.Graphs;
namespace UnityEditor.MaterialGraph
{
[Title("Math/Dot Node")]

}
protected override string GetFunctionName() { return "dot"; }
protected override MaterialGraphSlot GetInputSlot1()
{
var slot = new Slot(SlotType.InputSlot, GetInputSlot1Name());
return new MaterialGraphSlot(slot, SlotValueType.Vector3);
}
protected override MaterialGraphSlot GetInputSlot2()
{
var slot = new Slot(SlotType.InputSlot, GetInputSlot2Name());
return new MaterialGraphSlot(slot, SlotValueType.Vector3);
}
protected override MaterialGraphSlot GetOutputSlot()
{
var slot = new Slot(SlotType.OutputSlot, GetOutputSlotName());
return new MaterialGraphSlot(slot, SlotValueType.Vector1);
}
}
}

16
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function1Input.cs


protected virtual MaterialGraphSlot GetInputSlot()
{
var slot = new Slot(SlotType.InputSlot, GetInputSlotName());
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
}
protected virtual string GetInputSlotName() {return "Input"; }

inputValue = defaultValue.GetDefaultValue(generationMode, concreteInputSlotValueTypes[inputSlot.name]);
}
visitor.AddShaderChunk(precision + "4 " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(inputValue) + ";", true);
visitor.AddShaderChunk(precision + outputDimension + " " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(inputValue) + ";", true);
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteOutputSlotValueTypes[GetOutputSlotName()]); }
}
public string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteInputSlotValueTypes[GetInputSlotName()]); }
}
}
}

14
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function2Input.cs


protected virtual MaterialGraphSlot GetInputSlot1()
{
var slot = new Slot(SlotType.InputSlot, GetInputSlot1Name());
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
}
protected virtual string GetInputSlot1Name()

protected abstract string GetFunctionName();
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputSlot = FindOutputSlot(GetOutputSlotName());

{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{

44
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function3Input.cs


protected virtual MaterialGraphSlot GetInputSlot1()
{
var slot = new Slot(SlotType.InputSlot, GetInputSlot1Name());
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Vector4Dynamic);
return new MaterialGraphSlot(slot, SlotValueType.Dynamic);
}
protected virtual string GetInputSlot1Name()

protected abstract string GetFunctionName();
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ", "
+ precision + input3Dimension + " " + arg3Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputSlot = FindOutputSlot(GetOutputSlotName());

string input2Value = GetSlotValue(inputSlot2, generationMode);
string input3Value = GetSlotValue(inputSlot3, generationMode);
visitor.AddShaderChunk(precision + "4 " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true);
visitor.AddShaderChunk(precision + outputDimension + " " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true);
}
protected virtual string GetFunctionCallBody(string inputValue)
{
return GetFunctionName() + " (" + inputValue + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteOutputSlotValueTypes[GetOutputSlotName()]); }
}
public string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteInputSlotValueTypes[GetInputSlot1Name()]); }
}
public string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteInputSlotValueTypes[GetInputSlot2Name()]); }
}
public string input3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(concreteInputSlotValueTypes[GetInputSlot3Name()]); }
}
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/LerpNode.cs


using UnityEditor.Graphs;
namespace UnityEditor.MaterialGraph
{
[Title("Math/Lerp Node")]

var outputString = new ShaderGenerator();
foreach (var precision in m_PrecisionNames)
{
outputString.AddShaderChunk("inline " + precision + "4 unity_lerp_" + precision + " (" + precision + "4 first, " + precision + "4 second, " + precision + "4 s)", false);
outputString.AddShaderChunk(GetFunctionPrototype("first", "second", "s"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return lerp(first, second, s);", false);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MultiplyNode.cs


var outputString = new ShaderGenerator();
foreach (var precision in m_PrecisionNames)
{
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_multiply_" + precision + " (" + precision + input1Dimension + " arg1, " + precision + input2Dimension + " arg2)", false);
outputString.AddShaderChunk("inline " + precision + outputDimension + " " + GetFunctionName() + " (" + precision + input1Dimension + " arg1, " + precision + input2Dimension + " arg2)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 * arg2;", false);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/NormalNode.cs


if (generationMode == GenerationMode.Preview2D)
Debug.LogError("Trying to generate 2D preview on a node that does not support it!");
return generationMode.Is2DPreview() ? "half4 (IN.Normal, 1)" : "half4 (o.Normal, 1)";
return generationMode.Is2DPreview() ? "IN.Normal" : "o.Normal";
}
}
}

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs


AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kAlbedoSlotName), SlotValueType.Vector3));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kNormalSlotName), SlotValueType.Vector3));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kSpecularSlotName), SlotValueType.Vector1));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kSpecularSlotName), SlotValueType.Vector3));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kEmissionSlotName), SlotValueType.Vector3));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kMetallicSlotName), SlotValueType.Vector1));
AddSlot(new MaterialGraphSlot(new Slot(SlotType.InputSlot, kSmoothnessSlotName), SlotValueType.Vector1));

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SlotValue.cs


[Serializable]
public enum SlotValueType
{
Vector4Dynamic,
Dynamic,
Vector4,
Vector3,
Vector2,

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubtractNode.cs


var outputString = new ShaderGenerator();
foreach (var precision in m_PrecisionNames)
{
outputString.AddShaderChunk("inline " + precision + "4 unity_subtract_" + precision + " (" + precision + "4 arg1, " + precision + "4 arg2)", false);
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return arg1 - arg2;", false);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ViewDirectionNode.cs


if (generationMode == GenerationMode.Preview2D)
Debug.LogError("Trying to generate 2D preview on a node that does not support it!");
return "float4 (IN.viewDir, 1)";
return "IN.viewDir";
}
public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode)

6
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs


switch (outputConcreteType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("half2(({0}).x, 0.0f)", rawOutput);
return string.Format("half2(({0}).x, ({0}).x)", rawOutput);
case ConcreteSlotValueType.Vector3:
case ConcreteSlotValueType.Vector4:
return string.Format("half2(({0}).x, ({0}).y)", rawOutput);

switch (outputConcreteType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("half3(({0}).x, 0.0f, 0.0f)", rawOutput);
return string.Format("half3(({0}).x, ({0}).x, ({0}).x)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("half3(({0}).x, ({0}).y, 0.0f)", rawOutput);
case ConcreteSlotValueType.Vector4:

switch (outputConcreteType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("half4(({0}).x, 0.0f, 0.0f, 0.0f)", rawOutput);
return string.Format("half4(({0}).x, ({0}).x, ({0}).x, ({0}).x)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("half4(({0}).x, ({0}).y, 0.0f, 0.0f)", rawOutput);
case ConcreteSlotValueType.Vector3:

178
UnityProject/Assets/UnityShaderEditor/Graphs/FresnelSubGraph.ShaderSubGraph


- {fileID: 11400010}
- {fileID: 11400012}
- {fileID: 11400014}
- {fileID: 11400016}
- {fileID: 11400018}
edges:
- m_FromNode: {fileID: 11400006}

m_FromSlotName: Output
m_ToSlotName: Input2
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400016}
m_ToNode: {fileID: 11400018}
m_FromSlotName: Output
m_ToSlotName: Input
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400002}
m_ToNode: {fileID: 11400012}
m_FromSlotName: O00
m_ToSlotName: Input0
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11400002}
m_ToNode: {fileID: 11400016}
m_FromSlotName: O01
m_ToSlotName: Input
color: {r: 1, g: 1, b: 1, a: 1}
m_InvalidEdges: []
m_InputsNode: {fileID: 11400002}
m_OutputsNode: {fileID: 11400004}

height: 80
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 0.5, z: 1, w: 1}
m_Editable: 1
m_SlotName: O00
m_Node: {fileID: 11400002}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: O01
m_Node: {fileID: 11400002}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
m_PrecisionNames:
- half
--- !u!114 &11400004

height: 80
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: I00
m_Node: {fileID: 11400004}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
m_PrecisionNames:
- half
--- !u!114 &11400006

height: 105
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: ViewDirection
m_Node: {fileID: 11400006}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName: ViewDirection
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: ViewDirection
m_Node: {fileID: 11400006}
m_PrecisionNames:
- half
--- !u!114 &11400008

height: 105
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Normal
m_Node: {fileID: 11400008}
- slotName:
value:
m_DefaultVector: {x: 0, y: 0, z: 0, w: 0}
m_SlotName:
m_Node: {fileID: 0}
- slotName: Normal
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Normal
m_Node: {fileID: 11400008}
m_PrecisionNames:
- half
--- !u!114 &11400010

height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11400010}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input1
m_Node: {fileID: 11400010}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input2
m_Node: {fileID: 11400010}
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400010}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400010}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400010}
m_PrecisionNames:
- half
--- !u!114 &11400012

m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input 0
m_Name: Input0
m_Title: Input 1
m_Name: Input1
m_Title: Input 1
m_Name: Input1
m_Title: Input 2
m_Name: Input2
m_DataTypeString:
m_Properties: []
m_GenericTypeString:

height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11400012}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input0
m_Node: {fileID: 11400012}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input1
m_Node: {fileID: 11400012}
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400012}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400012}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400012}
m_PrecisionNames:
- half
--- !u!114 &11400014

height: 129
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11400014}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input1
m_Node: {fileID: 11400014}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input2
m_Node: {fileID: 11400014}
- slotName: Input1
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input1
m_Node: {fileID: 11400014}
- slotName: Input2
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input2
m_Node: {fileID: 11400014}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400014}
m_PrecisionNames:
- half
--- !u!114 &11400016

height: 117
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11400018}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input
m_Node: {fileID: 11400018}
- slotName: Input
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Input
m_Node: {fileID: 11400018}
- slotName: Output
value:
m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_SlotName: Output
m_Node: {fileID: 11400018}
m_PrecisionNames:
- half

988
UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph
文件差异内容过多而无法显示
查看文件

993
UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph
文件差异内容过多而无法显示
查看文件

992
UnityProject/Assets/UnityShaderEditor/Graphs/SimpleGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

980
UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph
文件差异内容过多而无法显示
查看文件

30
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeOutputAnchor.cs


using System;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class NodeOutputAnchor : NodeAnchor
{
public NodeOutputAnchor(Vector3 position, Type type, Slot slot, MaterialGraphDataSource data)
: base(position, type, slot, data)
{
m_Direction = Direction.eOutput;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var anchorColor = Color.yellow;
anchorColor.a = 0.7f;
base.Render(parentRect, canvas);
EditorGUI.DrawRect(new Rect(translation.x, translation.y, scale.x, scale.y), anchorColor);
Vector2 sizeOfText = GUIStyle.none.CalcSize(new GUIContent(m_Type.Name));
Rect labelRect = new Rect(translation.x - sizeOfText.x - 4.0f, translation.y, sizeOfText.x + 4.0f, sizeOfText.y + 4.0f);
GUI.Label(labelRect, m_Slot.name);
}
};
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/NodeOutputAnchor.cs.meta


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

62
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs


using UnityEngine;
namespace UnityEditor.MaterialGraph
{
[Title("Channels/Splat Node")]
class SplatNode : Function1Input
{
[SerializeField]
private int m_SwizzleChannel;
public override void OnCreate()
{
base.OnCreate();
name = "SplatNode";
m_SwizzleChannel = 0;
}
private string GetChannelFromConfiguration()
{
switch (m_SwizzleChannel)
{
case 0:
return "xxxx";
case 1:
return "yyyy";
case 2:
return "zzzz";
default:
return "wwww";
}
}
public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
string[] values = {"x", "y", "z", "w"};
EditorGUI.BeginChangeCheck();
m_SwizzleChannel = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Channel", m_SwizzleChannel, values);
if (EditorGUI.EndChangeCheck())
{
RegeneratePreviewShaders();
return true;
}
return false;
}
protected override string GetFunctionName()
{
return "";
}
protected override string GetFunctionCallBody(string inputValue)
{
return inputValue + "." + GetChannelFromConfiguration();
}
}
}

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs.meta


fileFormatVersion: 2
guid: c740b99e5a743e84d8030d697cc6d0a1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
正在加载...
取消
保存