您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
90 行
2.9 KiB
90 行
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing.Slots;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.UIElements;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Serializable]
|
|
public class Matrix4MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
|
|
{
|
|
[SerializeField]
|
|
private Matrix4x4 m_Value = Matrix4x4.identity;
|
|
|
|
[SerializeField]
|
|
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
|
|
|
|
public Matrix4MaterialSlot()
|
|
{
|
|
}
|
|
|
|
public Matrix4MaterialSlot(
|
|
int slotId,
|
|
string displayName,
|
|
string shaderOutputName,
|
|
SlotType slotType,
|
|
ShaderStage shaderStage = ShaderStage.Dynamic,
|
|
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; } }
|
|
|
|
public Matrix4x4 value
|
|
{
|
|
get { return m_Value; }
|
|
set { m_Value = value; }
|
|
}
|
|
|
|
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
|
|
{
|
|
return precision + "4x4 (1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)";
|
|
}
|
|
|
|
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
|
{
|
|
if (!generationMode.IsPreview())
|
|
return;
|
|
|
|
var matOwner = owner as AbstractMaterialNode;
|
|
if (matOwner == null)
|
|
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
|
|
|
|
var property = new Matrix4ShaderProperty()
|
|
{
|
|
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
|
generatePropertyBlock = false,
|
|
value = value
|
|
};
|
|
properties.AddShaderProperty(property);
|
|
}
|
|
|
|
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
|
{
|
|
var pp = new PreviewProperty(PropertyType.Matrix4)
|
|
{
|
|
name = name,
|
|
vector4Value = new Vector4(value.GetRow(0).x, value.GetRow(0).y, value.GetRow(0).z, value.GetRow(0).w),
|
|
};
|
|
properties.Add(pp);
|
|
}
|
|
|
|
public override SlotValueType valueType { get { return SlotValueType.Matrix4; } }
|
|
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix4; } }
|
|
|
|
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
|
{
|
|
var slot = foundSlot as Matrix4MaterialSlot;
|
|
if (slot != null)
|
|
value = slot.value;
|
|
}
|
|
}
|
|
}
|