浏览代码

Add preview serialization for matrices

/main
Matt Dean 7 年前
当前提交
e5bdf43e
共有 3 个文件被更改,包括 201 次插入121 次删除
  1. 89
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix2Node.cs
  2. 106
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix3Node.cs
  3. 127
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Matrix/Matrix4Node.cs

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


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

const int kOutputSlotId = 0;
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]

if (value == row)
return;
row = value;
Dirty(ModificationScope.Graph);
Dirty(ModificationScope.Node);
}
public Matrix2Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix2MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
AddSlot(new Matrix2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
public override string GetVariableNameForSlot(int slotId)
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
return GetVariableNameForNode();
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector2ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
properties.AddShaderProperty(new Vector2ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
visitor.AddShaderChunk(precision + "2x2 " + GetVariableNameForNode() + " = " + precision + "2x2 (" + m_Row0.x + ", " + m_Row0.y + ", " + m_Row1.x + ", " + m_Row1.y + ");", true);
}
[SerializeField]
string m_Description = string.Empty;
public string description
{
get
var sb = new ShaderStringBuilder();
if (!generationMode.IsPreview())
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
sb.AppendLine("{0}3 _{1}_m0 = {0}3 ({2}, {3});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y));
sb.AppendLine("{0}3 _{1}_m1 = {0}3 ({2}, {3});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y));
set { m_Description = value; }
sb.AppendLine("{0}2x2 {1} = {0}2x2 (_{1}_m0.x, _{1}_m0.y, _{1}_m1.x, _{1}_m1.y);",
precision, GetVariableNameForNode());
visitor.AddShaderChunk(sb.ToString(), false);
// 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)
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}*/
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
/*public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
}*/
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
}
/*public override PreviewProperty GetPreviewProperty()
public override string GetVariableNameForSlot(int slotId)
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector2 = m_Value
};
}*/
return GetVariableNameForNode();
}
}
}

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


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

const int kOutputSlotId = 0;
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]

if (value == row)
return;
row = value;
Dirty(ModificationScope.Graph);
Dirty(ModificationScope.Node);
}
public Matrix3Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
AddSlot(new Matrix3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
public override string GetVariableNameForSlot(int slotId)
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
return GetVariableNameForNode();
}
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + "3x3 " + GetVariableNameForNode() + " = " + 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);
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m2", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row2
});
[SerializeField]
string m_Description = string.Empty;
public string description
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
get
var sb = new ShaderStringBuilder();
if (!generationMode.IsPreview())
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
sb.AppendLine("{0}3 _{1}_m0 = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y),
NodeUtils.FloatToShaderValue(m_Row0.z));
sb.AppendLine("{0}3 _{1}_m1 = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y),
NodeUtils.FloatToShaderValue(m_Row1.z));
sb.AppendLine("{0}3 _{1}_m2 = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row2.x),
NodeUtils.FloatToShaderValue(m_Row2.y),
NodeUtils.FloatToShaderValue(m_Row2.z));
set { m_Description = value; }
sb.AppendLine("{0}3x3 {1} = {0}3x3 (_{1}_m0.x, _{1}_m0.y, _{1}_m0.z, _{1}_m1.x, _{1}_m1.y, _{1}_m1.z, _{1}_m2.x, _{1}_m2.y, _{1}_m2.z);",
precision, GetVariableNameForNode());
visitor.AddShaderChunk(sb.ToString(), false);
// TODO - Remove Property entries everywhere?
// Matrix cant be a shader property
/*public override PropertyType propertyType
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
get { return PropertyType.Matrix2; }
}*/
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
/*public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}*/
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
/*public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
}*/
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m2", GetVariableNameForNode()),
vector4Value = m_Row2
});
}
/*public override PreviewProperty GetPreviewProperty()
public override string GetVariableNameForSlot(int slotId)
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector3 = m_Value
};
}*/
return GetVariableNameForNode();
}
}
}

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


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

const int kOutputSlotId = 0;
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]

if (value == row)
return;
row = value;
Dirty(ModificationScope.Graph);
Dirty(ModificationScope.Node);
}
public Matrix4Node()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
AddSlot(new Matrix4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
visitor.AddShaderChunk(precision + "4x4 " + GetVariableNameForNode() + " = " + 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);
}
if (!generationMode.IsPreview())
return;
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
[SerializeField]
string m_Description = string.Empty;
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
public string description
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m2", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row2
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m3", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row3
});
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
get
var sb = new ShaderStringBuilder();
if (!generationMode.IsPreview())
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
sb.AppendLine("{0}4 _{1}_m0 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y),
NodeUtils.FloatToShaderValue(m_Row0.z),
NodeUtils.FloatToShaderValue(m_Row0.w));
sb.AppendLine("{0}4 _{1}_m1 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y),
NodeUtils.FloatToShaderValue(m_Row1.z),
NodeUtils.FloatToShaderValue(m_Row1.w));
sb.AppendLine("{0}4 _{1}_m2 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row2.x),
NodeUtils.FloatToShaderValue(m_Row2.y),
NodeUtils.FloatToShaderValue(m_Row2.z),
NodeUtils.FloatToShaderValue(m_Row2.w));
sb.AppendLine("{0}4 _{1}_m3 = {0}4 ({2}, {3}, {4}, {5});", precision, GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row3.x),
NodeUtils.FloatToShaderValue(m_Row3.y),
NodeUtils.FloatToShaderValue(m_Row3.z),
NodeUtils.FloatToShaderValue(m_Row3.w));
set { m_Description = value; }
sb.AppendLine("{0}4x4 {1} = {0}4x4 (_{1}_m0.x, _{1}_m0.y, _{1}_m0.z, _{1}_m0.w, _{1}_m1.x, _{1}_m1.y, _{1}_m1.z, _{1}_m1.w, _{1}_m2.x, _{1}_m2.y, _{1}_m2.z, _{1}_m2.w, _{1}_m3.x, _{1}_m3.y, _{1}_m3.z, _{1}_m3.w);",
precision, GetVariableNameForNode());
visitor.AddShaderChunk(sb.ToString(), false);
// TODO - Remove Property entries everywhere?
// Matrix cant be a shader property
/*public override PropertyType propertyType
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
get { return PropertyType.Matrix2; }
}*/
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
/*public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}*/
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m2", GetVariableNameForNode()),
vector4Value = m_Row2
});
/*public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "2 " + propertyName + ";", true);
}*/
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m3", GetVariableNameForNode()),
vector4Value = m_Row3
});
}
/*public override PreviewProperty GetPreviewProperty()
public override string GetVariableNameForSlot(int slotId)
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector2,
m_Vector4 = m_Value
};
}*/
return GetVariableNameForNode();
}
}
}
正在加载...
取消
保存