浏览代码

Added Matrix4 and fixed Matrix multiply

/main
Matt Dean 8 年前
当前提交
3bce395a
共有 12 个文件被更改,包括 210 次插入8 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix2Node.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix3Node.cs
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs
  5. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  6. 26
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixMultiplyNode.cs
  7. 1
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph
  8. 9
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta
  9. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix4NodePresenter.cs
  10. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix4NodePresenter.cs.meta
  11. 103
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix4Node.cs
  12. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix4Node.cs.meta

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


typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix2Node.cs


//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2x2 (" + precision + "2(" + m_Value[0].x + ", " + m_Value[0].y + "), " + precision + "2(" + m_Value[1].x + ", " + m_Value[1].y + "))", true);
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2x2 (" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[1].x + ", " + m_Value[1].y + ");", true);
}
[SerializeField]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix3Node.cs


//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
visitor.AddShaderChunk(precision + "3x3 (" + precision + "3(" + m_Value[0].x + ", " + m_Value[0].y + ", " + m_Value[0].z + "), " + precision + "3(" + m_Value[1].x + ", " + m_Value[1].y + ", " + m_Value[1].z + "), " + precision + "3(" + m_Value[2].x + ", " + m_Value[2].y + ", " + m_Value[2].z + "))", true);
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);
}
[SerializeField]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs


if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
visitor.AddShaderChunk(precision + "2x2 " + propertyName + " = " + precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
}
public override PreviewProperty GetPreviewProperty()

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs


case ConcreteSlotValueType.Vector4:
return matOwner.precision + "4 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + "," + m_CurrentValue.w + ")";
case ConcreteSlotValueType.Matrix2:
return matOwner.precision + "2x2 (" + matOwner.precision + "2(" + m_CurrentValue.x + ", " + m_CurrentValue.x + "), " + matOwner.precision + "2(" + m_CurrentValue.y + ", "+ m_CurrentValue.y + "))";
return matOwner.precision + "2x2 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", "+ m_CurrentValue.y + ")";
return matOwner.precision + "3x3 (" + matOwner.precision + "3(" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + "), " + matOwner.precision + "3(" + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + "), " + matOwner.precision + "3(" + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + "))";
return matOwner.precision + "3x3 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ")";
return matOwner.precision + "4x4 (" + matOwner.precision + "4(" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + "), " + matOwner.precision + "4(" + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + "), " + matOwner.precision + "4(" + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + "), " + matOwner.precision + "4(" + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + "))";
return matOwner.precision + "4x4 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ")";
default:
return "error";
}

26
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixMultiplyNode.cs


using UnityEngine.Graphing;
[Title("Matrix/Multiply Node")]
[Title("Math/Matrix/Multiply")]
name = "MatrixMultiplyNode";
name = "MatrixMultiply";
}
protected override string GetFunctionName()

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override bool hasPreview
{
get { return false; }
}
/*protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix3, Vector4.zero);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Matrix3, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix3, Vector4.zero);
}*/
}
}

1
MaterialGraphProject/Assets/Matt/Test.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta


fileFormatVersion: 2
guid: 62568f909ca80d342836892f01cb06c9
timeCreated: 1495663356
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix4NodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
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<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<Matrix4ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

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


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

103
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix4Node.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Matrix/Matrix 4")]
public class Matrix4Node : AbstractMaterialNode, IGeneratesBodyCode
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
[SerializeField]
private Vector4[] m_Value = new Vector4[4];
public Vector4 this[int index]
{
get { return m_Value[index]; }
set
{
if (m_Value[index] == value)
return;
m_Value[index] = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public Matrix4Node()
{
name = "Matrix4";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public string propertyName
{
get
{
return string.Format("{0}_{1}_Uniform", name, guid.ToString().Replace("-", "_"));
}
}
public override string GetVariableNameForSlot(int slotId)
{
return propertyName;
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//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);
}
[SerializeField]
private string m_Description = string.Empty;
public string description
{
get
{
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
}
set { m_Description = value; }
}
// TODO - Remove Property entries everywhere?
// Matrix cant be a shader property
/*public override PropertyType propertyType
{
get { return PropertyType.Matrix2; }
}*/
/*public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}*/
/*public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
}*/
/*public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};
}*/
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/Matrix4Node.cs.meta


fileFormatVersion: 2
guid: d3889ae2c6ffabd40a2ee45f5b051d3b
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存