浏览代码

No-presenters works: Fractal and Vector1 node creation and deletion.

/main
damian 7 年前
当前提交
73ca4594
共有 13 个文件被更改,包括 423 次插入29 次删除
  1. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Vector1NodePresenter.cs
  3. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
  4. 57
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  6. 167
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  7. 2
      MaterialGraphProject/Assets/fresnelstuff.ShaderSubGraph.meta
  8. 13
      MaterialGraphProject/ProjectSettings/DynamicsManager.asset
  9. 16
      MaterialGraphProject/ProjectSettings/Physics2DSettings.asset
  10. 39
      MaterialGraphProject/ProjectSettings/ProjectSettings.asset
  11. 1
      MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
  12. 9
      MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta
  13. 84
      MaterialGraphProject/GeneratedShader.shader

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


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

[Serializable]
public class MaterialGraphPresenter : GraphViewPresenter
{
private GraphView m_GraphView;
GraphTypeMapper typeMapper { get; set; }
PreviewSystem m_PreviewSystem;

// if (scope == ModificationScope.Topological)
}
public virtual void Initialize(IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
public virtual void Initialize(GraphView graphView, IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
m_GraphView = graphView;
m_PreviewSystem = previewSystem;
this.graph = graph;
m_Container = container;

void NodeAdded(NodeAddedGraphChange change)
{
if (change.node is Vector1Node)
{
var nodeView = new Vector1NodeView();
change.node.onModified += OnNodeChanged;
nodeView.Initialize(change.node, m_PreviewSystem);
m_GraphView.AddElement(nodeView);
return;
}
if (change.node is FractalNode)
{
var nodeView = new MaterialNodeView();
change.node.onModified += OnNodeChanged;
nodeView.Initialize(change.node, m_PreviewSystem);
m_GraphView.AddElement(nodeView);
return;
}
var nodePresenter = (MaterialNodePresenter)typeMapper.Create(change.node);
change.node.onModified += OnNodeChanged;
nodePresenter.Initialize(change.node, m_PreviewSystem);

void NodeRemoved(NodeRemovedGraphChange change)
{
change.node.onModified -= OnNodeChanged;
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node.guid == change.node.guid);
if (nodeView != null)
m_GraphView.RemoveElement(nodeView);
}
void EdgeAdded(EdgeAddedGraphChange change)

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));
graph.ValidateGraph();
}
public void Connect(GraphAnchorPresenter left, GraphAnchorPresenter right)
{
if (left != null && right != null)

public bool canCopy
{
get { return elements.Any(e => e.selected); }
get { return elements.Any(e => e.selected) || (m_GraphView != null && m_GraphView.selection.OfType<GraphElement>().Any(e => e.selected)); }
}
public void Copy()

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

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Vector1NodePresenter.cs


return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
public class Vector1NodeView : PropertyNodeView
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = ScriptableObject.CreateInstance<Vector1ControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

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


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

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


using System;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEditor.MaterialGraph.Drawing.Inspector;

m_GraphInspectorPresenter = ScriptableObject.CreateInstance<GraphInspectorPresenter>();
m_GraphInspectorPresenter.Initialize(assetName, previewSystem, container);
m_GraphPresenter = ScriptableObject.CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter.Initialize(graph, container, previewSystem);
m_GraphPresenter.onSelectionChanged += m_GraphInspectorPresenter.UpdateSelection;
m_ToolbarView = new ToolbarView { name = "TitleBar" };
{
m_ToolbarView.Add(new ToolbarSpaceView());

}
Add(m_ToolbarView);
m_GraphPresenter = ScriptableObject.CreateInstance<MaterialGraphPresenter>();
var content = new VisualElement();
content.name = "content";
{

content.Add(m_GraphInspectorView);
m_GraphView.graphViewChanged = GraphViewChanged;
m_GraphPresenter.Initialize(m_GraphView, graph, container, previewSystem);
m_GraphPresenter.onSelectionChanged += m_GraphInspectorPresenter.UpdateSelection;
}
private GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
{
/*
if (graphViewChange.elementsToRemove != null)
{
graphViewChange.elementsToRemove.To
foreach (GraphElement element in graphViewChange.elementsToRemove)
{
if (element is Node)
{
m_GraphPresenter.RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>().Where(e => e.selected && e.presenter == null),
m_GraphView.selection.OfType<Edge>().Where(e => e.selected));
}
else if (element is Edge)
{
EdgeDisconnected(element as Edge);
}
}
}
if (graphViewChange.edgesToCreate != null)
{
foreach (Edge edge in graphViewChange.edgesToCreate)
{
EdgeConnected(edge);
}
}
if (graphViewChange.movedElements != null)
{
foreach (GraphElement element in graphViewChange.movedElements)
{
MathNode mathNode = element.userData as MathNode;
if (mathNode == null)
continue;
mathNode.m_Position = element.layout.position;
}
}
*/
return graphViewChange;
}
public void Dispose()

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


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

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


using UnityEngine.MaterialGraph;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
public AbstractMaterialNode node { get; private set; }
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
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));
}
*/
}
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 = InstantiateNodeAnchor(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, typeof(Vector4));
data.capabilities &= ~Capabilities.Movable;
data.anchorName = slot.displayName;
if (slot.isOutputSlot)
{
outputContainer.Add(data);
}
else
{
inputContainer.Add(data);
}
}
}
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);
SetPosition(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;
// From OnDataChange()
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
if (node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
UpdateControls();
UpdatePreviewTexture(node.previewExpanded ? previewTexture : null);
}
void OnReplaced(INode previous, INode current)
{
node = current as AbstractMaterialNode;
}
void OnPreviewChanged()
{
previewTexture = m_Preview.texture;
UpdatePreviewTexture(node.previewExpanded ? previewTexture : null);
m_Version++;
}
public void Dispose()
{
if (m_Preview != null)
{
m_Preview.onPreviewChanged -= OnPreviewChanged;
m_Preview = null;
}
}
////////////////////////////////////////////////////////////////////////////////////
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
VisualElement m_PreviewToggle;

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

if (previewTexture == null)
if (previewTexture == null)
{
m_PreviewImage.visible = false;
m_PreviewImage.RemoveFromClassList("visible");

}
Dirty(ChangeType.Repaint);
}
void UpdateControls()
{
if (controls.SequenceEqual(m_CurrentControls) && expanded)
return;
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
Dirty(ChangeType.Layout);
if (!expanded)
return;
foreach (var controlData in controls)
{
m_ControlsContainer.Add(new IMGUIContainer(controlData.OnGUIHandler)
{
name = "element"
});
m_CurrentControls.Add(controlData);
}
}
void UpdateControls(MaterialNodePresenter nodeData)

2
MaterialGraphProject/Assets/fresnelstuff.ShaderSubGraph.meta


fileFormatVersion: 2
guid: 605d9bda370241843a5ab9cd42b7aeed
timeCreated: 1504017790
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:

13
MaterialGraphProject/ProjectSettings/DynamicsManager.asset


--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
serializedVersion: 3
serializedVersion: 7
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2

m_QueriesHitBackfaces: 0
m_QueriesHitTriggers: 1
m_EnableAdaptiveForce: 0
m_EnablePCM: 1
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_ClothInterCollisionSettingsToggle: 0
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_WorldBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 250, y: 250, z: 250}
m_WorldSubdivisions: 8

16
MaterialGraphProject/ProjectSettings/Physics2DSettings.asset


--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
serializedVersion: 3
m_Gravity: {x: 0, y: -9.81}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8

m_MaxAngularCorrection: 8
m_MaxTranslationSpeed: 100
m_MaxRotationSpeed: 360
m_MinPenetrationForPenalty: 0.01
m_DefaultContactOffset: 0.01
m_AutoSimulation: 1
m_CallbacksOnDisable: 1
m_AutoSyncTransforms: 1
m_AlwaysShowColliders: 0
m_ShowColliderSleep: 1
m_ShowColliderContacts: 0
m_ShowColliderAABB: 0
m_ContactArrowScale: 0.2
m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

39
MaterialGraphProject/ProjectSettings/ProjectSettings.asset


--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
serializedVersion: 14
productGUID: 918d4c17ff3414942ad7fbe59f853890
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0

allowedAutorotateToLandscapeLeft: 1
useOSAutorotation: 1
use32BitDisplayBuffer: 1
preserveFramebufferAlpha: 0
disableDepthAndStencilBuffers: 0
androidBlitType: 0
defaultIsFullScreen: 1

visibleInBackground: 1
allowFullscreenSwitch: 1
graphicsJobMode: 0
macFullscreenMode: 2
d3d9FullscreenMode: 1
d3d11FullscreenMode: 1
fullscreenMode: -1
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0

n3dsEnableSharedListOpt: 1
n3dsEnableVSync: 0
ignoreAlphaClear: 0
xboxOneResolution: 0
xboxOneMonoLoggingLevel: 0
xboxOneLoggingLevel: 1

useSustainedPerformanceMode: 0
enableVideoLayer: 0
useProtectedVideoMemory: 0
minimumSupportedHeadTracking: 0
maximumSupportedHeadTracking: 1
targetPixelDensity: 0
targetPixelDensity: 30
resolutionScalingMode: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1

iPadLandscapeSplashScreen: {fileID: 0}
iPadHighResLandscapeSplashScreen: {fileID: 0}
appleTVSplashScreen: {fileID: 0}
appleTVSplashScreen2x: {fileID: 0}
tvOSSmallIconLayers2x: []
tvOSLargeIconLayers2x: []
tvOSTopShelfImageLayers2x: []
tvOSTopShelfImageWideLayers2x: []
iOSLaunchScreenType: 0
iOSLaunchScreenPortrait: {fileID: 0}
iOSLaunchScreenLandscape: {fileID: 0}

iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
appleEnableAutomaticSigning: 0
iOSRequireARKit: 0
clonedFromGUID: 00000000000000000000000000000000
AndroidTargetDevice: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}

AndroidIsGame: 1
AndroidEnableTango: 0
AndroidTangoUsesCamera: 1
androidEnableBanner: 1
androidUseLowAccuracyLocation: 0
m_AndroidBanners:

Android: 1
iPhone: 1
tvOS: 1
m_BuildTargetGroupLightmapEncodingQuality:
- m_BuildTarget: Standalone
m_EncodingQuality: 1
- m_BuildTarget: XboxOne
m_EncodingQuality: 1
- m_BuildTarget: PS4
m_EncodingQuality: 1
wiiUTitleID: 0005000011000000
wiiUGroupID: 00010000
wiiUCommonSaveSize: 4096

ps4PronunciationSIGPath:
ps4BackgroundImagePath:
ps4StartupImagePath:
ps4StartupImagesFolder:
ps4IconImagesFolder:
ps4SaveDataImagePath:
ps4SdkOverride:
ps4BGMPath:

ps4pnFriends: 1
ps4pnGameCustomData: 1
playerPrefsSupport: 0
enableApplicationExit: 0
restrictedAudioUsageRights: 0
ps4UseResolutionFallback: 0
ps4ReprojectionSupport: 0

webGLUseEmbeddedResources: 0
webGLUseWasm: 0
webGLCompressionFormat: 1
scriptingDefineSymbols: {}
scriptingDefineSymbols:
1: UNITY_POST_PROCESSING_STACK_V2
platformArchitecture: {}
scriptingBackend: {}
incrementalIl2cppBuild: {}

n3dsTitle: GameName
n3dsProductCode:
n3dsApplicationId: 0xFF3FF
stvDeviceAddress:
stvProductDescription:
stvProductAuthor:
stvProductAuthorEmail:
stvProductLink:
stvProductCategory: 0
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:

1
MaterialGraphProject/Assets/New Shader Graph.ShaderGraph


{"m_SerializableNodes":[],"m_SerializableEdges":[],"m_SerializedProperties":[]}

9
MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta


fileFormatVersion: 2
guid: bc622a74b3c2c0d4db4c564bf551b9b5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

84
MaterialGraphProject/GeneratedShader.shader


Shader "hidden/preview/Fractal_DDEE6FBB"
{
Properties
{
}
CGINCLUDE
#include "UnityCG.cginc"
void Unity_Fractal_float(float2 uv, float2 pan, float zoom, float aspect, out float result)
{
const int Iterations = 128;
float2 c = (uv - 0.5) * zoom * float2(1, aspect) - pan;
float2 v = 0;
for (int n = 0; n < Iterations && dot(v,v) < 4; n++)
{
v = float2(v.x * v.x - v.y * v.y, v.x * v.y * 2) + c;
}
result = (dot(v, v) > 4) ? (float)n / (float)Iterations : 0;
}
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct SurfaceInputs{
half4 uv0;
};
struct SurfaceDescription{
float Fractal_DDEE6FBB_result;
};
float4 Fractal_DDEE6FBB_uv;
float4 Fractal_DDEE6FBB_pan;
float Fractal_DDEE6FBB_zoom;
float Fractal_DDEE6FBB_aspect;
GraphVertexInput PopulateVertexData(GraphVertexInput v){
return v;
}
SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {
half4 uv0 = IN.uv0;
float Fractal_DDEE6FBB_result;
Unity_Fractal_float(uv0, Fractal_DDEE6FBB_pan, Fractal_DDEE6FBB_zoom, Fractal_DDEE6FBB_aspect, Fractal_DDEE6FBB_result);
SurfaceDescription surface = (SurfaceDescription)0;
surface.Fractal_DDEE6FBB_result = Fractal_DDEE6FBB_result;
return surface;
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct GraphVertexOutput
{
float4 position : POSITION;
half4 uv0 : TEXCOORD;
};
GraphVertexOutput vert (GraphVertexInput v)
{
v = PopulateVertexData(v);
GraphVertexOutput o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv0 = v.texcoord0;
return o;
}
fixed4 frag (GraphVertexOutput IN) : SV_Target
{
float4 uv0 = IN.uv0;
SurfaceInputs surfaceInput = (SurfaceInputs)0;;
surfaceInput.uv0 =uv0;
SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
return half4(surf.Fractal_DDEE6FBB_result, surf.Fractal_DDEE6FBB_result, surf.Fractal_DDEE6FBB_result, 1.0);
}
ENDCG
}
}
}
正在加载...
取消
保存