您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
64 行
2.0 KiB
64 行
2.0 KiB
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Title("Input", "Geometry", "Screen Position")]
|
|
public class ScreenPositionNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireScreenPosition
|
|
{
|
|
public ScreenPositionNode()
|
|
{
|
|
name = "Screen Position";
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
public override string documentationURL
|
|
{
|
|
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Screen-Position-Node"; }
|
|
}
|
|
|
|
[SerializeField]
|
|
private ScreenSpaceType m_ScreenSpaceType = ScreenSpaceType.Default;
|
|
|
|
[EnumControl("Mode")]
|
|
public ScreenSpaceType screenSpaceType
|
|
{
|
|
get { return m_ScreenSpaceType; }
|
|
set
|
|
{
|
|
if (m_ScreenSpaceType == value)
|
|
return;
|
|
|
|
m_ScreenSpaceType = value;
|
|
Dirty(ModificationScope.Graph);
|
|
}
|
|
}
|
|
|
|
private const int kOutputSlotId = 0;
|
|
private const string kOutputSlotName = "Out";
|
|
|
|
public override bool hasPreview { get { return true; } }
|
|
public override PreviewMode previewMode
|
|
{
|
|
get { return PreviewMode.Preview2D; }
|
|
}
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
|
|
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
|
|
}
|
|
|
|
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
|
|
{
|
|
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId), m_ScreenSpaceType.ToValueAsVariable()), true);
|
|
}
|
|
|
|
public bool RequiresScreenPosition(ShaderStageCapability stageCapability)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|