浏览代码

Merge remote-tracking branch 'origin/master'

/main
Tim Cooper 7 年前
当前提交
ccf49055
共有 10 个文件被更改,包括 147 次插入309 次删除
  1. 2
      .gitignore
  2. 10
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs
  3. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  4. 273
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  5. 2
      MaterialGraphProject/ProjectSettings/QualitySettings.asset
  6. 27
      MaterialGraphProject/Assets/graphs_PartyPreview.mat
  7. 8
      MaterialGraphProject/Assets/graphs_PartyPreview.mat.meta
  8. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphControlPresenter.cs
  9. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphControlPresenter.cs.meta
  10. 84
      MaterialGraphProject/GeneratedShader.shader

2
.gitignore


MaterialGraphProject/Library
MaterialGraphProject/obj
MaterialGraphProject/MaterialGraphProject.CSharp.csproj
MaterialGraphProject/MaterialGraphProject.sln.DotSettings.user
*.csproj
MaterialGraphProject/MaterialGraphProject.sln
MaterialGraphProject/Temp

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

10
MaterialGraphProject/Assets/NewNodes/Editor/Keep/GradientNode.cs


[Title("Input/Gradient")]
public class GradientNode : AbstractMaterialNode, IGeneratesBodyCode
{
Gradient m_Gradient;
Gradient m_Gradient = new Gradient();
[SerializeField]
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), };

AddSlot(new Vector1MaterialSlot(BOutputSlotId, k_BOutputSlotName, k_BOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(AOutputSlotId, k_AOutputSlotName, k_AOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { TimeInputSlotId, RGBAOutputSlotId, ROutputSlotId, GOutputSlotId, BOutputSlotId, AOutputSlotId });
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_SerializableAlphaKeys = null;
m_SerializableColorKeys = null;
m_Gradient.SetKeys(colorKeys, alphaKeys);
}

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


void NodeAdded(NodeAddedGraphChange change)
{
var nodeView = new MaterialNodeView();
var nodeView = new MaterialNodeView(change.node as AbstractMaterialNode, m_PreviewSystem);
nodeView.userData = change.node;
nodeView.Initialize(change.node, m_PreviewSystem);
m_GraphView.AddElement(nodeView);
}

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.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.userData as IEdge));
graph.ValidateGraph();
}

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


using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using UnityEngine.Experimental.UIElements.StyleSheets;
public class MaterialNodeView : Node
public sealed class MaterialNodeView : Node
public AbstractMaterialNode node { get; private set; }
List<VisualElement> m_ControlViews;
PreviewData m_Preview;
Image m_PreviewImage;
VisualElement m_PreviewToggle;
VisualElement m_ControlsContainer;
public MaterialNodeView(AbstractMaterialNode inNode, PreviewSystem previewSystem)
{
AddToClassList("MaterialNode");
if (inNode == null)
return;
node = inNode;
title = inNode.name;
m_ControlsContainer = new VisualElement
{
name = "controls"
};
leftContainer.Add(m_ControlsContainer);
m_PreviewToggle = new VisualElement { name = "toggle", text = "" };
m_PreviewToggle.AddManipulator(new Clickable(() => previewExpanded = !previewExpanded));
if (node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
previewExpanded = node.previewExpanded;
leftContainer.Add(m_PreviewToggle);
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
m_PreviewImage = new Image
{
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
m_Preview = previewSystem.GetPreview(inNode);
m_Preview.onPreviewChanged += UpdatePreviewTexture;
UpdatePreviewTexture();
leftContainer.Add(m_PreviewImage);
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
m_ControlViews = new List<VisualElement>();
foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
m_ControlViews.Add(attribute.InstantiateControl(node, propertyInfo));
expanded = node.drawState.expanded;
AddSlots(node.GetSlots<ISlot>());
SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));
UpdateControls();
if (node is PreviewNode)
{
var resizeHandle = new VisualElement { name = "resize", text = "" };
resizeHandle.AddManipulator(new Draggable(OnResize));
Add(resizeHandle);
UpdateSize();
}
int m_Version;
PreviewData m_Preview;
public Texture previewTexture { get; private set; }
public AbstractMaterialNode node { get; private set; }
public override bool expanded
{

if (base.expanded != value)
{
if (node.drawState.expanded != value)
{
UpdateControls();
public virtual void OnModified(ModificationScope scope)
bool previewExpanded
m_Version++;
get { return node.previewExpanded; }
set
{
node.previewExpanded = value;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}
}
public void OnModified(ModificationScope scope)
{
// Update slots to match node modification
if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();

{
}
{
}
foreach (var ve in anchorsToRemove)
outputContainer.Remove(ve);

}
}
protected virtual IEnumerable<GraphControlPresenter> GetControlData()
{
return Enumerable.Empty<GraphControlPresenter>();
}
protected void AddSlots(IEnumerable<ISlot> slots)
void AddSlots(IEnumerable<ISlot> slots)
{
foreach (var slot in slots)
{

data.userData = slot;
if (slot.isOutputSlot)
{
}
{
}
public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode as AbstractMaterialNode;
userData = node;
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;
// 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);
m_NodeGuid = node.guid;
if (node is PreviewNode)
{
if (!m_ResizeHandleAdded)
{
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
m_ResizeHandleAdded = true;
}
UpdateSize();
}
}
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<VisualElement> m_ControlViews;
Guid m_NodeGuid;
VisualElement m_PreviewToggle;
VisualElement m_ResizeHandle;
Image m_PreviewImage;
bool m_IsScheduled;
bool m_ResizeHandleAdded;
public MaterialNodeView()
{
CreateContainers();
AddToClassList("MaterialNode");
}
void CreateContainers()
{
m_ControlsContainer = new VisualElement
{
name = "controls"
};
leftContainer.Add(m_ControlsContainer);
m_ControlViews = new List<VisualElement>();
m_PreviewToggle = new VisualElement { name = "toggle", text = "" };
m_PreviewToggle.AddManipulator(new Clickable(OnPreviewToggle));
leftContainer.Add(m_PreviewToggle);
m_PreviewImage = new Image
{
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
leftContainer.Add(m_PreviewImage);
m_ResizeHandleAdded = false;
}
float updatedWidth = leftContainer.layout.width + deltaSize.x;
float updatedHeight = m_PreviewImage.layout.height + deltaSize.y;
var updatedWidth = leftContainer.layout.width + deltaSize.x;
var updatedHeight = m_PreviewImage.layout.height + deltaSize.y;
PreviewNode previewNode = node as PreviewNode;
var previewNode = node as PreviewNode;
if (previewNode != null)
{
previewNode.SetDimensions(updatedWidth, updatedHeight);

void OnPreviewToggle()
{
node.previewExpanded = !node.previewExpanded;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}
void UpdatePreviewTexture(Texture previewTexture)
void UpdatePreviewTexture()
if (previewTexture == null)
if (m_Preview.texture == null || !node.previewExpanded)
{
m_PreviewImage.visible = false;
m_PreviewImage.RemoveFromClassList("visible");

m_PreviewImage.visible = true;
m_PreviewImage.AddToClassList("visible");
m_PreviewImage.RemoveFromClassList("hidden");
m_PreviewImage.image = previewTexture;
m_PreviewImage.image = m_Preview.texture;
if (!node.guid.Equals(m_NodeGuid))
{
m_ControlViews.Clear();
foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
m_ControlViews.Add(attribute.InstantiateControl(node, propertyInfo));
}
}
if (!expanded)
{
m_ControlsContainer.Clear();

var previewNode = node as PreviewNode;
if (previewNode == null)
{
}
float width = previewNode.width;
float height = previewNode.height;
var width = previewNode.width;
var height = previewNode.height;
}
public void Dispose()
{
if (m_Preview != null)
{
m_Preview.onPreviewChanged -= UpdatePreviewTexture;
m_Preview = null;
}
}
}
}

2
MaterialGraphProject/ProjectSettings/QualitySettings.asset


blendWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
antiAliasing: 4
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1

27
MaterialGraphProject/Assets/graphs_PartyPreview.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: graphs_PartyPreview
m_Shader: {fileID: 4800000, guid: e67b8be7b087145ab87b7ae0a690c35e, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Texture_507A46B3:
m_Texture: {fileID: 2800000, guid: a653bbc25cc7e4794829cf7b1184abcb, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Float_D2D9489B: 3.3
m_Colors: []

8
MaterialGraphProject/Assets/graphs_PartyPreview.mat.meta


fileFormatVersion: 2
guid: 7f7b583966bf341438cffacfeba751eb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphControlPresenter.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public abstract class GraphControlPresenter : ScriptableObject
{
public INode node { get; private set; }
protected GraphControlPresenter()
{}
public void Initialize(INode inNode)
{
node = inNode;
}
public virtual void OnGUIHandler()
{
if (node == null)
return;
GUIUtility.GetControlID(node.guid.GetHashCode(), FocusType.Passive);
}
public abstract float GetHeight();
}
}

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


fileFormatVersion: 2
guid: 070b72651e4f90b478ca6f031541065e
timeCreated: 1476707366
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

84
MaterialGraphProject/GeneratedShader.shader


Shader "hidden/preview/Fractal_70AE3FBF"
{
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_70AE3FBF_result;
};
float4 Fractal_70AE3FBF_uv;
float4 Fractal_70AE3FBF_pan;
float Fractal_70AE3FBF_zoom;
float Fractal_70AE3FBF_aspect;
GraphVertexInput PopulateVertexData(GraphVertexInput v){
return v;
}
SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {
half4 uv0 = IN.uv0;
float Fractal_70AE3FBF_result;
Unity_Fractal_float(uv0, Fractal_70AE3FBF_pan, Fractal_70AE3FBF_zoom, Fractal_70AE3FBF_aspect, Fractal_70AE3FBF_result);
SurfaceDescription surface = (SurfaceDescription)0;
surface.Fractal_70AE3FBF_result = Fractal_70AE3FBF_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_70AE3FBF_result, surf.Fractal_70AE3FBF_result, surf.Fractal_70AE3FBF_result, 1.0);
}
ENDCG
}
}
}
正在加载...
取消
保存