浏览代码

Use attribute controls for Matrix nodes

/main
Peter Bay Bastian 7 年前
当前提交
7bb42428
共有 12 个文件被更改,包括 115 次插入269 次删除
  1. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
  2. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
  3. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix2NodePresenter.cs.meta
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix3NodePresenter.cs.meta
  7. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix4NodePresenter.cs.meta
  8. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix2NodePresenter.cs
  9. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix3NodePresenter.cs
  10. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix4NodePresenter.cs
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs.meta
  12. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector2[] m_Value = new Vector2[2];
Vector2 m_Row0;
public Vector2 this[int index]
[SerializeField]
Vector2 m_Row1;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
void SetRow(ref Vector2 row, Vector2 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
public Matrix2Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix2, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix2, Vector2.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "2 " + name + " = " + precision + "2x2 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[1].x + ", " + m_Value[1].y + ");", true);
visitor.AddShaderChunk(precision + "2 " + name + " = " + precision + "2x2 (" + m_Row0.x + ", " + m_Row0.y + ", " + m_Row1.x + ", " + m_Row1.y + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
m_Vector2 = m_Value
};
}*/
}

56
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector3[] m_Value = new Vector3[3];
Vector3 m_Row0;
public Vector3 this[int index]
[SerializeField]
Vector3 m_Row1;
[SerializeField]
Vector3 m_Row2;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
void SetRow(ref Vector3 row, Vector3 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
public Matrix3Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix3, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix3, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "3x3 " + propertyName + " = " + precision + "3x3 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[0].z + ", " + m_Value[1].x + ", " + m_Value[1].y + ", " + m_Value[1].z + ", " + m_Value[2].x + ", " + m_Value[2].y + ", " + m_Value[2].z + ");", true);
visitor.AddShaderChunk(precision + "3x3 " + propertyName + " = " + precision + "3x3 (" + m_Row0.x + ", " + m_Row0.y + ", " + m_Row0.z + ", " + m_Row1.x + ", " + m_Row1.y + ", " + m_Row1.z + ", " + m_Row2.x + ", " + m_Row2.y + ", " + m_Row2.z + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
m_Vector3 = m_Value
};
}*/
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs


using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
const int kOutputSlotId = 0;
const string kOutputSlotName = "Value";
private Vector4[] m_Value = new Vector4[4];
Vector4 m_Row0;
[SerializeField]
Vector4 m_Row1;
[SerializeField]
Vector4 m_Row2;
[SerializeField]
Vector4 m_Row3;
public Vector4 this[int index]
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row0
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
m_Value[index] = value;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row3
{
get { return m_Row3; }
set { SetRow(ref m_Row3, value); }
}
void SetRow(ref Vector4 row, Vector4 value)
{
if (value == row)
return;
row = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
public Matrix4Node()

//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "4x4 " + propertyName + " = " + precision + "4x4 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[0].z + ", " + m_Value[0].w + ", " + m_Value[1].x + ", " + m_Value[1].y + ", " + m_Value[1].z + ", " + m_Value[1].w + ", " + m_Value[2].x + ", " + m_Value[2].y + ", " + m_Value[2].z + ", " + m_Value[2].w + ", " + m_Value[3].x + ", " + m_Value[3].y + ", " + m_Value[3].z + ", " + m_Value[3].w + ");", true);
visitor.AddShaderChunk(precision + "4x4 " + propertyName + " = " + precision + "4x4 (" + row0.x + ", " + row0.y + ", " + row0.z + ", " + row0.w + ", " + m_Row1.x + ", " + m_Row1.y + ", " + m_Row1.z + ", " + m_Row1.w + ", " + m_Row2.x + ", " + m_Row2.y + ", " + m_Row2.z + ", " + m_Row2.w + ", " + m_Row3.x + ", " + m_Row3.y + ", " + m_Row3.z + ", " + m_Row3.w + ");", true);
private string m_Description = string.Empty;
string m_Description = string.Empty;
public string description
{

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


// typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
// typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix2NodePresenter.cs.meta


fileFormatVersion: 2
guid: 7a56e192798ff9a45a01f10c9113e539
timeCreated: 1476871291
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix3NodePresenter.cs.meta


fileFormatVersion: 2
guid: 8cb077290891de74d905d2361f73441b
timeCreated: 1476871291
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix4NodePresenter.cs.meta


fileFormatVersion: 2
guid: 8183008b69a6d79419dc9f1f08d12f4d
timeCreated: 1476871291
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix2NodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class Matrix2ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.Matrix2Node;
if (tNode == null)
return;
tNode[0] = EditorGUILayout.Vector2Field("", tNode[0]);
tNode[1] = EditorGUILayout.Vector2Field("", tNode[1]);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class Matrix2NodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<Matrix2ControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

40
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix3NodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class Matrix3ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.Matrix3Node;
if (tNode == null)
return;
tNode[0] = EditorGUILayout.Vector3Field("", tNode[0]);
tNode[1] = EditorGUILayout.Vector3Field("", tNode[1]);
tNode[2] = EditorGUILayout.Vector3Field("", tNode[2]);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class Matrix3NodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<Matrix3ControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/Matrix4NodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class Matrix4ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.Matrix4Node;
if (tNode == null)
return;
tNode[0] = EditorGUILayout.Vector4Field("", tNode[0]);
tNode[1] = EditorGUILayout.Vector4Field("", tNode[1]);
tNode[2] = EditorGUILayout.Vector4Field("", tNode[2]);
tNode[3] = EditorGUILayout.Vector4Field("", tNode[3]);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class Matrix4NodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<Matrix4ControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}

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


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

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


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class PropertyControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as PropertyNode;
if (tNode == null)
return;
var graph = node.owner as AbstractMaterialGraph;
var currentGUID = tNode.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
var newIndex = EditorGUILayout.Popup("Property", currentSelectedIndex, properties.Select(x => x.displayName).ToArray());
if (newIndex != currentSelectedIndex)
tNode.propertyGuid = propertiesGUID[newIndex];
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2 + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class PropertyNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<PropertyControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}
正在加载...
取消
保存