You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.1 KiB
64 lines
2.1 KiB
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Title("Input", "Geometry", "Screen Position")]
|
|
class ScreenPositionNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireScreenPosition, IMayRequireNDCPosition, IMayRequirePixelPosition
|
|
{
|
|
public ScreenPositionNode()
|
|
{
|
|
name = "Screen Position";
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
[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 sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
|
|
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
|
|
}
|
|
|
|
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
|
|
{
|
|
sb.AppendLine(string.Format("$precision4 {0} = {1};", GetVariableNameForSlot(kOutputSlotId), m_ScreenSpaceType.ToValueAsVariable()));
|
|
}
|
|
|
|
bool IMayRequireScreenPosition.RequiresScreenPosition(ShaderStageCapability stageCapability)
|
|
{
|
|
return screenSpaceType.RequiresScreenPosition();
|
|
}
|
|
|
|
bool IMayRequireNDCPosition.RequiresNDCPosition(ShaderStageCapability stageCapability)
|
|
{
|
|
return screenSpaceType.RequiresNDCPosition();
|
|
}
|
|
|
|
bool IMayRequirePixelPosition.RequiresPixelPosition(ShaderStageCapability stageCapability)
|
|
{
|
|
return screenSpaceType.RequiresPixelPosition();
|
|
}
|
|
}
|
|
}
|