浏览代码

Add axis selection to Matrix Split and Construction nodes

/main
Matt Dean 7 年前
当前提交
6298bd34
共有 2 个文件被更改,包括 76 次插入6 次删除
  1. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixConstructionNode.cs
  2. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixSplitNode.cs

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixConstructionNode.cs


using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{

UpdateNodeAfterDeserialization();
}
[SerializeField]
MatrixAxis m_Axis;
[EnumControl("")]
MatrixAxis axis
{
get { return m_Axis; }
set
{
if (m_Axis.Equals(value))
return;
m_Axis = value;
Dirty(ModificationScope.Graph);
}
}
static string[] s_ComponentList = new string[4] { "r", "g", "b", "a" };
string GetFunctionName()
{
return string.Format("Unity_MatrixConstruction_{0}", precision);

FindOutputSlot<MaterialSlot>(Output2x2SlotId).concreteValueType.ToString(precision));
using (s.BlockScope())
{
s.AppendLine("Out4x4 = {0}4x4(M0.x, M0.y, M0.z, M0.w, M1.x, M1.y, M1.z, M1.w, M2.x, M2.y, M2.z, M2.w, M3.x, M3.y, M3.z, M3.w);", precision);
s.AppendLine("Out3x3 = {0}3x3(M0.x, M0.y, M0.z, M1.x, M1.y, M1.z, M2.x, M2.y, M2.z);", precision);
s.AppendLine("Out2x2 = {0}2x2(M0.x, M0.y, M1.x, M1.y);", precision);
switch(m_Axis)
{
case MatrixAxis.Column:
s.AppendLine("Out4x4 = {0}4x4(M0.x, M1.x, M2.x, M3.x, M0.y, M1.y, M2.y, M3.y, M0.z, M1.z, M2.z, M3.z, M0.w, M1.w, M2.w, M3.w);", precision);
s.AppendLine("Out3x3 = {0}3x3(M0.x, M1.x, M2.x, M0.y, M1.y, M2.y, M0.z, M1.z, M2.z);", precision);
s.AppendLine("Out2x2 = {0}2x2(M0.x, M1.x, M0.y, M1.y);", precision);
break;
default:
s.AppendLine("Out4x4 = {0}4x4(M0.x, M0.y, M0.z, M0.w, M1.x, M1.y, M1.z, M1.w, M2.x, M2.y, M2.z, M2.w, M3.x, M3.y, M3.z, M3.w);", precision);
s.AppendLine("Out3x3 = {0}3x3(M0.x, M0.y, M0.z, M1.x, M1.y, M1.z, M2.x, M2.y, M2.z);", precision);
s.AppendLine("Out2x2 = {0}2x2(M0.x, M0.y, M1.x, M1.y);", precision);
break;
}
}
});
}

47
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixSplitNode.cs


using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
public enum MatrixAxis
{
Row,
Column
}
[Title("Math", "Matrix", "Matrix Split")]
public class MatrixSplitNode : AbstractMaterialNode, IGeneratesBodyCode
{

UpdateNodeAfterDeserialization();
}
[SerializeField]
MatrixAxis m_Axis;
[EnumControl("")]
MatrixAxis axis
{
get { return m_Axis; }
set
{
if (m_Axis.Equals(value))
return;
m_Axis = value;
Dirty(ModificationScope.Graph);
}
}
static string[] s_ComponentList = new string[4] { "r", "g", "b", "a" };
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicMatrixMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input));

for (var i = 0; i < 4; i++)
{
var outputFormat = string.Format("{0}[{1}]", inputValue, i);
string outputValue;
if(i >= numInputRows)
{

outputValue += ", ";
outputValue += "0";
}
outputValue += ");";
outputValue += ")";
outputValue = outputFormat;
{
switch(m_Axis)
{
case MatrixAxis.Column:
outputValue = string.Format("{0}{1}(", precision, numInputRows);
for(int r = 0; r < numInputRows; r++)
{
if(r!= 0)
outputValue += ", ";
outputValue += string.Format("{0}[{1}].{2}", inputValue, r, s_ComponentList[i]);
}
outputValue += ")";
break;
default:
outputValue = string.Format("{0}[{1}]", inputValue, i);
break;
}
}
visitor.AddShaderChunk(string.Format("{0}{1} {2} = {3};", precision, numInputRows, GetVariableNameForSlot(s_OutputSlots[i]), outputValue), true);
}
}

正在加载...
取消
保存