浏览代码

Fix matrix defaults

/main
Matt Dean 7 年前
当前提交
e20fd08b
共有 12 个文件被更改,包括 90 次插入60 次删除
  1. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs
  2. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs
  3. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2ShaderProperty.cs
  4. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3ShaderProperty.cs
  6. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs
  7. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4ShaderProperty.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MatrixShaderProperty.cs
  9. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixConstructionNode.cs
  10. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixSplitNode.cs
  11. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs
  12. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs.meta

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs


public class DynamicMatrixMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
{
[SerializeField]
private Matrix4x4 m_Value;
private Matrix4x4 m_Value = Matrix4x4.identity;
private Matrix4x4 m_DefaultValue;
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Matrix4;

m_Value = value;
}
public override VisualElement InstantiateControl()
{
return new LabelSlotControlView("Identity");
}
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
public Matrix4x4 value

protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
var channelCount = (int)SlotValueHelper.GetChannelCount(concreteValueType);
var channelCount = (int)SlotValueHelper.GetMatrixDimension(concreteValueType);
bool isFirst = true;
for (var i = 0; i < channelCount; i++)
for (var c = 0; c < channelCount; c++)
values += ", " + value.GetRow(r)[i];
if(!isFirst)
values += ", ";
isFirst = false;
values += value.GetRow(r)[c];
return string.Format("{0}{1}({2})", precision, channelCount, values);
return string.Format("{0}{1}x{1}({2})", precision, channelCount, values);
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs


using System;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

[SerializeField]
private Matrix4x4 m_Value;
private Matrix4x4 m_Value = Matrix4x4.identity;
private Matrix4x4 m_DefaultValue;
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
public Matrix2MaterialSlot()
{

bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
public override VisualElement InstantiateControl()
{
return new LabelSlotControlView("Identity");
}
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2ShaderProperty.cs


public override string GetPropertyDeclarationString(string delimiter = ";")
{
return "float2x2 " + referenceName + ";";
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)" + delimiter;
}
public override INode ToConcreteNode()

row0 = new Vector2(value.m00, value.m01),
row1 = new Vector2(value.m10, value.m11)
};
}
}
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs


using System;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

[SerializeField]
private Matrix4x4 m_Value;
private Matrix4x4 m_Value = Matrix4x4.identity;
private Matrix4x4 m_DefaultValue;
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
public Matrix3MaterialSlot()
{

bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
public override VisualElement InstantiateControl()
{
return new LabelSlotControlView("Identity");
}
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3ShaderProperty.cs


public override string GetPropertyDeclarationString(string delimiter = ";")
{
return "float3x3 " + referenceName + ";";
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)" + delimiter;
}
public override INode ToConcreteNode()

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs


using System;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

[SerializeField]
private Matrix4x4 m_Value;
private Matrix4x4 m_Value = Matrix4x4.identity;
private Matrix4x4 m_DefaultValue;
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
public Matrix4MaterialSlot()
{

bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
public override VisualElement InstantiateControl()
{
return new LabelSlotControlView("Identity");
}
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4ShaderProperty.cs


get { return PropertyType.Matrix4; }
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return "float4x4 " + referenceName + ";";
}
public override INode ToConcreteNode()
{
return new Matrix4Node

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MatrixShaderProperty.cs


public override string GetPropertyDeclarationString(string delimiter = ";")
{
return "float4x4 " + referenceName + ";";
return "float4x4 " + referenceName + " = float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)" + delimiter;
}
public override PreviewProperty GetPreviewMaterialProperty()

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


}
}
static string[] s_ComponentList = new string[4] { "r", "g", "b", "a" };
string GetFunctionName()
{
return string.Format("Unity_MatrixConstruction_{0}", precision);

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


[Title("Math", "Matrix", "Matrix Split")]
public class MatrixSplitNode : AbstractMaterialNode, IGeneratesBodyCode
{
const string kInputSlotName = "Input";
const string kInputSlotName = "In";
const string kOutputSlotM0Name = "M0";
const string kOutputSlotM1Name = "M1";
const string kOutputSlotM2Name = "M2";

var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId);
var numInputRows = 0;
bool useIndentity = false;
if (inputSlot != null)
{
numInputRows = SlotValueHelper.GetMatrixDimension(inputSlot.concreteValueType);

if (!owner.GetEdges(inputSlot.slotReference).Any())
{
useIndentity = true;
}
for (var i = 0; i < 4; i++)
int concreteRowCount = useIndentity ? 2 : numInputRows;
for (var r = 0; r < 4; r++)
if(i >= numInputRows)
if(r >= numInputRows)
outputValue = string.Format("{0}{1}(", precision, numInputRows);
for(int r = 0; r < numInputRows; r++)
outputValue = string.Format("{0}{1}(", precision, concreteRowCount);
for(int c = 0; c < concreteRowCount; c++)
if(r!= 0)
if(c!= 0)
outputValue += "0";
outputValue += Matrix4x4.identity.GetRow(r)[c];
}
outputValue += ")";
}

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

ListPool<DynamicMatrixMaterialSlot>.Release(skippedDynamicMatrixSlots);
DictionaryPool<DynamicMatrixMaterialSlot, ConcreteSlotValueType>.Release(dynamicMatrixInputSlotsToCompare);
}
public override ConcreteSlotValueType ConvertDynamicInputTypeToConcrete(IEnumerable<ConcreteSlotValueType> inputTypes)
{
var concreteSlotValueTypes = inputTypes as IList<ConcreteSlotValueType> ?? inputTypes.ToList();
var inputTypesDistinct = concreteSlotValueTypes.Distinct().ToList();
switch (inputTypesDistinct.Count)
{
case 0:
return ConcreteSlotValueType.Vector1;
case 1:
return inputTypesDistinct.FirstOrDefault();
default:
// find the 'minumum' channel width excluding 1 as it can promote
inputTypesDistinct.RemoveAll(x => x == ConcreteSlotValueType.Vector1);
var ordered = inputTypesDistinct.OrderByDescending(x => x);
if (ordered.Any())
return ordered.FirstOrDefault();
break;
}
return ConcreteSlotValueType.Vector1;
}
}
}

19
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs


using System;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class LabelSlotControlView : VisualElement
{
public LabelSlotControlView(string label)
{
var labelField = new Label (label);
Add(labelField);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/LabelSlotControlView.cs.meta


fileFormatVersion: 2
guid: b7e0bdc2deb5a43aca74fd1e84c94cfa
timeCreated: 1509718979
正在加载...
取消
保存