您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
104 行
4.2 KiB
104 行
4.2 KiB
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEditor.ShaderGraph;
|
|
using UnityEditor.ShaderGraph.Internal;
|
|
|
|
namespace UnityEditor.Experimental.Rendering.Universal
|
|
{
|
|
[Serializable]
|
|
[Title("Master", "Sprite Unlit (Experimental)")]
|
|
[FormerName("UnityEditor.Experimental.Rendering.LWRP.SpriteUnlitMasterNode")]
|
|
class SpriteUnlitMasterNode : MasterNode<ISpriteUnlitSubShader>, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent
|
|
{
|
|
public const string PositionName = "Vertex Position";
|
|
public const string NormalName = "Vertex Normal";
|
|
public const string TangentName = "Vertex Tangent";
|
|
public const string ColorSlotName = "Color";
|
|
|
|
|
|
public const int PositionSlotId = 9;
|
|
public const int ColorSlotId = 0;
|
|
public const int VertNormalSlotId = 10;
|
|
public const int VertTangentSlotId = 11;
|
|
|
|
public SpriteUnlitMasterNode()
|
|
{
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
base.UpdateNodeAfterDeserialization();
|
|
name = "Sprite 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 ColorRGBAMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.white, ShaderStageCapability.Fragment));
|
|
|
|
RemoveSlotsNameNotMatching(
|
|
new[]
|
|
{
|
|
PositionSlotId,
|
|
VertNormalSlotId,
|
|
VertTangentSlotId,
|
|
ColorSlotId,
|
|
});
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|