浏览代码

Fix up setting preview properties to be pull based instead of push based (needs close review)

/main
Tim Cooper 9 年前
当前提交
c2f74843
共有 9 个文件被更改,包括 66 次插入32 次删除
  1. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs
  2. 21
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  3. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
  4. 7
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs
  5. 7
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphInputsNode.cs
  6. 10
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphNode.cs
  7. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  8. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs
  9. 33
      UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/Editors/BaseMaterialNodeEditor.cs


slot.title = EditorGUILayout.TextField("Title", slot.title);
var def = node.GetSlotDefaultValue(slot.name);
if (def != null)
if (def != null && def.OnGUI())
if (def.OnGUI())
{
node.UpdatePreviewProperties();
}
node.UpdatePreviewProperties();
node.ForwardPreviewMaterialPropertyUpdate();
}
}

21
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


private const int kPreviewWidth = 64;
private const int kPreviewHeight = 64;
[NonSerialized]
private UnityEngine.Material m_Material;
[SerializeField]

{
m_Material = new UnityEngine.Material(defaultPreviewShader) {hideFlags = HideFlags.DontSave};
UpdatePreviewMaterial();
UpdatePreviewProperties();
}
return m_Material;

}
}
protected void SetDependentPreviewMaterialProperty(PreviewProperty previewProperty)
public void ForwardPreviewMaterialPropertyUpdate()
{
var dependentNodes = CollectDependentNodes();

node.SetPreviewMaterialProperty(previewProperty);
node.UpdatePreviewProperties();
public virtual void UpdatePreviewProperties()
protected virtual void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
{
foreach (var s in inputSlots)
{

m_PropType = PropertyType.Vector4,
m_Vector4 = defaultInput.defaultValue
};
SetDependentPreviewMaterialProperty(pp);
properties.Add (pp);
}
public void UpdatePreviewProperties()
{
var childrenNodes = CollectChildNodesByExecutionOrder();
var pList = new List<PreviewProperty>();
foreach (var node in childrenNodes)
node.CollectPreviewMaterialProperties(pList);
foreach (var prop in pList)
SetPreviewMaterialProperty (prop);
}
#endregion

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs


boundProp.defaultColor = m_Color;
}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
}
}

if (rebuildShaders)
RegeneratePreviewShaders();
else
{
ForwardPreviewMaterialPropertyUpdate();
}
}
public override PreviewProperty GetPreviewProperty()

7
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PropertyNode.cs


public abstract PreviewProperty GetPreviewProperty();
public override void UpdatePreviewProperties()
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
base.UpdatePreviewProperties();
MaterialWindow.DebugMaterialGraph("In Property Node: " + this);
SetDependentPreviewMaterialProperty(GetPreviewProperty());
base.CollectPreviewMaterialProperties(properties);
properties.Add(GetPreviewProperty());
}
public void UnbindProperty(ShaderProperty prop)

7
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphInputsNode.cs


using UnityEngine;
using System.Collections.Generic;
namespace UnityEditor.Graphs.Material
{

}
}
public override void UpdatePreviewProperties()
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
base.UpdatePreviewProperties();
base.CollectPreviewMaterialProperties(properties);
foreach (var slot in outputSlots)
{
if (slot.edges.Count == 0)

m_PropType = PropertyType.Vector4,
m_Vector4 = defaultOutput.defaultValue
};
SetDependentPreviewMaterialProperty(pp);
properties.Add (pp);
}
}
}

10
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SubGraphNode.cs


m_SubGraphAsset.GeneratePropertyUsages(visitor, GenerationMode.SurfaceShader);
}
public override void UpdatePreviewProperties()
protected override void CollectPreviewMaterialProperties (List<PreviewProperty> properties)
base.UpdatePreviewProperties();
var previewProperties = m_SubGraphAsset.GetPreviewProperties();
foreach (var prop in previewProperties)
SetDependentPreviewMaterialProperty(prop);
base.CollectPreviewMaterialProperties(properties);
properties.AddRange(m_SubGraphAsset.GetPreviewProperties());
}
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs


boundProp.defaultTextureType = m_TextureType;
}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
}
}

if (rebuildShaders)
RegeneratePreviewShaders();
else
{
ForwardPreviewMaterialPropertyUpdate();
}
}
public override PreviewProperty GetPreviewProperty()

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs


boundProp.defaultVector = m_Value;
}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
}
}

if (rebuildShaders)
RegeneratePreviewShaders();
else
{
ForwardPreviewMaterialPropertyUpdate();
}
}
public override PreviewProperty GetPreviewProperty()

33
UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph


m_ToSlotName: Input0
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11468266}
m_ToNode: {fileID: 11445316}
m_FromSlotName: Output
m_ToSlotName: UV
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11468266}
m_ToNode: {fileID: 11472310}
m_FromSlotName: Output
m_ToSlotName: UV

m_FromSlotName: Output
m_ToSlotName: Input1
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11468266}
m_ToNode: {fileID: 11445316}
m_FromSlotName: Output
m_ToSlotName: UV
color: {r: 1, g: 1, b: 1, a: 1}
m_InvalidEdges: []
--- !u!114 &11445316
MonoBehaviour:

position:
serializedVersion: 2
x: 240
y: -300
y: -312
width: 213
height: 139
showEmptySlots: 1

m_Node: {fileID: 11445316}
m_PrecisionNames:
- half
m_BoundProperty: {fileID: 0}
m_DefaultTexture: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8, type: 3}
m_BoundProperty: {fileID: 11475776}
m_DefaultTexture: {fileID: 2800000, guid: 28bdf1ba8c076ef4e910b59cc1baf342, type: 3}
m_TextureType: 0
--- !u!114 &11445996
MonoBehaviour:

m_BoundProperty: {fileID: 0}
m_DefaultTexture: {fileID: 2800000, guid: d5649239aacf54d4e8d6f656d15d30b0, type: 3}
m_TextureType: 3
--- !u!114 &11475776
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b793ff9211c8787428ec61378a5b39ac, type: 3}
m_Name: TextureProperty
m_EditorClassIdentifier:
m_PropertyDescription:
m_DefaultTexture: {fileID: 2800000, guid: 28bdf1ba8c076ef4e910b59cc1baf342, type: 3}
m_DefaultTextureType: 0
--- !u!114 &11477068
MonoBehaviour:
m_ObjectHideFlags: 1

m_Script: {fileID: 11500000, guid: cab057dbd683f5244aed9bd721e1973e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ShaderProperties: []
m_ShaderProperties:
- {fileID: 11475776}
previewState: 0
--- !u!114 &11480530
MonoBehaviour:

正在加载...
取消
保存