浏览代码

working on shader compiler issues

/main
Tim Cooper 8 年前
当前提交
9ea47ed4
共有 24 个文件被更改,包括 455 次插入357 次删除
  1. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset.meta
  3. 2
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset
  4. 2
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset
  5. 2
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset
  6. 2
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset.meta
  7. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs
  9. 363
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset
  10. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset.meta
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/2DPreview.template
  12. 111
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  13. 64
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractSurfaceMasterNode.cs
  14. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs
  15. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs
  16. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  17. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
  18. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
  19. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/WorldPosNode.cs
  20. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  21. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  22. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs.meta
  23. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphNodeDrawData.cs
  24. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphNodeDrawData.cs.meta

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset


m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_Name: SerializableGraph.uss.imported
m_EditorClassIdentifier:
matchers:
- specificity: 2

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset.meta


fileFormatVersion: 2
guid: 692fd89d176246745ad1640285f640d1
timeCreated: 1478592749
timeCreated: 1478599791
licenseType: Pro
NativeFormatImporter:
userData:

2
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset


m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_Name: NodalView.uss.imported
m_EditorClassIdentifier:
matchers:
- specificity: 102

2
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset


m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_Name: SimpleContentView.uss.imported
m_EditorClassIdentifier:
matchers:
- specificity: 2

2
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset


m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_Name: GraphView.uss.imported
m_EditorClassIdentifier:
matchers:
- specificity: 11

2
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset.meta


fileFormatVersion: 2
guid: 1655c36f61ec5a5499f7dc1f3abea03c
timeCreated: 1478592706
timeCreated: 1478599799
licenseType: Pro
NativeFormatImporter:
userData:

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs


AddTypeMapping(typeof(Vector2Node), typeof(Vector2NodeDrawData));
AddTypeMapping(typeof(Vector3Node), typeof(Vector3NodeDrawData));
AddTypeMapping(typeof(Vector4Node), typeof(Vector4NodeDrawData));
AddTypeMapping(typeof(SubGraphNode), typeof(SubgraphNodeDrawData));
AddTypeMapping(typeof(EdgeDrawData), typeof(Edge));
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/NodePreviewDrawer.cs


{
public NodePreviewDrawData data;
public NodePreviewDrawer() {}
public override void DoRepaint(IStylePainter args)
public override void DoRepaint(IStylePainter painter)
base.DoRepaint(args);
painter.DrawTexture(position, image, new Color(1,1,1,1), scaleMode);
//base.DoRepaint(args);
}
}
}

363
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset


m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 11997, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_Name: MaterialGraph.uss.imported
m_EditorClassIdentifier:
matchers:
- specificity: 2

depth: 2147483647
previousIndex: -1
nextIndex: -1
- specificity: 202
- specificity: 2
- MaterialNodeDrawer
- HeaderDrawer
nextIndex: 2
- specificity: 202
nextIndex: -1
- specificity: 102
- header
selectorTypes: 06000000
ruleIndex: 1
- HeaderDrawer
selectorTypes: 02000000
ruleIndex: 2
previousIndex: 1
previousIndex: -1
- specificity: 202
- specificity: 102
ruleIndex: 1
ruleIndex: 2
- MaterialNodeDrawer
- HeaderDrawer
ruleIndex: 2
ruleIndex: 3
- expandButton
selectorTypes: 06000000
ruleIndex: 3
depth: 2147483647
previousIndex: 4
nextIndex: -1
- specificity: 102
selectorValues:
- MaterialNodeDrawer
selectorTypes: 02000000
ruleIndex: 4
depth: 2147483647
previousIndex: -1
nextIndex: 7
- specificity: 102
selectorValues:
ruleIndex: 2
ruleIndex: 4
previousIndex: 4
previousIndex: 6
ruleIndex: 3
ruleIndex: 5
nextIndex: 7
nextIndex: 9
ruleIndex: 3
ruleIndex: 5
previousIndex: 6
nextIndex: 8
previousIndex: 8
nextIndex: 10
ruleIndex: 3
ruleIndex: 5
previousIndex: 7
previousIndex: 9
ruleIndex: 4
ruleIndex: 6
nextIndex: 10
nextIndex: 12
ruleIndex: 4
ruleIndex: 6
previousIndex: 9
nextIndex: 11
previousIndex: 11
nextIndex: 13
ruleIndex: 4
ruleIndex: 6
previousIndex: 10
previousIndex: 12
ruleIndex: 5
ruleIndex: 7
nextIndex: 13
nextIndex: 15
ruleIndex: 5
ruleIndex: 7
previousIndex: 12
nextIndex: 14
previousIndex: 14
nextIndex: 16
ruleIndex: 5
ruleIndex: 7
previousIndex: 13
previousIndex: 15
ruleIndex: 6
ruleIndex: 8
nextIndex: 16
nextIndex: 18
ruleIndex: 6
ruleIndex: 8
previousIndex: 15
nextIndex: 17
previousIndex: 17
nextIndex: 19
ruleIndex: 6
ruleIndex: 8
previousIndex: 16
nextIndex: 18
previousIndex: 18
nextIndex: 20
ruleIndex: 6
ruleIndex: 8
previousIndex: 17
previousIndex: 19
ruleIndex: 7
ruleIndex: 9
nextIndex: 20
nextIndex: 22
ruleIndex: 7
ruleIndex: 9
previousIndex: 19
nextIndex: 21
previousIndex: 21
nextIndex: 23
ruleIndex: 7
ruleIndex: 9
previousIndex: 20
nextIndex: 22
previousIndex: 22
nextIndex: 24
ruleIndex: 7
ruleIndex: 9
previousIndex: 21
previousIndex: 23
ruleIndex: 8
ruleIndex: 10
nextIndex: 24
nextIndex: 26
ruleIndex: 8
ruleIndex: 10
previousIndex: 23
previousIndex: 25
ruleIndex: 9
ruleIndex: 11
nextIndex: 26
nextIndex: 28
ruleIndex: 9
ruleIndex: 11
previousIndex: 25
previousIndex: 27
ruleIndex: 10
ruleIndex: 12
nextIndex: 28
nextIndex: 30
ruleIndex: 10
ruleIndex: 12
previousIndex: 27
nextIndex: 29
previousIndex: 29
nextIndex: 31
ruleIndex: 10
ruleIndex: 12
previousIndex: 28
nextIndex: 30
previousIndex: 30
nextIndex: 32
ruleIndex: 10
ruleIndex: 12
previousIndex: 29
previousIndex: 31
ruleIndex: 11
ruleIndex: 13
nextIndex: 32
nextIndex: 34
ruleIndex: 11
ruleIndex: 13
previousIndex: 31
nextIndex: 33
previousIndex: 33
nextIndex: 35
ruleIndex: 11
ruleIndex: 13
previousIndex: 32
nextIndex: 34
previousIndex: 34
nextIndex: 36
ruleIndex: 11
ruleIndex: 13
previousIndex: 33
nextIndex: 35
previousIndex: 35
nextIndex: 37
ruleIndex: 11
ruleIndex: 13
previousIndex: 34
previousIndex: 36
ruleIndex: 12
ruleIndex: 14
nextIndex: 37
nextIndex: 39
ruleIndex: 12
ruleIndex: 14
previousIndex: 36
nextIndex: 38
previousIndex: 38
nextIndex: 40
ruleIndex: 12
ruleIndex: 14
previousIndex: 37
nextIndex: 39
previousIndex: 39
nextIndex: 41
ruleIndex: 12
ruleIndex: 14
previousIndex: 38
nextIndex: 40
previousIndex: 40
nextIndex: 42
ruleIndex: 12
ruleIndex: 14
previousIndex: 39
previousIndex: 41
ruleIndex: 13
ruleIndex: 15
nextIndex: 42
nextIndex: 44
ruleIndex: 13
ruleIndex: 15
previousIndex: 41
previousIndex: 43
ruleIndex: 14
ruleIndex: 16
nextIndex: 44
nextIndex: 46
ruleIndex: 14
ruleIndex: 16
previousIndex: 43
nextIndex: 45
previousIndex: 45
nextIndex: 47
ruleIndex: 14
ruleIndex: 16
previousIndex: 44
previousIndex: 46
ruleIndex: 15
ruleIndex: 17
nextIndex: 47
nextIndex: 49
ruleIndex: 15
ruleIndex: 17
previousIndex: 46
previousIndex: 48
ruleIndex: 16
ruleIndex: 18
nextIndex: 49
nextIndex: 51
ruleIndex: 16
ruleIndex: 18
previousIndex: 48
nextIndex: 50
previousIndex: 50
nextIndex: 52
ruleIndex: 16
ruleIndex: 18
previousIndex: 49
previousIndex: 51
ruleIndex: 17
ruleIndex: 19
depth: 2147483647
previousIndex: -1
nextIndex: -1

customPropertyNames: []
customPropertyHandles: []
- builtinPropertyHandles:
- type: 1
propertyID: 26
valueIndex: 1
customPropertyNames: []
customPropertyHandles: []
- builtinPropertyHandles:
- type: 3
propertyID: 40
valueIndex: 0

- type: 1
propertyID: 32
valueIndex: 2
customPropertyNames: []
customPropertyHandles: []
- builtinPropertyHandles:
- type: 3
propertyID: 40
- type: 1
propertyID: 12
valueIndex: 3
- type: 0
propertyID: 14
valueIndex: 1
- type: 0
propertyID: 13
valueIndex: 2
- type: 3
propertyID: 41
valueIndex: 2
- type: 0
propertyID: 17
valueIndex: 3
- type: 1
propertyID: 32
valueIndex: 4
valueIndex: 1
valueIndex: 4
valueIndex: 2
valueIndex: 5
valueIndex: 1
valueIndex: 3
valueIndex: 2
valueIndex: 5
valueIndex: 3
valueIndex: 6
valueIndex: 4
valueIndex: 7
valueIndex: 3
valueIndex: 6
valueIndex: 4
valueIndex: 7
valueIndex: 5
valueIndex: 8
valueIndex: 2
valueIndex: 4
valueIndex: 3
valueIndex: 5
valueIndex: 5
valueIndex: 8
valueIndex: 6
valueIndex: 9
valueIndex: 7
valueIndex: 10
valueIndex: 4
valueIndex: 6
valueIndex: 5
valueIndex: 7
valueIndex: 8
valueIndex: 11
valueIndex: 6
valueIndex: 9
valueIndex: 7
valueIndex: 10
valueIndex: 8
valueIndex: 11
valueIndex: 9
valueIndex: 12
valueIndex: 6
valueIndex: 8
valueIndex: 9
valueIndex: 12
valueIndex: 10
valueIndex: 13
valueIndex: 7
valueIndex: 9
valueIndex: 10
valueIndex: 13
valueIndex: 11
valueIndex: 14
customPropertyNames: []
customPropertyHandles: []
- builtinPropertyHandles: []

customPropertyHandles:
- type: 3
propertyID: 43
valueIndex: 8
valueIndex: 10
valueIndex: 9
valueIndex: 11
valueIndex: 10
valueIndex: 12
valueIndex: 11
valueIndex: 14
valueIndex: 12
valueIndex: 15
- 0
- 5
- 10
- 15
- 200
- 1

- 2
- 200
- 200
ints: 00000000040000000200000002000000020000000300000003000000050000000000000000000000000000004b0000000a000000
ints: 00000000020000000400000001000000040000000200000002000000020000000300000003000000050000000000000000000000000000004b0000000a000000
- {r: 1, g: 1, b: 1, a: 1}
- {r: 0, g: 0, b: 0, a: 1}
- {r: 0.26666668, g: 0.26666668, b: 0.26666668, a: 1}
- {r: 1, g: 1, b: 0, a: 1}
- {r: 1, g: 1, b: 0, a: 1}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset.meta


fileFormatVersion: 2
guid: 13814e9314253674e8d4966bba14d963
timeCreated: 1478592681
timeCreated: 1478599780
licenseType: Pro
NativeFormatImporter:
userData:

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/2DPreview.template


}
SubShader {
// inside SubShader
Tags
{
"Queue"="Geometry"
"RenderType"="Opaque"
"IgnoreProjector"="True"
}
// inside Pass
ZWrite On
Pass {
CGPROGRAM
#pragma vertex vert

111
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs


var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V4Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
[Test]
public void AdaptNodeOutput1To1PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V1Out, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V1Out)), result);
}
[Test]
public void AdaptNodeOutput1To2PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V1Out, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0})", node.GetVariableNameForSlot(TestNode.V1Out)), result);
}
[Test]
public void AdaptNodeOutput1To3PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V1Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0})", node.GetVariableNameForSlot(TestNode.V1Out)), result);
}
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V1Out, ConcreteSlotValueType.Vector4);
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V1Out);
[Test]
public void AdaptNodeOutput2To1PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V2Out, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetVariableNameForSlot(TestNode.V2Out)), result);
}
[Test]
public void AdaptNodeOutput2To2PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V2Out, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V2Out)), result);
}
[Test]
public void AdaptNodeOutput2To3PreviewWorks()
{
var node = new TestNode();
var expected = string.Format("half3({0}.x, {0}.y, 0.0)", node.GetVariableNameForSlot(TestNode.V2Out));
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V2Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(expected, result);
}
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V2Out, ConcreteSlotValueType.Vector4);
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V2Out);
public void AdaptNodeOutput3To1PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetVariableNameForSlot(TestNode.V3Out)), result);
}
[Test]
public void AdaptNodeOutput3To2PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0}.xy)", node.GetVariableNameForSlot(TestNode.V3Out)), result);
}
[Test]
public void AdaptNodeOutput3To3PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V3Out)), result);
}
[Test]
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out, ConcreteSlotValueType.Vector4);
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V3Out);
[Test]
public void AdaptNodeOutput4To1PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V4Out, ConcreteSlotValueType.Vector1);
Assert.AreEqual(string.Format("({0}).x", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
[Test]
public void AdaptNodeOutput4To2PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V4Out, ConcreteSlotValueType.Vector2);
Assert.AreEqual(string.Format("({0}.xy)", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
[Test]
public void AdaptNodeOutput4To3PreviewWorks()
{
var node = new TestNode();
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V4Out, ConcreteSlotValueType.Vector3);
Assert.AreEqual(string.Format("({0}.xyz)", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V4Out, ConcreteSlotValueType.Vector4);
var result = ShaderGenerator.AdaptNodeOutputForPreview(node, TestNode.V4Out);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
}

64
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractSurfaceMasterNode.cs


foreach (var node in activeNodeList.OfType<AbstractMaterialNode>())
{
if (node is IGeneratesFunction) (node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, mode);
if (node is IGenerateProperties)
{
(node as IGenerateProperties).GeneratePropertyBlock(shaderProperties, mode);
(node as IGenerateProperties).GeneratePropertyUsages(propertyUsages, mode);
}
if (node is IGeneratesFunction)
(node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, mode);
node.GeneratePropertyBlock(shaderProperties, mode);
node.GeneratePropertyUsages(propertyUsages, mode);
if (activeNodeList.Any(x => x is IRequiresMeshUV))
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV()))
if (activeNodeList.Any(x => x is IRequiresViewDirection))
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))
shaderInputVisitor.AddShaderChunk("float3 viewDir;", true);
shaderBody.AddShaderChunk("fixed3 worldViewDir = IN.viewDir;", true);
shaderInputVisitor.AddShaderChunk("float3 worldViewDir;", true);
shaderBody.AddShaderChunk("fixed3 worldViewDir = IN.worldViewDir;", true);
if (activeNodeList.Any(x => x is IRequiresWorldPosition))
if (activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition()))
if (activeNodeList.Any(x => x is IRequiresScreenPosition))
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition()))
if (activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
{
// is the normal connected?
var normalSlot = FindInputSlot<MaterialSlot>(NormalSlotId);
var edges = owner.GetEdges(normalSlot.slotReference);
shaderInputVisitor.AddShaderChunk("float3 worldNormal;", true);
if (edges.Any())
shaderInputVisitor.AddShaderChunk("INTERNAL_DATA", true);
}
var firstPassSlotId = NormalSlotId;
// do the normal slot first so that it can be used later in the shader :)
var firstPassSlot = FindInputSlot<MaterialSlot>(firstPassSlotId);
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, firstPassSlotId, NodeUtils.IncludeSelf.Exclude);
for (int index = 0; index < nodes.Count; index++)
{
var node = nodes[index];
if (node is IGeneratesBodyCode)
(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, generationMode);
}
foreach (var edge in owner.GetEdges(firstPassSlot.slotReference))
{
var outputRef = edge.outputSlot;
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
if (fromNode == null)
continue;
shaderBody.AddShaderChunk("o." + firstPassSlot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
}
// track the last index of nodes... they have already been processed :)
int pass2StartIndex = nodes.Count;
for (var i = pass2StartIndex; i < nodes.Count; i++)
for (var i = 0; i < nodes.Count; i++)
ListPool<INode>.Release(nodes);
foreach (var slot in GetInputSlots<MaterialSlot>())

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs


namespace UnityEngine.MaterialGraph
{
public interface IRequiresNormal
{ }
public interface IMayRequireNormal
{
bool RequiresNormal();
}
public class NormalNode : AbstractMaterialNode, IRequiresNormal
public class NormalNode : AbstractMaterialNode, IMayRequireNormal
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Normal";

public override string GetVariableNameForSlot(int slotId)
{
return "IN.worldNormal";
}
public bool RequiresNormal()
{
return true;
}
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs


namespace UnityEngine.MaterialGraph
{
public interface IRequiresScreenPosition
{ }
public interface IMayRequireScreenPosition
{
bool RequiresScreenPosition();
}
public class ScreenPosNode : AbstractMaterialNode, IRequiresScreenPosition
public class ScreenPosNode : AbstractMaterialNode, IMayRequireScreenPosition
{
public ScreenPosNode()
{

public override string GetVariableNameForSlot(int slotId)
{
return "IN.screenPos";
}
public bool RequiresScreenPosition()
{
return true;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture Node")]
public class TextureNode : PropertyNode, IGeneratesBodyCode, IRequiresMeshUV
public class TextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "UV";
protected const string kOutputSlotRGBAName = "RGBA";

}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public bool RequiresMeshUV()
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return (edges.Count <= 0);
}
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs


namespace UnityEngine.MaterialGraph
{
interface IRequiresMeshUV
{ }
interface IMayRequireMeshUV
{
bool RequiresMeshUV();
}
public class UVNode : AbstractMaterialNode, IGeneratesBodyCode, IRequiresMeshUV
public class UVNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotId = 0;
private const string kOutputSlotName = "UV";

{
string uvValue = "IN.meshUV0";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + uvValue + ";", true);
}
public bool RequiresMeshUV()
{
return true;
}
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs


namespace UnityEngine.MaterialGraph
{
interface IRequiresViewDirection : IRequiresWorldPosition
{}
interface IMayRequireViewDirection
{
bool RequiresViewDirection();
}
public class ViewDirectionNode : AbstractMaterialNode, IRequiresViewDirection
public class ViewDirectionNode : AbstractMaterialNode, IMayRequireViewDirection
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "ViewDirection";

public override string GetVariableNameForSlot(int slotId)
{
return "worldViewDir";
}
public bool RequiresViewDirection()
{
return true;
}
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/WorldPosNode.cs


namespace UnityEngine.MaterialGraph
{
interface IRequiresWorldPosition
{ }
interface IMayRequireWorldPosition
{
bool RequiresWorldPosition();
}
public class WorldPosNode : AbstractMaterialNode, IRequiresWorldPosition
public class WorldPosNode : AbstractMaterialNode, IMayRequireWorldPosition
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "WorldPos";

public override string GetVariableNameForSlot(int slotId)
{
return "IN.worldPos";
}
public bool RequiresWorldPosition()
{
return true;
}
}
}

49
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif

, IGeneratesBodyCode
, IGeneratesFunction
, IOnAssetEnabled
, IMayRequireNormal
, IMayRequireMeshUV
, IMayRequireScreenPosition
, IMayRequireViewDirection
, IMayRequireWorldPosition
{
[SerializeField]
private string m_SerializedSubGraph = string.Empty;

helper.subGraph = value;
m_SerializedSubGraph = EditorJsonUtility.ToJson(helper, true);
OnEnable();
if (onModified != null)
onModified(this, ModificationScope.Graph);
}
}
/*

return;
subGraph.GenerateVertexToFragmentBlock(visitor, GenerationMode.ForReals);
}
public bool RequiresNormal()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal());
}
public bool RequiresMeshUV()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV());
}
public bool RequiresScreenPosition()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition());
}
public bool RequiresViewDirection()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
}
public bool RequiresWorldPosition()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition());
}
}
}

46
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs


}
}
public static string AdaptNodeOutputForPreview(AbstractMaterialNode node, int outputSlotId, ConcreteSlotValueType convertToType)
public static string AdaptNodeOutputForPreview(AbstractMaterialNode node, int outputSlotId)
{
var outputSlot = node.FindOutputSlot<MaterialSlot>(outputSlotId);

var convertFromType = outputSlot.concreteValueType;
// if we are in a normal situation, just convert!
if (convertFromType >= convertToType || convertFromType == ConcreteSlotValueType.Vector1)
return AdaptNodeOutput(node, outputSlotId, convertToType);
// otherwise we need to pad output for the preview!
switch (convertToType)
// preview is always dimension 4, and we always ignore alpha
switch (convertFromType)
case ConcreteSlotValueType.Vector1:
return string.Format("half4({0}.x, 0.0, 0.0, 1.0)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("half4({0}.x, {0}.y, 0.0, 1.0)", rawOutput);
switch (convertFromType)
{
case ConcreteSlotValueType.Vector2:
return string.Format("half3({0}.x, {0}.y, 0.0)", rawOutput);
default:
return kErrorString;
}
return string.Format("half4({0}.x, {0}.y, {0}.z, 1.0)", rawOutput);
switch (convertFromType)
{
case ConcreteSlotValueType.Vector2:
return string.Format("half4({0}.x, {0}.y, 0.0, 1.0)", rawOutput);
case ConcreteSlotValueType.Vector3:
return string.Format("half4({0}.x, {0}.y, {0}.z, 1.0)", rawOutput);
default:
return kErrorString;
}
return string.Format("half4({0}.x, {0}.y, {0}.z, 1.0)", rawOutput);
default:
return kErrorString;
}

vertexShaderBlock.AddShaderChunk("float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));", true);
vertexShaderBlock.AddShaderChunk("float3 worldNormal = UnityObjectToWorldNormal(v.normal);", true);
if (activeNodeList.Any(x => x is IRequiresWorldPosition))
bool needsWorldPos = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
if (needsWorldPos || activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition()))
if (activeNodeList.Any(x => x is IRequiresNormal))
if (activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
if (activeNodeList.Any(x => x is IRequiresMeshUV))
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV()))
if (activeNodeList.Any(x => x is IRequiresViewDirection))
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))
if (activeNodeList.Any(x => x is IRequiresScreenPosition))
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition()))
{
shaderInputVisitor.AddShaderChunk("float4 screenPos : TEXCOORD3;", true);
vertexShaderBlock.AddShaderChunk("o.screenPos = screenPos;", true);

activeNode.GeneratePropertyUsages(shaderPropertyUsagesVisitor, generationMode);
}
shaderBodyVisitor.AddShaderChunk("return " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First().id, ConcreteSlotValueType.Vector4) + ";", true);
shaderBodyVisitor.AddShaderChunk("return " + AdaptNodeOutputForPreview(node, node.GetOutputSlots<MaterialSlot>().First().id) + ";", true);
ListPool<INode>.Release(activeNodeList);

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs.meta


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

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphNodeDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SubgraphContolDrawData : ControlDrawData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var subGraphNode = node as SubGraphNode;
if (subGraphNode == null)
return;
subGraphNode.subGraphAsset = (MaterialSubGraphAsset)EditorGUILayout.MiniThumbnailObjectField(
new GUIContent("Subgraph"),
subGraphNode.subGraphAsset,
typeof(MaterialSubGraphAsset), null);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SubgraphNodeDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<SubgraphContolDrawData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphNodeDrawData.cs.meta


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