浏览代码

Merge branch 'master' into node-channel

/main
Matt Dean 7 年前
当前提交
dadccc50
共有 26 个文件被更改,包括 604 次插入477 次删除
  1. 1
      .gitignore
  2. 23
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/HeightToNormalNode.cs
  3. 268
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph
  4. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightMetallicMasterNode.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightSpecularMasterNode.cs
  7. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
  8. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs
  9. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  10. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  11. 185
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  12. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  13. 60
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  14. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PortInputView.cs
  15. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs
  16. 126
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  17. 2
      MaterialGraphProject/ProjectSettings/ProjectVersion.txt
  18. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask.meta
  19. 79
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs
  20. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta
  21. 37
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs
  22. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs.meta
  23. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs.meta
  24. 124
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs
  25. 20
      MaterialGraphProject/ProjectSettings/EditorSettings.asset

1
.gitignore


MaterialGraphProject/Assets/_MingWai/New Custom Texture.asset.meta
MaterialGraphProject/Packages/*
MaterialGraphProject/GeneratedShader.shader
MaterialGraphProject/UberShader.shader
!MaterialGraphProject/Packages/manifest.json

23
MaterialGraphProject/Assets/NewNodes/Editor/Keep/HeightToNormalNode.cs


namespace UnityEditor.ShaderGraph
{
[Title("Utility/Heightmap To Normalmap")]
public class HeightToNormalNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
public class HeightToNormalNode : AbstractMaterialNode, IGeneratesBodyCode
{
public const int TextureInput = 0;
public const int TexCoordInput = 1;

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Texture2DMaterialSlot(TextureInput, TextureInputName, TextureInputName, SlotType.Input));
AddSlot(new Vector2MaterialSlot(TexCoordInput, TexCoordInputName, TexCoordInputName, SlotType.Input, Vector2.zero));
AddSlot(new UVMaterialSlot(TexCoordInput, TexCoordInputName, TexCoordInputName, UVChannel.uv0));
AddSlot(new Vector1MaterialSlot(TexOffsetInput, TexOffsetInputName, TexOffsetInputName, SlotType.Input, 0.005f));
AddSlot(new Vector1MaterialSlot(StrengthInput, StrengthInputName, StrengthInputName, SlotType.Input, 8f));
AddSlot(new Vector3MaterialSlot(NormalOutput, NormalOutputName, NormalOutputName, SlotType.Output, Vector3.zero));

{
var textureInput = GetSlotValue(TextureInput, generationMode);
var texCoordInput = RequiresMeshUV(UVChannel.uv0)
? string.Format("{0}.xy", UVChannel.uv0.GetUVName())
: GetSlotValue(TexCoordInput, generationMode);
var texCoordInput = GetSlotValue(TexCoordInput, generationMode);
var texOffsetInput = GetSlotValue(TexOffsetInput, generationMode);
var strengthInput = GetSlotValue(StrengthInput, generationMode);
var normalOutput = GetVariableNameForSlot(NormalOutput);

public override bool hasPreview
{
get { return true; }
}
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(TexCoordInput);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}

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

27
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


if (isMaster)
{
foreach (var slot in slots)
{
if (slot.isInputSlot)
surfaceDescriptionStruct.AddShaderChunk(string.Format("{0} {1};", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), slot.shaderOutputName), false);
else
surfaceDescriptionStruct.AddShaderChunk(string.Format("{0} {1};", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), ((AbstractMaterialNode) slot.owner).GetVariableNameForSlot(slot.id)), false);
}
surfaceDescriptionStruct.AddShaderChunk(string.Format("{0} {1};", AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), AbstractMaterialNode.GetHLSLSafeName(slot.shaderOutputName)), false);
surfaceDescriptionStruct.Deindent();
surfaceDescriptionStruct.AddShaderChunk("};", false);

{
if (slot.isInputSlot)
surfaceDescriptionStruct.AddShaderChunk(string.Format("surface.{0} = scale * surface.{0};", slot.shaderOutputName), false);
else
surfaceDescriptionStruct.AddShaderChunk(string.Format("surface.{0} = scale * surface.{0};", ((AbstractMaterialNode) slot.owner).GetVariableNameForSlot(slot.id)), false);
}
surfaceDescriptionStruct.AddShaderChunk(string.Format("surface.{0} = scale * surface.{0};", AbstractMaterialNode.GetHLSLSafeName(slot.shaderOutputName)), false);
surfaceDescriptionStruct.Deindent();
surfaceDescriptionStruct.AddShaderChunk("};", false);

{
if (slot.isInputSlot)
surfaceDescriptionStruct.AddShaderChunk(string.Format("base.{0} = base.{0} + add.{0};", slot.shaderOutputName), false);
else
surfaceDescriptionStruct.AddShaderChunk(string.Format("base.{0} = base.{0} + add.{0};", ((AbstractMaterialNode) slot.owner).GetVariableNameForSlot(slot.id)), false);
}
surfaceDescriptionStruct.AddShaderChunk(string.Format("base.{0} = base.{0} + add.{0};", AbstractMaterialNode.GetHLSLSafeName(slot.shaderOutputName)), false);
}
else
{

{
var outputRef = foundEdges[0].outputSlot;
var fromNode = graph.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", AbstractMaterialNode.GetHLSLSafeName(input.shaderOutputName), fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, input.GetDefaultValue(mode)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", AbstractMaterialNode.GetHLSLSafeName(input.shaderOutputName), input.GetDefaultValue(mode)), true);
}
}
}

surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {0};", masterNode.GetVariableNameForSlot(slot.id)), true);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", AbstractMaterialNode.GetHLSLSafeName(slot.shaderOutputName), masterNode.GetVariableNameForSlot(slot.id)), true);
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightMetallicMasterNode.cs


public LightweightMetallicMasterNode()
{
name = "LightweightMetallicMasterNode";
name = "LW Metallic Master";
AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector4(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0,0,1), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightweightSpecularMasterNode.cs


public LightweightSpecularMasterNode()
{
name = "LightweightSpecularMasterNode";
name = "LW Specular Master";
AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector3(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0,0,1), ShaderStage.Fragment));
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));

18
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs


using System;
using System.Reflection;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;

if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
Add(new IMGUIContainer(OnGUIHandler));
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
var enumField = new EnumField((Enum) m_PropertyInfo.GetValue(m_Node, null));
enumField.OnValueChanged(OnValueChanged);
Add(enumField);
void OnGUIHandler()
void OnValueChanged(ChangeEvent<Enum> evt)
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
if (evt.newValue.Equals(value))
value = EditorGUILayout.EnumPopup(m_Label, value);
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, value, null);
}
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
}
}
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs


void AddField(int index, string subLabel)
{
Add(new Label(subLabel));
var label = new Label(subLabel);
Add(label);
var dragger = new FieldMouseDragger<double>(doubleField);
dragger.SetDragZone(label);
doubleField.RegisterCallback<MouseDownEvent>(Repaint);
doubleField.RegisterCallback<MouseMoveEvent>(Repaint);
doubleField.OnValueChanged(evt =>

SetValue(value);
m_UndoGroup = -1;
Dirty(ChangeType.Repaint);
});
doubleField.RegisterCallback<InputEvent>(evt =>
{

var value = GetValue();
value[index] = newValue;
SetValue(value);
Dirty(ChangeType.Repaint);
});
doubleField.RegisterCallback<KeyDownEvent>(evt =>
{

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


AbstractMaterialGraph m_Graph;
PreviewManager m_PreviewManager;
MasterNode m_MasterNode;
PreviewData m_PreviewHandle;
PreviewRenderData m_PreviewRenderHandle;
List<INode> m_SelectedNodes;

}
Add(bottomContainer);
masterNode = graph.GetNodes<MasterNode>().FirstOrDefault();
m_PreviewRenderHandle = previewManager.masterRenderData;
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged;
foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));

MasterNode masterNode
{
get { return m_MasterNode; }
set
{
if (value == m_MasterNode)
return;
if (m_MasterNode != null)
m_PreviewHandle.onPreviewChanged -= OnPreviewChanged;
m_PreviewHandle = null;
m_MasterNode = value;
if (m_MasterNode != null)
{
m_PreviewHandle = m_PreviewManager.GetPreview(m_MasterNode);
m_PreviewHandle.onPreviewChanged += OnPreviewChanged;
}
}
get { return m_PreviewRenderHandle.shaderData.node as MasterNode; }
}
void OnAddProperty()

void OnPreviewChanged()
{
m_PreviewTextureView.image = m_PreviewHandle.texture ?? Texture2D.blackTexture;
m_PreviewTextureView.image = m_PreviewRenderHandle.texture ?? Texture2D.blackTexture;
m_PreviewTextureView.Dirty(ChangeType.Repaint);
}

{
m_PreviewHandle.mesh = null;
m_PreviewRenderHandle.mesh = null;
m_PersistentMasterNodePreviewMesh.mesh = null;
}

{
m_PreviewHandle.mesh = changedMesh;
m_PreviewRenderHandle.mesh = changedMesh;
m_PersistentMasterNodePreviewMesh.mesh = changedMesh;
}

foreach (var layer in layerGraph.addedLayers)
m_LayerItems.Add(new ShaderLayerView(layerGraph, layer));
}
if (masterNode != null)
{
if (m_Graph.removedNodes.Contains(masterNode))
masterNode = null;
}
if (masterNode == null)
{
var addedMasterNode = m_Graph.addedNodes.OfType<MasterNode>().FirstOrDefault();
if (addedMasterNode != null)
masterNode = addedMasterNode;
}
if (m_PreviewHandle != null)
if (m_PreviewRenderHandle != null)
m_PreviewHandle.onPreviewChanged -= OnPreviewChanged;
m_PreviewHandle = null;
m_PreviewRenderHandle.onPreviewChanged -= OnPreviewChanged;
m_PreviewRenderHandle = null;
}
}
}

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


m_GraphEditorView.onConvertToSubgraphClick += ToSubGraph;
m_GraphEditorView.onShowInProjectClick += PingAsset;
this.GetRootVisualContainer().Add(graphEditorView);
this.GetRootVisualContainer().parent.clippingOptions = VisualElement.ClippingOptions.ClipContents;
}
}
}

graphEditorView = new GraphEditorView(materialGraph, asset.name) {persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GUIDToAssetPath(selectedGuid))};
}
graphEditorView.previewManager.HandleGraphChanges();
graphEditorView.previewManager.RenderPreviews();
graphEditorView.inspectorView.HandleGraphChanges();
graphObject.graph.ClearChanges();
}

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


public class PreviewManager : IDisposable
{
AbstractMaterialGraph m_Graph;
Dictionary<Guid, PreviewData> m_Previews = new Dictionary<Guid, PreviewData>();
Dictionary<Guid, PreviewRenderData> m_RenderDatas = new Dictionary<Guid, PreviewRenderData>();
Dictionary<Guid, PreviewShaderData> m_ShaderDatas = new Dictionary<Guid, PreviewShaderData>();
PreviewRenderData m_MasterRenderData;
HashSet<Guid> m_DirtyPreviews = new HashSet<Guid>();
HashSet<Guid> m_DirtyShaders = new HashSet<Guid>();
HashSet<Guid> m_TimeDependentPreviews = new HashSet<Guid>();

public PreviewRate previewRate { get; set; }
public PreviewRenderData masterRenderData
{
get { return m_MasterRenderData; }
}
public PreviewManager(AbstractMaterialGraph graph)
{
m_Graph = graph;

m_UberShader = ShaderUtil.CreateShaderAsset(k_EmptyShader);
m_UberShader.hideFlags = HideFlags.HideAndDontSave;
m_UberShaderIds = new Dictionary<Guid, int>();
m_MasterRenderData = new PreviewRenderData
{
renderTexture = new RenderTexture(400, 400, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }
};
public PreviewData GetPreview(INode node)
public PreviewRenderData GetPreview(INode node)
return m_Previews[node.guid];
return m_RenderDatas[node.guid];
var previewData = new PreviewData
PreviewShaderData shaderData;
if (!m_ShaderDatas.TryGetValue(node.guid, out shaderData))
{
shaderData = new PreviewShaderData
{
node = node
};
m_ShaderDatas[node.guid] = shaderData;
}
var previewData = new PreviewRenderData
node = node,
shaderData = shaderData,
if (m_Previews.ContainsKey(node.guid))
if (m_RenderDatas.ContainsKey(node.guid))
m_Previews.Add(node.guid, previewData);
m_RenderDatas.Add(node.guid, previewData);
var masterNode = node as IMasterNode;
if (masterRenderData.shaderData == null && masterNode != null)
{
masterRenderData.shaderData = shaderData;
}
m_Previews.Remove(node.guid);
m_RenderDatas.Remove(node.guid);
if (masterRenderData.shaderData != null && masterRenderData.shaderData.node == node)
masterRenderData.shaderData = m_ShaderDatas.Values.FirstOrDefault(x => x.node is IMasterNode);
}
void OnNodeModified(INode node, ModificationScope scope)

m_DirtyShaders.Add(edge.inputSlot.nodeGuid);
}
List<PreviewData> m_RenderList2D = new List<PreviewData>();
List<PreviewData> m_RenderList3D = new List<PreviewData>();
List<PreviewRenderData> m_RenderList2D = new List<PreviewRenderData>();
List<PreviewRenderData> m_RenderList3D = new List<PreviewRenderData>();
HashSet<Guid> m_NodesWith3DPreview = new HashSet<Guid>();
public void RenderPreviews()

foreach (var node in uberNodes)
{
PreviewData previewData;
if (!m_Previews.TryGetValue(node.guid, out previewData))
PreviewShaderData shaderData;
if (!m_ShaderDatas.TryGetValue(node.guid, out shaderData))
previewData.previewMode = m_NodesWith3DPreview.Contains(node.guid) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
previewData.shader = m_UberShader;
shaderData.previewMode = m_NodesWith3DPreview.Contains(node.guid) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
shaderData.shader = m_UberShader;
}
i++;
EditorUtility.DisplayProgressBar("Shader Graph", string.Format("Compiling preview shaders ({0}/{1})", i, count), 0f);

foreach (var nodeGuid in m_DirtyPreviews)
{
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
PreviewRenderData renderData;
if (!m_RenderDatas.TryGetValue(nodeGuid, out renderData))
if (previewData.shader == null)
if (renderData.shaderData.shader == null)
previewData.texture = null;
renderData.texture = null;
if (MaterialGraphAsset.ShaderHasError(previewData.shader))
if (MaterialGraphAsset.ShaderHasError(renderData.shaderData.shader))
previewData.texture = m_ErrorTexture;
renderData.texture = m_ErrorTexture;
if (previewData.previewMode == PreviewMode.Preview2D)
m_RenderList2D.Add(previewData);
if (renderData.shaderData.previewMode == PreviewMode.Preview2D)
m_RenderList2D.Add(renderData);
m_RenderList3D.Add(previewData);
m_RenderList3D.Add(renderData);
if (masterRenderData.shaderData != null && m_DirtyPreviews.Contains(masterRenderData.shaderData.node.guid))
m_RenderList3D.Add(masterRenderData);
var time = Time.realtimeSinceStartup;
EditorUtility.SetCameraAnimateMaterialsTime(m_SceneResources.camera, time);

m_SceneResources.camera.transform.rotation = Quaternion.identity;
m_SceneResources.camera.orthographicSize = 1;
m_SceneResources.camera.orthographic = true;
foreach (var previewData in m_RenderList2D)
foreach (var renderData in m_RenderList2D)
if (m_UberShaderIds.TryGetValue(previewData.node.guid, out outputId))
if (m_UberShaderIds.TryGetValue(renderData.shaderData.node.guid, out outputId))
m_PreviewMaterial.shader = previewData.shader;
m_SceneResources.camera.targetTexture = previewData.renderTexture;
m_PreviewMaterial.shader = renderData.shaderData.shader;
m_SceneResources.camera.targetTexture = renderData.renderTexture;
RenderTexture.active = previewData.renderTexture;
RenderTexture.active = renderData.renderTexture;
Graphics.Blit(Texture2D.whiteTexture, previewData.renderTexture, m_SceneResources.checkerboardMaterial);
Graphics.Blit(Texture2D.whiteTexture, renderData.renderTexture, m_SceneResources.checkerboardMaterial);
Graphics.DrawMesh(m_SceneResources.quad, Matrix4x4.identity, m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;
Unsupported.useScriptableRenderPipeline = false;

previewData.texture = previewData.renderTexture;
renderData.texture = renderData.renderTexture;
m_RenderList2D.Clear();
// Render 3D previews
m_SceneResources.camera.transform.position = -Vector3.forward * 5;

{
int outputId;
if (m_UberShaderIds.TryGetValue(previewData.node.guid, out outputId))
if (m_UberShaderIds.TryGetValue(previewData.shaderData.node.guid, out outputId))
m_PreviewMaterial.shader = previewData.shader;
m_PreviewMaterial.shader = previewData.shaderData.shader;
m_SceneResources.camera.targetTexture = previewData.renderTexture;
var previousRenderTexure = RenderTexture.active;
RenderTexture.active = previewData.renderTexture;

Graphics.DrawMesh(mesh, Matrix4x4.TRS(-mesh.bounds.center, Quaternion.identity, Vector3.one), m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;
Unsupported.useScriptableRenderPipeline = previewData.node is IMasterNode;
Unsupported.useScriptableRenderPipeline = previewData.shaderData.node is IMasterNode;
m_RenderList3D.Clear();
foreach (var nodeGuid in m_DirtyPreviews)
foreach (var previewRenderData in m_RenderList2D.Union(m_RenderList3D))
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
continue;
if (previewData.onPreviewChanged != null)
previewData.onPreviewChanged();
if (previewRenderData.onPreviewChanged != null)
previewRenderData.onPreviewChanged();
m_RenderList2D.Clear();
m_RenderList3D.Clear();
m_DirtyPreviews.Clear();
}

if (node == null)
return;
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
PreviewShaderData shaderData;
if (!m_ShaderDatas.TryGetValue(nodeGuid, out shaderData))
previewData.previewMode = m_NodesWith3DPreview.Contains(nodeGuid) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
shaderData.previewMode = m_NodesWith3DPreview.Contains(nodeGuid) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
previewData.shaderString = null;
shaderData.shaderString = null;
previewData.shaderString = m_Graph.GetPreviewShader(node, out mode);
shaderData.shaderString = m_Graph.GetPreviewShader(node, out mode);
File.WriteAllText(Application.dataPath + "/../GeneratedShader.shader", (previewData.shaderString ?? "null").Replace("UnityEngine.MaterialGraph", "Generated"));
File.WriteAllText(Application.dataPath + "/../GeneratedShader.shader", (shaderData.shaderString ?? "null").Replace("UnityEngine.MaterialGraph", "Generated"));
if (string.IsNullOrEmpty(previewData.shaderString))
if (string.IsNullOrEmpty(shaderData.shaderString))
if (previewData.shader != null)
Object.DestroyImmediate(previewData.shader, true);
previewData.shader = null;
if (shaderData.shader != null)
Object.DestroyImmediate(shaderData.shader, true);
shaderData.shader = null;
if (previewData.shader != null && MaterialGraphAsset.ShaderHasError(previewData.shader))
if (shaderData.shader != null && MaterialGraphAsset.ShaderHasError(shaderData.shader))
ShaderUtil.ClearShaderErrors(previewData.shader);
Object.DestroyImmediate(previewData.shader, true);
previewData.shader = null;
ShaderUtil.ClearShaderErrors(shaderData.shader);
Object.DestroyImmediate(shaderData.shader, true);
shaderData.shader = null;
if (previewData.shader == null)
if (shaderData.shader == null)
previewData.shader = ShaderUtil.CreateShaderAsset(previewData.shaderString);
previewData.shader.hideFlags = HideFlags.HideAndDontSave;
shaderData.shader = ShaderUtil.CreateShaderAsset(shaderData.shaderString);
shaderData.shader.hideFlags = HideFlags.HideAndDontSave;
ShaderUtil.ClearShaderErrors(previewData.shader);
ShaderUtil.UpdateShaderAsset(previewData.shader, previewData.shaderString);
ShaderUtil.ClearShaderErrors(shaderData.shader);
ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderData.shaderString);
var message = "RecreateShader: " + node.GetVariableNameForNode() + Environment.NewLine + previewData.shaderString;
if (MaterialGraphAsset.ShaderHasError(previewData.shader))
var message = "RecreateShader: " + node.GetVariableNameForNode() + Environment.NewLine + shaderData.shaderString;
if (MaterialGraphAsset.ShaderHasError(shaderData.shader))
void DestroyPreview(Guid nodeGuid, PreviewData previewData)
void DestroyPreview(Guid nodeGuid, PreviewRenderData previewRenderData)
if (m_Previews.Remove(nodeGuid))
if (m_RenderDatas.Remove(nodeGuid))
if (previewData.shader != null)
Object.DestroyImmediate(previewData.shader, true);
if (previewData.renderTexture != null)
Object.DestroyImmediate(previewData.renderTexture, true);
if (previewRenderData.shaderData.shader != null)
Object.DestroyImmediate(previewRenderData.shaderData.shader, true);
if (previewRenderData.renderTexture != null)
Object.DestroyImmediate(previewRenderData.renderTexture, true);
var node = m_Graph.GetNodeFromGuid(nodeGuid);
if (node != null)
node.onModified -= OnNodeModified;

previewData.shader = null;
previewData.renderTexture = null;
previewData.texture = null;
previewData.onPreviewChanged = null;
previewRenderData.shaderData.shader = null;
previewRenderData.renderTexture = null;
previewRenderData.texture = null;
previewRenderData.onPreviewChanged = null;
}
}

if (m_SceneResources != null)
m_SceneResources.Dispose();
m_SceneResources = null;
var previews = m_Previews.ToList();
var previews = m_RenderDatas.ToList();
foreach (var kvp in previews)
DestroyPreview(kvp.Key, kvp.Value);
}

public delegate void OnPreviewChanged();
public class PreviewData
public class PreviewShaderData
public Mesh mesh { get; set; }
}
public class PreviewRenderData
{
public PreviewShaderData shaderData { get; set; }
public Mesh mesh { get; set; }
public RenderTexture renderTexture { get; set; }
public Texture texture { get; set; }
public OnPreviewChanged onPreviewChanged;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


public void HandleGraphChanges()
{
previewManager.HandleGraphChanges();
previewManager.RenderPreviews();
inspectorView.HandleGraphChanges();
foreach (var node in m_Graph.removedNodes)
{
node.onModified -= OnNodeChanged;

60
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


public sealed class MaterialNodeView : Node
{
List<VisualElement> m_ControlViews;
PreviewData m_PreviewData;
PreviewRenderData m_PreviewRenderData;
VisualElement m_ControlsDivider;
public void Initialize(GraphView graphView, AbstractMaterialNode inNode, PreviewManager previewManager)
{

{
name = "controls"
};
leftContainer.Add(m_ControlsContainer);
extensionContainer.Add(m_ControlsContainer);
m_ControlsDivider = new VisualElement {name = "divider"};
m_ControlsDivider.AddToClassList("horizontal");
if (node.hasPreview)
{

pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
m_PreviewData = previewManager.GetPreview(inNode);
m_PreviewData.onPreviewChanged += UpdatePreviewTexture;
m_PreviewRenderData = previewManager.GetPreview(inNode);
m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
m_PreviewContainer.Add(m_PreviewTextureView);
var collapsePreviewButton = new Label { name = "collapse", text = "▲" };
var collapsePreviewButton = new VisualElement { name = "collapse"};
collapsePreviewButton.Add(new VisualElement { name = "icon" });
collapsePreviewButton.AddManipulator(new Clickable(() =>
{
node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview");

m_PreviewContainer.Add(collapsePreviewButton);
m_PreviewTextureView.Add(collapsePreviewButton);
var expandPreviewButton = new Label { name = "expand", text = "▼" };
var expandPreviewButton = new VisualElement { name = "expand"};
expandPreviewButton.Add(new VisualElement { name = "icon"});
expandPreviewButton.AddManipulator(new Clickable(() =>
{
node.owner.owner.RegisterCompleteObjectUndo("Expand Preview");

}
leftContainer.Add(m_PreviewContainer);
extensionContainer.Add(m_PreviewContainer);
}
m_ControlViews = new List<VisualElement>();

m_Attachers = new List<Attacher>(node.GetInputSlots<MaterialSlot>().Count());
expanded = node.drawState.expanded;
expanded = node.drawState.expanded;
RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here
UpdatePortInputVisibilities();
SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

var resizeHandle = new Label { name = "resize", text = "" };
resizeHandle.AddManipulator(new Draggable(OnResize));
Add(resizeHandle);
UpdateSize();
}
}

UpdateControls();
UpdatePortInputVisibilities();
RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here
}
}

return;
if (expanded)
{
if (m_PreviewTextureView.parent != m_PreviewContainer)
{
m_PreviewContainer.Add(m_PreviewTextureView);
}
if (m_PreviewTextureView.parent == m_PreviewContainer)
{
m_PreviewTextureView.RemoveFromHierarchy();
}
m_PreviewContainer.RemoveFromClassList("expanded");
m_PreviewContainer.AddToClassList("collapsed");
}

{
inputContainer.Add(port);
var portInputView = new PortInputView(slot);
m_GraphView.AddElement(portInputView);
m_Attachers.Add(new Attacher(portInputView, port, SpriteAlignment.LeftCenter) { distance = 0f });
Add(portInputView);
m_Attachers.Add(new Attacher(portInputView, port, SpriteAlignment.LeftCenter) { distance = -8f });
}
}
}

void OnResize(Vector2 deltaSize)
{
var updatedWidth = leftContainer.layout.width + deltaSize.x;
var updatedWidth = topContainer.layout.width + deltaSize.x;
var updatedHeight = m_PreviewTextureView.layout.height + deltaSize.y;
var previewNode = node as PreviewNode;

void UpdatePreviewTexture()
{
if (m_PreviewData.texture == null || !node.previewExpanded)
if (m_PreviewRenderData.texture == null || !node.previewExpanded || m_PreviewTextureView.panel == null)
{
m_PreviewTextureView.visible = false;
m_PreviewTextureView.image = Texture2D.blackTexture;

m_PreviewTextureView.visible = true;
m_PreviewTextureView.AddToClassList("visible");
m_PreviewTextureView.RemoveFromClassList("hidden");
m_PreviewTextureView.image = m_PreviewData.texture;
m_PreviewTextureView.image = m_PreviewRenderData.texture;
m_PreviewTextureView.Dirty(ChangeType.Repaint);
m_PreviewTextureView.Dirty(ChangeType.Repaint);
}
void UpdateControls()

m_ControlsContainer.Clear();
m_ControlsDivider.RemoveFromHierarchy();
}
else if (m_ControlsContainer.childCount != m_ControlViews.Count)
{

extensionContainer.Add(m_ControlsDivider);
if (m_PreviewContainer != null)
m_ControlsDivider.PlaceBehind(m_PreviewContainer);
}
}

var width = previewNode.width;
var height = previewNode.height;
leftContainer.style.width = width;
m_PreviewTextureView.style.height = height;
}

m_Attachers.Clear();
node = null;
if (m_PreviewData != null)
if (m_PreviewRenderData != null)
m_PreviewData.onPreviewChanged -= UpdatePreviewTexture;
m_PreviewData = null;
m_PreviewRenderData.onPreviewChanged -= UpdatePreviewTexture;
m_PreviewRenderData = null;
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PortInputView.cs


m_EdgeControl = new EdgeControl
{
@from = new Vector2(212f - 20f, 11.5f),
@from = new Vector2(212f - 21f, 11.5f),
edgeWidth = 2
edgeWidth = 2,
pickingMode = PickingMode.Ignore
clippingOptions = ClippingOptions.NoClipping;
m_Container.clippingOptions = ClippingOptions.ClipAndCacheContents;
}
protected override void OnStyleResolved(ICustomStyle styles)

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs


void AddField(Vector4 initialValue, int index, string subLabel)
{
Add(new Label(subLabel));
var label = new Label(subLabel);
Add(label);
var dragger = new FieldMouseDragger<double>(doubleField);
dragger.SetDragZone(label);
doubleField.OnValueChanged(evt =>
{
var value = m_Get();

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


background-color: rgb(20, 21, 21);
}
MaterialNodeView > .mainContainer > #left > #previewContainer {
width: 200;
MaterialNodeView #previewContainer,
MaterialNodeView #controls {
background-color: #393939;
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #preview.active,
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #preview.visible {
MaterialNodeView #previewContainer > #preview {
align-items:center;
MaterialNodeView > .mainContainer > #left > #previewContainer.collapsed > #collapse {
MaterialNodeView #previewContainer > #preview > #collapse {
background-color: #000;
border-color: #F0F0F0;
width: 0;
}
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #collapse {
border-radius: 2;
text-alignment: middle-center;
position-left: 87;
position-right: 87;
position-top: 5;
position-type: absolute;
height: 0;
border-top-width: 0;
border-bottom-width: 0;
border-left-width: 0;
border-right-width: 0;
}
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded:hover > #collapse {
background-color: rgba(0, 0, 0, 0.5);
text-color: rgba(255, 255, 255, 0.75);
border-color: rgba(255, 255, 255, 0.75);
opacity: 0;
border-radius: 1;
height: 26;
margin-top: 4;
align-items:center;
justify-content:center;
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #collapse:hover {
background-color: rgba(0, 0, 0, 0.75);
text-color: rgba(255, 255, 255, 1);
border-color: rgba(255, 255, 255, 1);
MaterialNodeView #previewContainer:hover > #preview > #collapse {
width: 20;
height: 20;
opacity: 0.6;
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #collapse:active {
background-color: rgba(0, 0, 0, 0.66);
MaterialNodeView #previewContainer > #preview > #collapse > #icon
{
background-image : resource("GraphView/Nodes/PreviewCollapse.png");
width: 16;
height: 16;
}
MaterialNodeView #previewContainer > #preview > #collapse:hover {
opacity: 1.0;
MaterialNodeView > .mainContainer > #left > #previewContainer.expanded > #expand {
MaterialNodeView #previewContainer.collapsed > #preview > #collapse {
MaterialNodeView > .mainContainer > #left > #previewContainer.collapsed > #expand {
text-alignment: middle-center;
text-color: rgb(153, 153, 153);
MaterialNodeView #previewContainer > #expand {
width: 50;
width: 56;
height: 16;
flex-direction: row;
justify-content:center;
}
MaterialNodeView #previewContainer > #expand > #icon {
align-self: center;
background-image : resource("GraphView/Nodes/PreviewExpand.png");
width: 16;
height: 16;
MaterialNodeView > .mainContainer > #left > #previewContainer.collapsed > #expand:hover {
background-color: rgba(0, 0, 0, 0.5);
text-color: rgba(255, 255, 255, 1);
MaterialNodeView #previewContainer.collapsed > #expand:hover {
background-color: #2B2B2B;
}
MaterialNodeView #previewContainer.expanded > #expand {
height: 0;
}
MaterialNodeView > #resize {

flex-direction: row;
align-items: center;
padding-left: 8;
margin-right: 10;
margin-right: 12;
border-left-width: 1;
border-top-width: 1;
border-right-width: 1;

MultiFloatSlotControlView > Label {
margin-left: 0;
margin-right: 0;
cursor: slide-arrow;
}
MultiFloatSlotControlView > DoubleField {

MultiFloatControlView {
flex-direction: row;
padding-left: 8;
padding-right: 8;
padding-top: 8;
padding-bottom: 8;
cursor: slide-arrow;
flex: 1;
min-width: 30;
flex-grow: 1;
}
ObjectControlView {

ObjectControlView > ObjectField {
flex: 1;
}
EnumControlView {
flex-direction: row;
}
EnumControlView > EnumField {
flex: 1;
margin-left: 0;
margin-right: 8;
margin-top: 8;
margin-bottom: 8;
}
EnumControlView > Label {
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
margin-left: 8;
margin-right: 8;
margin-top: 8;
margin-bottom: 8;
}
PropertyControlView {
padding-left: 8;
padding-right: 8;
padding-top: 8;
padding-bottom: 8;
}

2
MaterialGraphProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.1.0a6
m_EditorVersion: 2018.1.0a7

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask.meta


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

79
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class ChannelEnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
int m_SlotId;
public ChannelEnumControlAttribute(string label = null, int slotId = 0)
{
m_Label = label;
m_SlotId = slotId;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new ChannelEnumControlView(m_Label, m_SlotId, node, propertyInfo);
}
}
public class ChannelEnumControlView : VisualElement, INodeModificationListener
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
IMGUIContainer m_Container;
int m_SlotId;
public ChannelEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
m_SlotId = slotId;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
m_Container = new IMGUIContainer(OnGUIHandler);
Add(m_Container);
}
void OnGUIHandler()
{
UpdatePopup();
}
public void OnNodeModified(ModificationScope scope)
{
if (scope == ModificationScope.Graph)
m_Container.Dirty(ChangeType.Repaint);
}
private void UpdatePopup()
{
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
int channelCount = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType);
var enumEntryCount = (Enum)m_PropertyInfo.GetValue(m_Node, null);
string[] enumEntryNames = Enum.GetNames(enumEntryCount.GetType());
string[] popupEntries = new string[channelCount];
for (int i = 0; i < popupEntries.Length; i++)
popupEntries[i] = enumEntryNames[i];
value = EditorGUILayout.Popup(m_Label, value, popupEntries);
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta


fileFormatVersion: 2
guid: 74fdde12d8253bd4c874acc555be0585
timeCreated: 1507817885

37
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs


using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic/Mask/Color Mask")]
public class ColorMaskNode : CodeFunctionNode
{
public ColorMaskNode()
{
name = "Color Mask";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ColorMask", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ColorMask(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Color MaskColor,
[Slot(2, Binding.None)] Vector1 Range,
[Slot(3, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
{precision}3 col = {precision}3(0, 0, 0);
{precision} Distance = distance(MaskColor, In);
if(Distance <= Range)
col = {precision}3(1, 1, 1);
Out = col;
}";
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs.meta


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

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs.meta


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

124
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
public enum TextureChannel
{
Red,
Green,
Blue,
Alpha
}
[Title("Artistic/Mask/Channel Mask")]
public class ChannelMaskNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
public ChannelMaskNode()
{
name = "Channel Mask";
UpdateNodeAfterDeserialization();
}
const int InputSlotId = 0;
const int OutputSlotId = 1;
const string kInputSlotName = "In";
const string kOutputSlotName = "Out";
public override bool hasPreview
{
get { return true; }
}
string GetFunctionName()
{
return string.Format("Unity_ChannelMask_{0}_{1}", channel, precision);
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero));
AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
}
[SerializeField]
private TextureChannel m_Channel = TextureChannel.Red;
[ChannelEnumControl("Channel")]
public TextureChannel channel
{
get { return m_Channel; }
set
{
if (m_Channel == value)
return;
m_Channel = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
void ValidateChannelCount()
{
int channelCount = (int)SlotValueHelper.GetChannelCount(FindSlot<MaterialSlot>(InputSlotId).concreteValueType);
if ((int)channel >= channelCount)
channel = TextureChannel.Red;
}
string GetFunctionPrototype(string argIn, string argOut)
{
return string.Format("void {0} ({1} {2}, out {3} {4})", GetFunctionName(),
ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<DynamicVectorMaterialSlot>(InputSlotId).concreteValueType), argIn,
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<DynamicVectorMaterialSlot>(OutputSlotId).concreteValueType), argOut);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
ValidateChannelCount();
string inputValue = GetSlotValue(InputSlotId, generationMode);
string outputValue = GetSlotValue(OutputSlotId, generationMode);
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true);
visitor.AddShaderChunk(GetFunctionCallBody(inputValue, outputValue), true);
}
string GetFunctionCallBody(string inputValue, string outputValue)
{
return GetFunctionName() + " (" + inputValue + ", " + outputValue + ");";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
ValidateChannelCount();
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("In", "Out"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
switch(channel)
{
case TextureChannel.Green:
outputString.AddShaderChunk("Out = In.yyyy;", false);
break;
case TextureChannel.Blue:
outputString.AddShaderChunk("Out = In.zzzz;", false);
break;
case TextureChannel.Alpha:
outputString.AddShaderChunk("Out = In.wwww;", false);
break;
default:
outputString.AddShaderChunk("Out = In.xxxx;", false);
break;
}
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

20
MaterialGraphProject/ProjectSettings/EditorSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!159 &1
EditorSettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_ExternalVersionControlSupport: Visible Meta Files
m_SerializationMode: 2
m_DefaultBehaviorMode: 0
m_SpritePackerMode: 2
m_SpritePackerPaddingPower: 1
m_EtcTextureCompressorBehavior: 0
m_EtcTextureFastCompressor: 0
m_EtcTextureNormalCompressor: 2
m_EtcTextureBestCompressor: 5
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;uss
m_ProjectGenerationRootNamespace:
m_UserGeneratedProjectSuffix:
m_CollabEditorSettings:
inProgressEnabled: 1
正在加载...
取消
保存