浏览代码

Replaced MarkDirtyHack with scoped OnModified and optimised preview rendering

/main
Peter Bay Bastian 8 年前
当前提交
92dd5d89
共有 12 个文件被更改,包括 117 次插入31 次删除
  1. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
  2. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  3. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs
  4. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs
  5. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
  6. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
  9. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  10. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
  11. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/something.ShaderGraph
  12. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/something.ShaderGraph.meta

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs


public IGraphAsset graphAsset { get; private set; }
void OnNodeChanged(INode inNode, NodeModificationScope scope)
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);

var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.MarkDirtyHack();
drawableNodeData.OnModified(scope);
}
EditorUtility.SetDirty(graphAsset.GetScriptableObject());

if (toNode != null)
{
// Make the input node (i.e. right side of the connection) re-render
toNode.MarkDirtyHack();
OnNodeChanged(toNode.node, ModificationScope.Graph);
}
deletedElements.Add(edgeData);

var targetAnchors = targetNode.elements.OfType<AnchorDrawData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
targetNode.MarkDirtyHack();
OnNodeChanged(targetNode.node, ModificationScope.Graph);
var edgeData = ScriptableObject.CreateInstance<EdgeDrawData>();
edgeData.Initialize(edge);

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


get { return m_Children; }
}
//TODO: Kill this and the function below after talking with shanti
[SerializeField]
private int m_SerializationRandom;
public void MarkDirtyHack()
{
m_SerializationRandom++;
}
public virtual void OnModified(ModificationScope scope)
{}
public override void CommitChanges()
{

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs


namespace UnityEngine.Graphing
{
public enum NodeModificationScope
public enum ModificationScope
Redraw,
ShaderRegeneration
Nothing,
Node,
Graph
public delegate void OnNodeModified(INode node, NodeModificationScope scope);
public delegate void OnNodeModified(INode node, ModificationScope scope);
public interface INode
{

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs


[Serializable]
public class MaterialNodeDrawData : NodeDrawData
{
NodePreviewDrawData nodePreviewDrawData;
}
public override void OnModified(ModificationScope scope)
{
base.OnModified(scope);
if (nodePreviewDrawData != null)
nodePreviewDrawData.modificationScope = scope;
}
protected MaterialNodeDrawData()

if (materialNode == null || !materialNode.hasPreview)
return;
var previewData = CreateInstance<NodePreviewDrawData>();
previewData.Initialize(materialNode);
m_Children.Add(previewData);
nodePreviewDrawData = CreateInstance<NodePreviewDrawData>();
nodePreviewDrawData.Initialize(materialNode);
m_Children.Add(nodePreviewDrawData);
}
}
}

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs


private AbstractMaterialNode m_Node;
[NonSerialized]
private ModificationScope m_modificationScope;
// Null means no modification is currently in progress.
public ModificationScope modificationScope
{
get
{
return m_modificationScope;
}
set
{
// External changes can only set the modification scope higher, to prevent missing out on a previously set shader regeneration.
if (m_modificationScope == ModificationScope.Graph || (m_modificationScope == ModificationScope.Node && value == ModificationScope.Nothing))
return;
m_modificationScope = value;
}
}
[NonSerialized]
private Texture m_texture;
private PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D;
public Material previewMaterial

public void Initialize(AbstractMaterialNode node)
{
m_Node = node;
m_modificationScope = ModificationScope.Graph;
}
public Texture Render(Vector2 dimension)

if (m_Node.hasPreview == false)
return null;
if (m_LastShaderVersion != m_Node.version)
if (m_modificationScope != ModificationScope.Nothing)
{
bool status = false;
if (m_modificationScope == ModificationScope.Graph)
{
// TODO: Handle shader regeneration error
status = UpdatePreviewShader();
}
m_texture = RenderPreview(dimension);
m_modificationScope = ModificationScope.Nothing;
}
else if (m_texture == null)
if (UpdatePreviewShader())
m_LastShaderVersion = m_Node.version;
m_texture = RenderPreview(dimension);
return RenderPreview(dimension);
return m_texture;
}
protected virtual string GetPreviewShaderString()

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs


using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
using UnityEditor.Graphing.Util;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{

private void SchedulePolling()
{
Debug.LogFormat("SchedulePolling");
this.Schedule(InvalidateUIIfNeedsTime).StartingIn(0).Every(30);
this.Schedule(InvalidateUIIfNeedsTime).StartingIn(0).Every(16);
m_IsScheduled = true;
}
}

private void UnschedulePolling()
{
Debug.LogFormat("UnschedulePolling");
if (m_IsScheduled && panel != null)
{
this.Unschedule(InvalidateUIIfNeedsTime);

private void InvalidateUIIfNeedsTime(TimerState timerState)
{
var data = GetData<MaterialNodeDrawData>();
var data = GetData<MaterialNodeDrawData>();
this.Touch(ChangeType.Repaint);
{
data.OnModified(ModificationScope.Node);
}
ListPool<INode>.Release(childrenNodes);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs


m_Color = value;
if (onModified != null)
{
onModified(this, NodeModificationScope.ShaderRegeneration);
onModified(this, ModificationScope.Node);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs


m_Exposed = value;
if (onModified != null)
{
onModified(this, NodeModificationScope.ShaderRegeneration);
onModified(this, ModificationScope.Graph);
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


if (onModified != null)
{
onModified(this, NodeModificationScope.ShaderRegeneration);
onModified(this, ModificationScope.Graph);
}
}
}

m_TextureType = value;
if (onModified != null)
{
onModified(this, NodeModificationScope.ShaderRegeneration);
onModified(this, ModificationScope.Graph);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs


m_Value = value;
if (onModified != null)
onModified(this, NodeModificationScope.ShaderRegeneration);
onModified(this, ModificationScope.Node);
}
}

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/something.ShaderGraph


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 562bd27a5e73fc64d80a1d9d936ffbd5, type: 3}
m_Name: something
m_EditorClassIdentifier:
m_MaterialGraph:
m_MaterialOptions:
m_SrcBlend: 0
m_DstBlend: 1
m_CullMode: 0
m_ZTest: 2
m_ZWrite: 0
m_RenderQueue: 1
m_RenderType: 0
m_ShadowPass: 0
m_FullForwardShadows: 0
m_NoAmbient: 0
m_NoVertexLights: 0
m_NoLightmaps: 0
m_NoDirLightmap: 0
m_NoForwardAdd: 0
m_ApproxView: 0
m_HalfAsView: 0
m_Expanded: 0
m_PixelGraph:
m_SerializableNodes: []
m_SerializableEdges: []
m_Name:

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/something.ShaderGraph.meta


fileFormatVersion: 2
guid: 77154e36df4ac4c88b3ede1e4169e2e9
timeCreated: 1477575321
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存