您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
177 行
6.4 KiB
177 行
6.4 KiB
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
using UnityEditor.ShaderGraph.Internal;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Serializable]
|
|
[Title("Master", "Unlit")]
|
|
class UnlitMasterNode : MasterNode<IUnlitSubShader>, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent
|
|
{
|
|
public const string ColorSlotName = "Color";
|
|
public const string AlphaSlotName = "Alpha";
|
|
public const string AlphaClipThresholdSlotName = "AlphaClipThreshold";
|
|
public const string PositionName = "Vertex Position";
|
|
public const string NormalName = "Vertex Normal";
|
|
public const string TangentName = "Vertex Tangent";
|
|
|
|
public const int ColorSlotId = 0;
|
|
public const int AlphaSlotId = 7;
|
|
public const int AlphaThresholdSlotId = 8;
|
|
public const int PositionSlotId = 9;
|
|
public const int VertNormalSlotId = 10;
|
|
public const int VertTangentSlotId = 11;
|
|
|
|
[SerializeField]
|
|
SurfaceType m_SurfaceType;
|
|
|
|
public SurfaceType surfaceType
|
|
{
|
|
get { return m_SurfaceType; }
|
|
set
|
|
{
|
|
if (m_SurfaceType == value)
|
|
return;
|
|
|
|
m_SurfaceType = value;
|
|
Dirty(ModificationScope.Graph);
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
AlphaMode m_AlphaMode;
|
|
|
|
public AlphaMode alphaMode
|
|
{
|
|
get { return m_AlphaMode; }
|
|
set
|
|
{
|
|
if (m_AlphaMode == value)
|
|
return;
|
|
|
|
m_AlphaMode = value;
|
|
Dirty(ModificationScope.Graph);
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
bool m_TwoSided;
|
|
|
|
public ToggleData twoSided
|
|
{
|
|
get { return new ToggleData(m_TwoSided); }
|
|
set
|
|
{
|
|
if (m_TwoSided == value.isOn)
|
|
return;
|
|
m_TwoSided = value.isOn;
|
|
Dirty(ModificationScope.Graph);
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
bool m_AddPrecomputedVelocity = false;
|
|
|
|
public ToggleData addPrecomputedVelocity
|
|
{
|
|
get { return new ToggleData(m_AddPrecomputedVelocity); }
|
|
set
|
|
{
|
|
if (m_AddPrecomputedVelocity == value.isOn)
|
|
return;
|
|
m_AddPrecomputedVelocity = value.isOn;
|
|
Dirty(ModificationScope.Graph);
|
|
}
|
|
}
|
|
|
|
public UnlitMasterNode()
|
|
{
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
base.UpdateNodeAfterDeserialization();
|
|
name = "Unlit Master";
|
|
AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
|
AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
|
AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
|
AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment));
|
|
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment));
|
|
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment));
|
|
|
|
// clear out slot names that do not match the slots
|
|
// we support
|
|
RemoveSlotsNameNotMatching(
|
|
new[]
|
|
{
|
|
PositionSlotId,
|
|
VertNormalSlotId,
|
|
VertTangentSlotId,
|
|
ColorSlotId,
|
|
AlphaSlotId,
|
|
AlphaThresholdSlotId
|
|
});
|
|
}
|
|
|
|
protected override VisualElement CreateCommonSettingsElement()
|
|
{
|
|
return new UnlitSettingsView(this);
|
|
}
|
|
|
|
public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
|
|
{
|
|
List<MaterialSlot> slots = new List<MaterialSlot>();
|
|
GetSlots(slots);
|
|
|
|
List<MaterialSlot> validSlots = new List<MaterialSlot>();
|
|
for (int i = 0; i < slots.Count; i++)
|
|
{
|
|
if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
|
|
continue;
|
|
|
|
validSlots.Add(slots[i]);
|
|
}
|
|
return validSlots.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability));
|
|
}
|
|
|
|
public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability)
|
|
{
|
|
List<MaterialSlot> slots = new List<MaterialSlot>();
|
|
GetSlots(slots);
|
|
|
|
List<MaterialSlot> validSlots = new List<MaterialSlot>();
|
|
for (int i = 0; i < slots.Count; i++)
|
|
{
|
|
if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
|
|
continue;
|
|
|
|
validSlots.Add(slots[i]);
|
|
}
|
|
return validSlots.OfType<IMayRequirePosition>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability));
|
|
}
|
|
|
|
public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability)
|
|
{
|
|
List<MaterialSlot> slots = new List<MaterialSlot>();
|
|
GetSlots(slots);
|
|
|
|
List<MaterialSlot> validSlots = new List<MaterialSlot>();
|
|
for (int i = 0; i < slots.Count; i++)
|
|
{
|
|
if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
|
|
continue;
|
|
|
|
validSlots.Add(slots[i]);
|
|
}
|
|
return validSlots.OfType<IMayRequireTangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability));
|
|
}
|
|
}
|
|
}
|