浏览代码

Removed MaterialNodePresenter.

/main
damian 7 年前
当前提交
20646d1b
共有 13 个文件被更改,包括 60 次插入528 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs
  2. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphAnchorPresenter.cs
  4. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEdgePresenter.cs
  5. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  6. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  7. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  9. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  10. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs
  11. 254
      MaterialGraphProject/GeneratedShader.shader
  12. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta
  13. 148
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs


using System.IO;
using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEngine.MaterialGraph;

25
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs


using UnityEngine.MaterialGraph;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
namespace UnityEditor.MaterialGraph.Drawing
{

return;
var graphPresenter = graphEditorView.graphPresenter;
var selected = graphPresenter.elements.Where(e => e.selected);
var graphView = graphEditorView.graphView;
var selection = graphView.selection.OfType<GraphElement>();
var filtered = new List<GraphElementPresenter>();
var filtered = new List<GraphElement>();
foreach (var presenter in selected)
foreach (var element in selection)
var nodePresenter = presenter as MaterialNodePresenter;
if (nodePresenter != null)
var nodeView = element as MaterialNodeView;
if (nodeView != null)
if (!(nodePresenter.node is PropertyNode))
filtered.Add(nodePresenter);
if (!(nodeView.node is PropertyNode))
filtered.Add(nodeView);
filtered.Add(presenter);
filtered.Add(element);
}
}

edge => edge.outputSlot,
edge => edge,
(key, edges) => new {slotRef = key, edges = edges.ToList()});
var inputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
var inputNode = new PropertyNode();
var sr = group.slotRef;
var fromNode = graphPresenter.graph.GetNodeFromGuid(sr.nodeGuid);
var fromSlot = fromNode.FindOutputSlot<MaterialSlot>(sr.slotId);

graphPresenter.graph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
}
var toDelete = graphPresenter.elements.Where(e => e.selected).OfType<MaterialNodePresenter>();
graphPresenter.RemoveElements(toDelete, new List<GraphEdgePresenter>());
var toDelete = graphView.selection.OfType<MaterialNodeView>();
graphPresenter.RemoveElements(toDelete, new List<Edge>());
}
private void UpdateAbstractSubgraphOnDisk<T>(string path) where T : AbstractSubGraph

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphAnchorPresenter.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEdgePresenter.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<MaterialNodePresenter>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.OnModified(scope);
var theViews = m_GraphView.nodes.ToList().OfType<MaterialNodeView>();
var viewsFound = theViews.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in viewsFound)

{
change.node.onModified -= OnNodeChanged;
var nodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(p => p.node.guid == change.node.guid);
if (nodePresenter != null)
m_Elements.Remove(nodePresenter);
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node != null && p.node.guid == change.node.guid);
if (nodeView != null)
m_GraphView.RemoveElement(nodeView);

RecordState();
}
public void RemoveElements(IEnumerable<MaterialNodePresenter> nodes, IEnumerable<GraphEdgePresenter> edges)
{
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.edge));
graph.ValidateGraph();
}
public void RemoveElements(IEnumerable<MaterialNodeView> nodes, IEnumerable<Edge> edges)
{
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.userData as IEdge));

}
}
internal static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElementPresenter> selection)
internal static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElement> selection)
foreach (var presenter in selection)
foreach (var element in selection)
var nodePresenter = presenter as MaterialNodePresenter;
if (nodePresenter != null)
var nodeView = element as MaterialNodeView;
if (nodeView != null)
graph.AddNode(nodePresenter.node);
foreach (var edge in NodeUtils.GetAllEdges(nodePresenter.node))
graph.AddNode(nodeView.node);
foreach (var edge in NodeUtils.GetAllEdges(nodeView.userData as INode))
var edgePresenter = presenter as GraphEdgePresenter;
if (edgePresenter != null)
graph.AddEdge(edgePresenter.edge);
var edgeView = element as Edge;
if (edgeView != null)
graph.AddEdge(edgeView.userData as IEdge);
}
return graph;
}

public void Copy()
{
var graph = CreateCopyPasteGraph(elements.Where(e => e.selected));
var graph = CreateCopyPasteGraph(m_GraphView.selection.OfType<GraphElement>());
EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(graph, true);
}

{
Copy();
Undo.RecordObject(m_GraphObject, "Cut");
RemoveElements(elements.OfType<MaterialNodePresenter>().Where(e => e.selected), elements.OfType<GraphEdgePresenter>().Where(e => e.selected));
RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>(),
m_GraphView.selection.OfType<Edge>());
RecordState();
}

public void Duplicate()
{
var graph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(elements.Where(e => e.selected)), true));
var graph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(m_GraphView.selection.OfType<GraphElement>()), true));
Undo.RecordObject(m_GraphObject, "Duplicate");
InsertCopyPasteGraph(graph);
RecordState();

{
RecordState();
Undo.RecordObject(m_GraphObject, "Delete");
RemoveElements(elements.OfType<MaterialNodePresenter>().Where(e => e.selected), elements.OfType<GraphEdgePresenter>().Where(e => e.selected));
m_GraphView.selection.OfType<MaterialNodeView>().Where(e => e.selected && e.presenter == null),
m_GraphView.selection.OfType<Edge>().Where(e => e.selected));
m_GraphView.selection.OfType<MaterialNodeView>(),
m_GraphView.selection.OfType<Edge>());
RecordState();
}

}
public delegate void OnSelectionChanged(IEnumerable<INode> presenters);
public delegate void OnSelectionChanged(IEnumerable<INode> nodes);
public void UpdateSelection(IEnumerable<MaterialNodePresenter> presenters)
public void UpdateSelection(IEnumerable<MaterialNodeView> nodes)
onSelectionChanged(presenters.Select(x => x.node as INode));
onSelectionChanged(nodes.Select(x => x.userData as INode));
}
public override void AddElement(GraphElementPresenter element)

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs


}
}
[Serializable]
public class PropertyNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<PropertyControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
public class PropertyNodeView : MaterialNodeView
{
protected override IEnumerable<GraphControlPresenter> GetControlData()

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


}
else
{
List<PropertyCollector.TextureInfo> defaultTextures;
PreviewMode mode;
previewData.shaderString = m_Graph.GetPreviewShader(node, out mode);
previewData.previewMode = mode;

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


using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using MouseButton = UnityEngine.Experimental.UIElements.MouseButton;
namespace UnityEditor.MaterialGraph.Drawing

this.AddManipulator(new ClickSelector());
Insert(0, new GridBackground());
typeFactory[typeof(MaterialNodePresenter)] = typeof(MaterialNodeView);
typeFactory[typeof(GraphAnchorPresenter)] = typeof(NodeAnchor);
typeFactory[typeof(EdgePresenter)] = typeof(Edge);
AddStyleSheetPath("Styles/MaterialGraph");
}

if (graphPresenter == null)
return;
var selectedNodes = selection.OfType<MaterialNodeView>().Where(x => x.presenter != null).Select(x => (MaterialNodePresenter)x.presenter);
var selectedNodes = selection.OfType<MaterialNodeView>().Where(x => x.userData is INode);
graphPresenter.UpdateSelection(selectedNodes);
}

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


void OnPreviewToggle()
{
AbstractMaterialNode materialNode = node;
if (presenter != null)
materialNode = GetPresenter<MaterialNodePresenter>().node;
node.previewExpanded = !node.previewExpanded;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}

});
m_CurrentControls.Add(controlData);
}
}
void UpdateControls(MaterialNodePresenter nodeData)
{
if (nodeData.controls.SequenceEqual(m_CurrentControls) && nodeData.expanded)
return;
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
Dirty(ChangeType.Layout);
if (!nodeData.expanded)
return;
foreach (var controlData in nodeData.controls)
{
m_ControlsContainer.Add(new IMGUIContainer(controlData.OnGUIHandler)
{
name = "element"
});
m_CurrentControls.Add(controlData);
}
}
public override void SetPosition(Rect newPos)
{
var nodePresenter = GetPresenter<MaterialNodePresenter>();
if (nodePresenter != null)
nodePresenter.position = newPos;
base.SetPosition(newPos);
}
public override void OnDataChanged()
{
base.OnDataChanged();
var nodePresenter = GetPresenter<MaterialNodePresenter>();
if (nodePresenter == null)
{
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
UpdatePreviewTexture(null);
return;
}
m_PreviewToggle.text = nodePresenter.node.previewExpanded ? "▲" : "▼";
if (nodePresenter.node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
UpdateControls(nodePresenter);
UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
}
}
}

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEditor.Experimental.UIElements.GraphView;
#if WITH_PRESENTER
public class GraphTypeMapper : BaseTypeFactory<INode, ScriptableObject>
{
public GraphTypeMapper(Type fallbackType) : base(fallbackType)
{
}
protected override ScriptableObject InternalCreate(Type valueType)
{
return ScriptableObject.CreateInstance(valueType);
}
}
#else
public class GraphTypeMapper : BaseTypeFactory<INode, GraphElement>
{
public GraphTypeMapper(Type fallbackType) : base(fallbackType)

return (GraphElement) Activator.CreateInstance(valueType);
}
}
#endif
}

254
MaterialGraphProject/GeneratedShader.shader


Shader "3af7e7b7-0e1c-4b85-9b74-f027f0cdccb4_preview"
Shader "hidden/preview/Multiply_C3CB7BE2"
{
Properties
{

float3 P = abs(frac(hsv.xxx + K.xyz) * 6.0 - K.www);
rgb = hsv.z * lerp(K.xxx, saturate(P - K.xxx), hsv.y);
}
void Unity_Subtract_float(float first, float second, out float result)
{
result = first - second;
}
void Unity_OneMinus_float(float argument, out float result)
{
result = argument * -1 + 1;;
}
void Unity_Multiply_float(float3 first, float3 second, out float3 result)
{
result = first * second;
}
void Unity_Add_float(float3 first, float3 second, out float3 result)
{
result = first + second;
}
struct GraphVertexInput
{
float4 vertex : POSITION;

half4 uv0;
};
struct SurfaceDescription{
float3 Albedo;
float3 Normal;
float3 Emission;
float Metallic;
float Smoothness;
float Occlusion;
float Alpha;
float Multiply_C3CB7BE2_result;
};
UNITY_DECLARE_TEX2D(Texture_FD0EDC2E);
float Combine_76C873_G;

float Subtract_4053AE6C_first;
float Combine_EBDC57C5_G;
float Combine_EBDC57C5_B;
float Combine_EBDC57C5_A;
float4 Multiply_F77E48F9_second;
float4 Multiply_156218A9_second;
float4 LightweightMetallicMasterNode_53B6BCE4_Normal;
float4 LightweightMetallicMasterNode_53B6BCE4_Emission;
float LightweightMetallicMasterNode_53B6BCE4_Metallic;
float LightweightMetallicMasterNode_53B6BCE4_Smoothness;
float LightweightMetallicMasterNode_53B6BCE4_Occlusion;
float LightweightMetallicMasterNode_53B6BCE4_Alpha;
float Multiply_C3CB7BE2_second;
GraphVertexInput PopulateVertexData(GraphVertexInput v){
return v;
}

float Split_81BA869A_G = HSVtoRGB_AE8D0A0E_rgb[1];
float Split_81BA869A_B = HSVtoRGB_AE8D0A0E_rgb[2];
float Split_81BA869A_A = 1.0;
float Subtract_4053AE6C_result;
Unity_Subtract_float(Subtract_4053AE6C_first, _Time.y, Subtract_4053AE6C_result);
float4 Combine_EBDC57C5_RGBA;
Unity_Combine_float(Subtract_4053AE6C_result, Combine_EBDC57C5_G, Combine_EBDC57C5_B, Combine_EBDC57C5_A, Combine_EBDC57C5_RGBA);
float3 HSVtoRGB_6DD0292E_rgb;
Unity_HSVToRGB_float((Combine_EBDC57C5_RGBA.xyz), HSVtoRGB_6DD0292E_rgb);
float OneMinus_F47415CA_result;
Unity_OneMinus_float(Multiply_841C266E_result, OneMinus_F47415CA_result);
float3 Multiply_E8E6BAEA_result;
Unity_Multiply_float((OneMinus_F47415CA_result.xxx), HSVtoRGB_6DD0292E_rgb, Multiply_E8E6BAEA_result);
float3 Multiply_F77E48F9_result;
Unity_Multiply_float(HSVtoRGB_AE8D0A0E_rgb, Multiply_F77E48F9_second, Multiply_F77E48F9_result);
float3 Multiply_156218A9_result;
Unity_Multiply_float(Multiply_E8E6BAEA_result, Multiply_156218A9_second, Multiply_156218A9_result);
float3 Add_A93EC3AF_result;
Unity_Add_float(Multiply_156218A9_result, Multiply_F77E48F9_result, Add_A93EC3AF_result);
float Multiply_C3CB7BE2_result;
Unity_Multiply_float(Multiply_841C266E_result, Multiply_C3CB7BE2_second, Multiply_C3CB7BE2_result);
surface.Albedo = Add_A93EC3AF_result;
surface.Normal = LightweightMetallicMasterNode_53B6BCE4_Normal;
surface.Emission = LightweightMetallicMasterNode_53B6BCE4_Emission;
surface.Metallic = LightweightMetallicMasterNode_53B6BCE4_Metallic;
surface.Smoothness = LightweightMetallicMasterNode_53B6BCE4_Smoothness;
surface.Occlusion = LightweightMetallicMasterNode_53B6BCE4_Occlusion;
surface.Alpha = LightweightMetallicMasterNode_53B6BCE4_Alpha;
surface.Multiply_C3CB7BE2_result = Multiply_C3CB7BE2_result;
Tags{"RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"}
LOD 200
Pass
{
Tags{"LightMode" = "LightweightForward"}
Tags
{
"RenderType"="Opaque"
"Queue"="Geometry"
}
Blend One Zero
Cull Back
ZTest LEqual
ZWrite On
CGPROGRAM
#pragma target 3.0
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT _SINGLE_SPOT_LIGHT _SINGLE_POINT_LIGHT
#pragma multi_compile _ LIGHTWEIGHT_LINEAR
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ _LIGHT_PROBES_ON
#pragma multi_compile _ _HARD_SHADOWS _SOFT_SHADOWS _HARD_SHADOWS_CASCADES _SOFT_SHADOWS_CASCADES
#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile_fog
#pragma multi_compile_instancing
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma fragment frag
#pragma glsl
#pragma debug
#define _GLOSSYREFLECTIONS_ON
#define _SPECULARHIGHLIGHTS_ON
#define _METALLIC_SETUP 1
#include "UnityCG.cginc"
#include "CGIncludes/LightweightPBR.cginc"
struct GraphVertexOutput
#pragma fragment frag
#include "UnityCG.cginc"
struct GraphVertexOutput
float4 lwCustom : TEXCOORD0;
float4 fogCoord : TEXCOORD1; // x: fogCoord, yzw: vertexColor
float3 objectSpaceNormal : NORMAL;
float4 objectSpaceTangent : TANGENT;
float3 objectSpaceViewDirection : TEXCOORD2;
float4 objectSpacePosition : TEXCOORD3;
half4 uv0 : TEXCOORD4;
UNITY_VERTEX_OUTPUT_STEREO
half4 uv0 : TEXCOORD;
{
v = PopulateVertexData(v);
UNITY_SETUP_INSTANCE_ID(v);
GraphVertexOutput o = (GraphVertexOutput)0;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
{
v = PopulateVertexData(v);
GraphVertexOutput o;
o.objectSpaceNormal = v.normal;
o.objectSpaceTangent = v.tangent;
o.objectSpaceViewDirection = ObjSpaceViewDir(v.vertex);
o.objectSpacePosition = v.vertex;
o.uv0 = v.texcoord0;
#ifdef LIGHTMAP_ON
o.lwCustom.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
float3 lwWNormal = normalize(UnityObjectToWorldNormal(v.normal));
float3 lwWorldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU
#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS)
half3 diffuse = half3(1.0, 1.0, 1.0);
// pixel lights shaded = min(pixelLights, perObjectLights)
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights)
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter)
{
int lightIndex = unity_4LightIndices0[lightIter];
LightInput lightInput;
INITIALIZE_LIGHT(lightInput, lightIndex);
half3 lightDirection;
half atten = ComputeLightAttenuationVertex(lightInput, lwWNormal, lwWorldPos, lightDirection);
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, lwWNormal, atten);
}
#endif
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON)
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(lwWNormal, 1)));
#endif
UNITY_TRANSFER_FOG(o, o.position);
return o;
}
fixed4 frag (GraphVertexOutput IN) : SV_Target
o.uv0 = v.texcoord0;
return o;
}
fixed4 frag (GraphVertexOutput IN) : SV_Target
float3 objectSpaceNormal = normalize(IN.objectSpaceNormal);
float4 objectSpaceTangent = IN.objectSpaceTangent;
float3 objectSpaceBiTangent = normalize(cross(normalize(IN.objectSpaceNormal), normalize(IN.objectSpaceTangent.xyz)) * IN.objectSpaceTangent.w);
float3 objectSpaceViewDirection = normalize(IN.objectSpaceViewDirection);
float4 objectSpacePosition = IN.objectSpacePosition;
float3 worldSpaceNormal = UnityObjectToWorldNormal(objectSpaceNormal);
float3 worldSpaceTangent = UnityObjectToWorldDir(objectSpaceTangent);
float3 worldSpaceBiTangent = UnityObjectToWorldDir(objectSpaceBiTangent);
float3 worldSpaceViewDirection = UnityObjectToWorldDir(objectSpaceViewDirection);
float3 worldSpacePosition = UnityObjectToWorldDir(objectSpacePosition);
float4 uv0 = IN.uv0;
SurfaceInputs surfaceInput = (SurfaceInputs)0;
surfaceInput.uv0 =uv0;
float4 uv0 = IN.uv0;
SurfaceInputs surfaceInput = (SurfaceInputs)0;;
surfaceInput.uv0 =uv0;
float3 Albedo = float3(0.5, 0.5, 0.5);
float3 Specular = float3(0, 0, 0);
float Metallic = 0;
float3 Normal = float3(0, 0, 1);
float3 Emission = 0;
float Smoothness = 0;
float Occlusion = 1;
float Alpha = 1;
Albedo = surf.Albedo;
Normal = surf.Normal;
Emission = surf.Emission;
Metallic = surf.Metallic;
Smoothness = surf.Smoothness;
Occlusion = surf.Occlusion;
Alpha = surf.Alpha;
#if defined(UNITY_COLORSPACE_GAMMA)
Albedo = Albedo * Albedo;
Emission = Emission * Emission;
#endif
return FragmentLightingPBR(
IN.lwCustom,
worldSpacePosition,
worldSpaceNormal,
worldSpaceTangent,
worldSpaceBiTangent,
worldSpaceViewDirection,
IN.fogCoord,
Albedo,
Metallic,
Specular,
Smoothness,
Normal,
Occlusion,
Emission,
Alpha);
return half4(surf.Multiply_C3CB7BE2_result, surf.Multiply_C3CB7BE2_result, surf.Multiply_C3CB7BE2_result, 1.0);
ENDCG
}
Pass
{
Tags{"Lightmode" = "ShadowCaster"}
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 2.0
#include "UnityCG.cginc"
#include "CGIncludes/LightweightPass.cginc"
#pragma vertex shadowVert
#pragma fragment shadowFrag
ENDCG
}
Pass
{
Tags{"Lightmode" = "DepthOnly"}
ZWrite On
CGPROGRAM
#pragma target 2.0
#include "UnityCG.cginc"
#include "CGIncludes/LightweightPass.cginc"
#pragma vertex depthVert
#pragma fragment depthFrag
ENDCG
}
ENDCG
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta


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

148
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialNodePresenter : NodePresenter, IDisposable
{
public AbstractMaterialNode node { get; private set; }
[SerializeField]
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
[SerializeField]
int m_Version;
PreviewData m_Preview;
public Texture previewTexture { get; private set; }
public override bool expanded
{
get { return base.expanded; }
set
{
if (base.expanded != value)
{
base.expanded = value;
var ds = node.drawState;
ds.expanded = value;
node.drawState = ds;
}
}
}
public virtual void OnModified(ModificationScope scope)
{
m_Version++;
expanded = node.drawState.expanded;
if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();
inputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
outputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
AddSlots(slots.Except(inputAnchors.Concat(outputAnchors).Select(data => ((GraphAnchorPresenter)data).slot)));
inputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
outputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
}
}
public override void CommitChanges()
{
var drawState = node.drawState;
drawState.position = position;
node.drawState = drawState;
}
protected virtual IEnumerable<GraphControlPresenter> GetControlData()
{
return Enumerable.Empty<GraphControlPresenter>();
}
protected void AddSlots(IEnumerable<ISlot> slots)
{
foreach (var slot in slots)
{
if (slot.hidden)
continue;
var data = CreateInstance<GraphAnchorPresenter>();
data.capabilities &= ~Capabilities.Movable;
data.Initialize(slot);
if (slot.isOutputSlot)
{
outputAnchors.Add(data);
}
else
{
inputAnchors.Add(data);
}
}
}
protected MaterialNodePresenter()
{}
public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode as AbstractMaterialNode;
if (node == null)
return;
title = inNode.name;
expanded = node.drawState.expanded;
AddSlots(node.GetSlots<ISlot>());
var controlData = GetControlData();
controls.AddRange(controlData);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
m_Version = 0;
m_Preview = previewSystem.GetPreview(inNode);
m_Preview.onPreviewChanged += OnPreviewChanged;
node.onReplaced += OnReplaced;
}
void OnReplaced(INode previous, INode current)
{
node = current as AbstractMaterialNode;
}
void OnPreviewChanged()
{
previewTexture = m_Preview.texture;
m_Version++;
}
public void Dispose()
{
if (m_Preview != null)
{
m_Preview.onPreviewChanged -= OnPreviewChanged;
m_Preview = null;
}
}
}
}
正在加载...
取消
保存