GitHub
8 年前
当前提交
1172640f
共有 49 个文件被更改,包括 908 次插入 和 778 次删除
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/EdgeConnector.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/SerializableGraph.uss.imported.asset.meta
-
2MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodalView.uss.imported.asset.meta
-
2MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.imported.asset.meta
-
2MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/EdgeData.cs
-
2MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.imported.asset.meta
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
-
77MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
-
412MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss.imported.asset.meta
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/2DPreview.template
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/shader.template
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/Interfaces.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalNode.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
-
29MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/WorldPosNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
-
229MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
-
18MaterialGraphProject/Assets/assetr.ShaderSubGraph
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/COPIED/SelectionDragger.cs.meta
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs.meta
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs.meta
-
32MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMasterNode.cs
-
201MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractSurfaceMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractSurfaceMasterNode.cs.meta
-
57MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MetallicMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MetallicMasterNode.cs.meta
-
57MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SpecularMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SpecularMasterNode.cs.meta
-
41MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/3DPreview.template
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/3DPreview.template.meta
-
201MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMasterNode.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 692fd89d176246745ad1640285f640d1 |
|||
timeCreated: 1478070440 |
|||
timeCreated: 1478592749 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: ae904e6b00e321143b960221024f7fc3 |
|||
timeCreated: 1478070317 |
|||
timeCreated: 1478592722 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: fbe164d03ec59254eafe10baa5a9c5ba |
|||
timeCreated: 1478070327 |
|||
timeCreated: 1478592725 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1655c36f61ec5a5499f7dc1f3abea03c |
|||
timeCreated: 1478070258 |
|||
timeCreated: 1478592706 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: 13814e9314253674e8d4966bba14d963 |
|||
timeCreated: 1478162579 |
|||
timeCreated: 1478592681 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8539d5b9cb1cfe24589be23c34008c2f |
|||
timeCreated: 1478187487 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3a2754e4165dbb54e886b7604ffbfb31 |
|||
timeCreated: 1478187487 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 82f528cda04f18f4090208d5ff5a4700 |
|||
timeCreated: 1478187487 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
interface IMasterNode |
|||
{ |
|||
string GetShader( |
|||
MaterialOptions options, |
|||
GenerationMode mode, |
|||
out List<PropertyGenerator.TextureInfo> configuredTextures); |
|||
} |
|||
|
|||
[Serializable] |
|||
public abstract class AbstractMasterNode : AbstractMaterialNode, IMasterNode |
|||
{ |
|||
protected override bool generateDefaultInputs { get { return false; } } |
|||
|
|||
public override IEnumerable<ISlot> GetInputsWithNoConnection() |
|||
{ |
|||
return new List<ISlot>(); |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public abstract string GetShader(MaterialOptions options, GenerationMode mode, out List<PropertyGenerator.TextureInfo> configuredTextures); |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text.RegularExpressions; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Math/Add Node")] |
|||
public abstract class AbstractSurfaceMasterNode : AbstractMasterNode |
|||
{ |
|||
public const string AlbedoSlotName = "Albedo"; |
|||
public const string NormalSlotName = "Normal"; |
|||
public const string EmissionSlotName = "Emission"; |
|||
public const string SmoothnessSlotName = "Smoothness"; |
|||
public const string OcclusionSlotName = "Occlusion"; |
|||
public const string AlphaSlotName = "Alpha"; |
|||
|
|||
public const int AlbedoSlotId = 0; |
|||
public const int NormalSlotId = 1; |
|||
public const int EmissionSlotId = 3; |
|||
public const int SmoothnessSlotId = 4; |
|||
public const int OcclusionSlotId = 5; |
|||
public const int AlphaSlotId = 6; |
|||
|
|||
public abstract string GetSurfaceOutputName(); |
|||
public abstract string GetLightFunction(); |
|||
|
|||
public override string GetShader( |
|||
MaterialOptions options, |
|||
GenerationMode mode, |
|||
out List<PropertyGenerator.TextureInfo> configuredTextures) |
|||
{ |
|||
var templateLocation = ShaderGenerator.GetTemplatePath("shader.template"); |
|||
|
|||
if (!File.Exists(templateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyGenerator.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var templateText = File.ReadAllText(templateLocation); |
|||
|
|||
var shaderBodyVisitor = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var shaderPropertiesVisitor = new PropertyGenerator(); |
|||
var shaderPropertyUsagesVisitor = new ShaderGenerator(); |
|||
var shaderInputVisitor = new ShaderGenerator(); |
|||
var vertexShaderBlock = new ShaderGenerator(); |
|||
|
|||
GenerateSurfaceShaderInternal( |
|||
shaderBodyVisitor, |
|||
shaderFunctionVisitor, |
|||
shaderInputVisitor, |
|||
vertexShaderBlock, |
|||
shaderPropertiesVisitor, |
|||
shaderPropertyUsagesVisitor, |
|||
mode); |
|||
|
|||
var tagsVisitor = new ShaderGenerator(); |
|||
var blendingVisitor = new ShaderGenerator(); |
|||
var cullingVisitor = new ShaderGenerator(); |
|||
var zTestVisitor = new ShaderGenerator(); |
|||
var zWriteVisitor = new ShaderGenerator(); |
|||
|
|||
options.GetTags(tagsVisitor); |
|||
options.GetBlend(blendingVisitor); |
|||
options.GetCull(cullingVisitor); |
|||
options.GetDepthTest(zTestVisitor); |
|||
options.GetDepthWrite(zWriteVisitor); |
|||
|
|||
var resultShader = templateText.Replace("${ShaderName}", GetType() + guid.ToString()); |
|||
resultShader = resultShader.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ShaderPropertyUsages}", shaderPropertyUsagesVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${LightingFunctionName}", GetLightFunction()); |
|||
resultShader = resultShader.Replace("${SurfaceOutputStructureName}", GetSurfaceOutputName()); |
|||
resultShader = resultShader.Replace("${ShaderFunctions}", shaderFunctionVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ShaderInputs}", shaderInputVisitor.GetShaderString(3)); |
|||
resultShader = resultShader.Replace("${PixelShaderBody}", shaderBodyVisitor.GetShaderString(3)); |
|||
resultShader = resultShader.Replace("${Tags}", tagsVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${Blending}", blendingVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${Culling}", cullingVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ZTest}", zTestVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2)); |
|||
|
|||
resultShader = resultShader.Replace("${VertexShaderDecl}", "vertex:vert"); |
|||
resultShader = resultShader.Replace("${VertexShaderBody}", vertexShaderBlock.GetShaderString(3)); |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
|
|||
return Regex.Replace(resultShader, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
|
|||
} |
|||
|
|||
private void GenerateSurfaceShaderInternal( |
|||
ShaderGenerator shaderBody, |
|||
ShaderGenerator nodeFunction, |
|||
ShaderGenerator shaderInputVisitor, |
|||
ShaderGenerator vertexShaderBlock, |
|||
PropertyGenerator shaderProperties, |
|||
ShaderGenerator propertyUsages, |
|||
GenerationMode mode) |
|||
{ |
|||
var activeNodeList = new List<INode>(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
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); |
|||
} |
|||
} |
|||
|
|||
// always add color because why not.
|
|||
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true); |
|||
|
|||
if (activeNodeList.Any(x => x is IRequiresMeshUV)) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("half4 meshUV0 : TEXCOORD0;", true); |
|||
vertexShaderBlock.AddShaderChunk("o.meshUV0 = v.texcoord;", true); |
|||
} |
|||
|
|||
if (activeNodeList.Any(x => x is IRequiresViewDirection)) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float3 viewDir;", true); |
|||
shaderBody.AddShaderChunk("fixed3 worldViewDir = IN.viewDir;", true); |
|||
} |
|||
|
|||
if (activeNodeList.Any(x => x is IRequiresWorldPosition)) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float3 worldPos;", true); |
|||
} |
|||
|
|||
if (activeNodeList.Any(x => x is IRequiresScreenPosition)) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float4 screenPos;", true); |
|||
} |
|||
|
|||
GenerateNodeCode(shaderBody, mode); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator shaderBody, GenerationMode generationMode) |
|||
{ |
|||
var firstPassSlotId = NormalSlotId; |
|||
// do the normal slot first so that it can be used later in the shader :)
|
|||
var firstPassSlot = FindInputSlot<MaterialSlot>(firstPassSlotId); |
|||
var nodes = ListPool<INode>.Get(); |
|||
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; |
|||
|
|||
//Get the rest of the nodes for all the other slots
|
|||
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, null, NodeUtils.IncludeSelf.Exclude); |
|||
for (var i = pass2StartIndex; i < nodes.Count; i++) |
|||
{ |
|||
var node = nodes[i]; |
|||
if (node is IGeneratesBodyCode) |
|||
(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, generationMode); |
|||
} |
|||
|
|||
ListPool<INode>.Release(nodes); |
|||
|
|||
foreach (var slot in GetInputSlots<MaterialSlot>()) |
|||
{ |
|||
foreach (var edge in owner.GetEdges(slot.slotReference)) |
|||
{ |
|||
var outputRef = edge.outputSlot; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|||
if (fromNode == null) |
|||
continue; |
|||
|
|||
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f956d787e3ba4a84484d424011bcca14 |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/Metallic")] |
|||
public class MetallicMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string MetallicSlotName = "Metallic"; |
|||
public const int MetallicSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "Standard"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandard"; |
|||
|
|||
public MetallicMasterNode() |
|||
{ |
|||
name = "MetallicMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
MetallicSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetSurfaceOutputName() |
|||
{ |
|||
return SurfaceOutputStructureName; |
|||
} |
|||
|
|||
public override string GetLightFunction() |
|||
{ |
|||
return LightFunctionName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 42127be94ae3fe2469834cecaa1a185e |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/Specular")] |
|||
public class SpecularMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string SpecularSlotName = "Specular"; |
|||
public const int SpecularSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "StandardSpecular"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandardSpecular"; |
|||
|
|||
public SpecularMasterNode() |
|||
{ |
|||
name = "SpecularMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
SpecularSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetSurfaceOutputName() |
|||
{ |
|||
return SurfaceOutputStructureName; |
|||
} |
|||
|
|||
public override string GetLightFunction() |
|||
{ |
|||
return LightFunctionName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ce805d849104fa244b396c52f2531f13 |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "${ShaderName}" |
|||
{ |
|||
Properties |
|||
{ |
|||
${ShaderPropertiesHeader} |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
LOD 200 |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
#pragma surface surf Lambert ${VertexShaderDecl} |
|||
#pragma glsl |
|||
#pragma debug |
|||
|
|||
|
|||
${ShaderFunctions} |
|||
|
|||
${ShaderPropertyUsages} |
|||
|
|||
struct Input |
|||
{ |
|||
${ShaderInputs} |
|||
}; |
|||
|
|||
void vert (inout appdata_full v, out Input o) |
|||
{ |
|||
UNITY_INITIALIZE_OUTPUT(Input,o); |
|||
${VertexShaderBody} |
|||
} |
|||
|
|||
void surf (Input IN, inout SurfaceOutput o) |
|||
{ |
|||
${PixelShaderBody} |
|||
} |
|||
ENDCG |
|||
} |
|||
FallBack "Diffuse" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d370877f47fbe644a45ccf5960f4c54 |
|||
DefaultImporter: |
|||
userData: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable][Title("Math/Add Node")] |
|||
public abstract class AbstractSurfaceMasterNode : AbstractMasterNode |
|||
{ |
|||
public const string AlbedoSlotName = "Albedo"; |
|||
public const string NormalSlotName = "Normal"; |
|||
public const string EmissionSlotName = "Emission"; |
|||
public const string SmoothnessSlotName = "Smoothness"; |
|||
public const string OcclusionSlotName = "Occlusion"; |
|||
public const string AlphaSlotName = "Alpha"; |
|||
|
|||
public const int AlbedoSlotId = 0; |
|||
public const int NormalSlotId = 1; |
|||
public const int EmissionSlotId = 3; |
|||
public const int SmoothnessSlotId = 4; |
|||
public const int OcclusionSlotId = 5; |
|||
public const int AlphaSlotId = 6; |
|||
|
|||
public override void GenerateNodeCode(ShaderGenerator shaderBody, GenerationMode generationMode) |
|||
{ |
|||
var firstPassSlotId = NormalSlotId; |
|||
// do the normal slot first so that it can be used later in the shader :)
|
|||
var firstPassSlot = FindInputSlot<MaterialSlot>(firstPassSlotId); |
|||
var nodes = ListPool<INode>.Get(); |
|||
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; |
|||
|
|||
//Get the rest of the nodes for all the other slots
|
|||
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, null, NodeUtils.IncludeSelf.Exclude); |
|||
for (var i = pass2StartIndex; i < nodes.Count; i++) |
|||
{ |
|||
var node = nodes[i]; |
|||
if (node is IGeneratesBodyCode) |
|||
(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, generationMode); |
|||
} |
|||
|
|||
ListPool<INode>.Release(nodes); |
|||
|
|||
foreach (var slot in GetInputSlots<MaterialSlot>()) |
|||
{ |
|||
foreach (var edge in owner.GetEdges(slot.slotReference)) |
|||
{ |
|||
var outputRef = edge.outputSlot; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|||
if (fromNode == null) |
|||
continue; |
|||
|
|||
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
[Title("Master/Metallic")] |
|||
public class MetallicMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string MetallicSlotName = "Metallic"; |
|||
public const int MetallicSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "Standard"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandard"; |
|||
|
|||
public MetallicMasterNode() |
|||
{ |
|||
name = "MetallicMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
MetallicSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override void GenerateSurfaceOutput(ShaderGenerator surfaceOutput) |
|||
{ |
|||
surfaceOutput.AddPragmaChunk(SurfaceOutputStructureName); |
|||
} |
|||
|
|||
public override void GenerateLightFunction(ShaderGenerator lightFunction) |
|||
{ |
|||
lightFunction.AddPragmaChunk(LightFunctionName); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
[Title("Master/Specular")] |
|||
public class SpecularMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string SpecularSlotName = "Specular"; |
|||
public const int SpecularSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "StandardSpecular"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandardSpecular"; |
|||
|
|||
public SpecularMasterNode() |
|||
{ |
|||
name = "SpecularMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
SpecularSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override void GenerateSurfaceOutput(ShaderGenerator surfaceOutput) |
|||
{ |
|||
surfaceOutput.AddPragmaChunk(SurfaceOutputStructureName); |
|||
} |
|||
|
|||
public override void GenerateLightFunction(ShaderGenerator lightFunction) |
|||
{ |
|||
lightFunction.AddPragmaChunk(LightFunctionName); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public abstract class AbstractMasterNode : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
protected override bool generateDefaultInputs { get { return false; } } |
|||
|
|||
public override IEnumerable<ISlot> GetInputsWithNoConnection() |
|||
{ |
|||
return new List<ISlot>(); |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public abstract void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode); |
|||
public abstract void GenerateSurfaceOutput (ShaderGenerator surfaceOutput); |
|||
public abstract void GenerateLightFunction(ShaderGenerator lightFunction); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue