Matt Dean
7 年前
当前提交
41740d78
共有 12 个文件被更改,包括 799 次插入 和 23 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
-
27MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PreviewProperty.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
515MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/MultiplyNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
99MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
-
7MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta
-
139MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicValueMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicValueMaterialSlot.cs.meta
99
MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 3128537d5706b43ad99fd9cd6b5c7edf |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class DynamicValueMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4> |
|||
{ |
|||
[SerializeField] |
|||
private Matrix4x4 m_Value; |
|||
|
|||
[SerializeField] |
|||
private Matrix4x4 m_DefaultValue; |
|||
|
|||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4; |
|||
|
|||
public DynamicValueMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public DynamicValueMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
Matrix4x4 value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_Value = value; |
|||
} |
|||
|
|||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public Matrix4x4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set { m_Value = value; } |
|||
} |
|||
|
|||
public override VisualElement InstantiateControl() |
|||
{ |
|||
int components = |
|||
concreteValueType == ConcreteSlotValueType.Vector4 ? 4 : |
|||
concreteValueType == ConcreteSlotValueType.Vector3 ? 3 : |
|||
concreteValueType == ConcreteSlotValueType.Vector2 ? 2 : |
|||
concreteValueType == ConcreteSlotValueType.Vector1 ? 1 : 0; |
|||
|
|||
return new MultiFloatSlotControlView(owner, components, () => value.GetRow(0), (newValue) => value = new Matrix4x4(newValue, value.GetRow(1), value.GetRow(2), value.GetRow(3))); |
|||
} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Dynamic; } } |
|||
|
|||
public override ConcreteSlotValueType concreteValueType |
|||
{ |
|||
get { return m_ConcreteValueType; } |
|||
} |
|||
|
|||
public void SetConcreteType(ConcreteSlotValueType valueType) |
|||
{ |
|||
m_ConcreteValueType = valueType; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var propType = ConvertConcreteSlotValueTypeToPropertyType(concreteValueType); |
|||
var pp = new PreviewProperty(propType) { name = name }; |
|||
if (propType == PropertyType.Vector1) |
|||
pp.floatValue = value.m00; |
|||
else |
|||
pp.vector4Value = new Vector4(value.m00, value.m01, value.m02, value.m03); |
|||
return pp; |
|||
} |
|||
|
|||
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) |
|||
{ |
|||
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType); |
|||
string values = NodeUtils.FloatToShaderValue(value.m00); |
|||
if (channelCount == 1) |
|||
return values; |
|||
for (var i = 1; i < channelCount; i++) |
|||
values += ", " + value.GetRow(0)[i]; |
|||
return string.Format("{0}{1}({2})", precision, channelCount, values); |
|||
} |
|||
|
|||
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))); |
|||
|
|||
IShaderProperty property; |
|||
switch (concreteValueType) |
|||
{ |
|||
case ConcreteSlotValueType.Vector4: |
|||
property = new Vector4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector3: |
|||
property = new Vector3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector2: |
|||
property = new Vector2ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector1: |
|||
property = new Vector1ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix4: |
|||
property = new Matrix4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix3: |
|||
property = new Matrix3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Matrix2: |
|||
property = new Matrix2ShaderProperty(); |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
property.generatePropertyBlock = false; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as DynamicValueMaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 38b2d4645340d4274a793e2e12ec097c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue