This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,66 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Default Bitmap Text")]
[SubTargetFilter(typeof(IUISubTarget))]
class DefaultBitmapTextNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public DefaultBitmapTextNode()
{
name = "Default Bitmap Text";
synonyms = null;
UpdateNodeAfterDeserialization();
}
const int k_InputSlotIdTint = 0;
const int k_OutputSlotId = 1;
const string k_InputSlotNameTint = "Tint";
const string k_OutputSlotName = "Bitmap Text";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdTint, k_InputSlotNameTint, k_InputSlotNameTint, "Default"));
AddSlot(new ColorRGBAMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.one, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_InputSlotIdTint, k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarName = GetVariableNameForSlot(k_OutputSlotId);
sb.AppendLine("float4 {0} = float4(1, 1, 1, 1);", outputVarName);
if (generationMode == GenerationMode.Preview)
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
if (hasTint)
sb.AppendLine("{0} = {1};", outputVarName, GetSlotValue(k_InputSlotIdTint, generationMode));
return;
}
sb.AppendLine("[branch] if ((_UIE_RENDER_TYPE_TEXT || _UIE_RENDER_TYPE_ANY) && round(IN.typeTexSettings.x) == k_FragTypeText && (!(GetTextureInfo(IN.typeTexSettings.y).sdfScale > 0.0)))");
using (sb.BlockScope())
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
sb.AppendLine("BitmapTextFragInput Unity_UIE_EvaluateBitmapNode_Input;");
// Straight tint; opacity is applied at the end of the fragment, so pass 1 here.
sb.AppendLine("Unity_UIE_EvaluateBitmapNode_Input.tint = {0};", hasTint ? GetSlotValue(k_InputSlotIdTint, generationMode) : "IN.color");
sb.AppendLine("Unity_UIE_EvaluateBitmapNode_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_EvaluateBitmapNode_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_EvaluateBitmapNode_Input.opacity = 1.0;");
sb.AppendLine("CommonFragOutput Unity_UIE_EvaluateBitmapNode_Output = uie_std_frag_bitmap_text(Unity_UIE_EvaluateBitmapNode_Input);");
sb.AppendLine("{0} = Unity_UIE_EvaluateBitmapNode_Output.color;", outputVarName);
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 006a87e9975ae6f40963c25f46922381
@@ -0,0 +1,57 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Default Gradient")]
[SubTargetFilter(typeof(IUISubTarget))]
class DefaultGradientNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public DefaultGradientNode()
{
name = "Default Gradient";
synonyms = null;
UpdateNodeAfterDeserialization();
}
const int k_OutputSlotId = 0;
const string k_OutputSlotName = "Gradient";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ColorRGBAMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.one, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarName = GetVariableNameForSlot(k_OutputSlotId);
sb.AppendLine("float4 {0} = float4(1, 1, 1, 1);", outputVarName);
if (generationMode == GenerationMode.Preview)
return;
sb.AppendLine("[branch] if (_UIE_RENDER_TYPE_GRADIENT || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeSvgGradient)");
using (sb.BlockScope())
{
sb.AppendLine("SvgGradientFragInput Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.settingIndex = round(IN.typeTexSettings.z);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.textureSlot = round(IN.typeTexSettings.y);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.isArc = false;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_svg_gradient(Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color * IN.color;", outputVarName);
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ca2aa3fbf13850248989af2d145fd0a6
@@ -0,0 +1,71 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Default SDF Text")]
[SubTargetFilter(typeof(IUISubTarget))]
class DefaultSDFTextNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public DefaultSDFTextNode()
{
name = "Default SDF Text";
synonyms = null;
UpdateNodeAfterDeserialization();
}
const int k_InputSlotIdTint = 0;
const int k_OutputSlotId = 1;
const string k_InputSlotNameTint = "Tint";
const string k_OutputSlotName = "SDF Text";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdTint, k_InputSlotNameTint, k_InputSlotNameTint, "Default"));
AddSlot(new ColorRGBAMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.one, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_InputSlotIdTint, k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarName = GetVariableNameForSlot(k_OutputSlotId);
sb.AppendLine("float4 {0} = float4(1, 1, 1, 1);", outputVarName);
if (generationMode == GenerationMode.Preview)
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
if (hasTint)
sb.AppendLine("{0} = {1};", outputVarName, GetSlotValue(k_InputSlotIdTint, generationMode));
return;
}
sb.AppendLine("[branch] if ((_UIE_RENDER_TYPE_TEXT || _UIE_RENDER_TYPE_ANY) && round(IN.typeTexSettings.x) == k_FragTypeText && (GetTextureInfo(IN.typeTexSettings.y).sdfScale > 0.0))");
using (sb.BlockScope())
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
sb.AppendLine("SdfTextFragInput Unity_UIE_EvaluateSdfTextNode_Input;");
// The tint is straight (not premultiplied); SDF text needs a premultiplied face color,
// a step that used to happen in the vertex. Opacity is applied at the end of the fragment.
sb.AppendLine("float4 Unity_UIE_EvaluateSdfTextNode_Tint = {0};", hasTint ? GetSlotValue(k_InputSlotIdTint, generationMode) : "IN.color");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Tint.rgb *= Unity_UIE_EvaluateSdfTextNode_Tint.a;");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.tint = Unity_UIE_EvaluateSdfTextNode_Tint;");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.extraDilate = IN.circle.x;");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.textCoreLoc = round(IN.textCoreLoc);");
sb.AppendLine("Unity_UIE_EvaluateSdfTextNode_Input.opacity = 1.0;");
sb.AppendLine("CommonFragOutput Unity_UIE_EvaluateSdfTextNode_Output = uie_std_frag_sdf_text(Unity_UIE_EvaluateSdfTextNode_Input);");
sb.AppendLine("{0} = Unity_UIE_EvaluateSdfTextNode_Output.color;", outputVarName);
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3552cc93742edec4196401f0c0ea5236
@@ -0,0 +1,55 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Default Solid")]
[SubTargetFilter(typeof(IUISubTarget))]
class DefaultSolidNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public DefaultSolidNode()
{
name = "Default Solid";
synonyms = null;
UpdateNodeAfterDeserialization();
}
const int k_OutputSlotId = 0;
const string k_OutputSlotName = "Solid";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ColorRGBAMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.one, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarName = GetVariableNameForSlot(k_OutputSlotId);
sb.AppendLine("float4 {0} = float4(1, 1, 1, 1);", outputVarName);
if (generationMode == GenerationMode.Preview)
return;
sb.AppendLine("[branch] if (_UIE_RENDER_TYPE_SOLID || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeSolid)");
using (sb.BlockScope())
{
sb.AppendLine("SolidFragInput Unity_UIE_EvaluateSolidNode_Input;");
sb.AppendLine("Unity_UIE_EvaluateSolidNode_Input.tint = IN.color;");
sb.AppendLine("Unity_UIE_EvaluateSolidNode_Input.isArc = false;");
sb.AppendLine("Unity_UIE_EvaluateSolidNode_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_EvaluateSolidNode_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_EvaluateSolidNode_Output = uie_std_frag_solid(Unity_UIE_EvaluateSolidNode_Input);");
sb.AppendLine("{0} = Unity_UIE_EvaluateSolidNode_Output.color;", outputVarName);
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ca8f1d7d5541490a942a6ff1ac54d223
@@ -0,0 +1,72 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Default Texture")]
[SubTargetFilter(typeof(IUISubTarget))]
class DefaultTextureNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public DefaultTextureNode()
{
name = "Default Texture";
synonyms = null;
UpdateNodeAfterDeserialization();
}
const int k_InputSlotIdUV = 0;
const int k_InputSlotIdTint = 1;
const int k_OutputSlotId = 2;
const string k_InputSlotNameUV = "UV";
const string k_InputSlotNameTint = "Tint";
const string k_OutputSlotName = "Texture";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DefaultVector2MaterialSlot(k_InputSlotIdUV, k_InputSlotNameUV, k_InputSlotNameUV));
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdTint, k_InputSlotNameTint, k_InputSlotNameTint, "Default"));
AddSlot(new ColorRGBAMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, Vector4.one, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_InputSlotIdUV, k_InputSlotIdTint, k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarName = GetVariableNameForSlot(k_OutputSlotId);
sb.AppendLine("float4 {0} = float4(1, 1, 1, 1);", outputVarName);
if (generationMode == GenerationMode.Preview)
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
if (hasTint)
sb.AppendLine("{0} = {1};", outputVarName, GetSlotValue(k_InputSlotIdTint, generationMode));
return;
}
sb.AppendLine("[branch] if (_UIE_RENDER_TYPE_TEXTURE || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeTexture)");
using (sb.BlockScope())
{
bool hasTint = GetInputNodeFromSlot(k_InputSlotIdTint) != null;
bool hasUV = GetInputNodeFromSlot(k_InputSlotIdUV) != null;
sb.AppendLine("TextureFragInput Unity_UIE_EvaluateTextureNode_Input;");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.tint = {0};", hasTint ? GetSlotValue(k_InputSlotIdTint, generationMode) : "IN.color");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.uv = {0};", hasUV ? GetSlotValue(k_InputSlotIdUV, generationMode) : "IN.uvClip.xy");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.isArc = false;");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_EvaluateTextureNode_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_EvaluateTextureNode_Output = uie_std_frag_texture(Unity_UIE_EvaluateTextureNode_Input);");
sb.AppendLine("{0} = Unity_UIE_EvaluateTextureNode_Output.color;", outputVarName);
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 558a60e942a60164d8f8570adf26a57a
@@ -0,0 +1,44 @@
using UnityEditor.Graphing;
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Is Forced Gamma")]
[SubTargetFilter(typeof(IUISubTarget))]
class IsForcedGammaNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
const int k_OutputSlotId = 0;
const string k_OutputSlotName = "Out";
public IsForcedGammaNode()
{
name = "Is Forced Gamma";
synonyms = new string[] { };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new BooleanMaterialSlot(k_OutputSlotId, k_OutputSlotName, k_OutputSlotName, SlotType.Output, true));
RemoveSlotsNameNotMatching(new[] { k_OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode == GenerationMode.Preview)
{
// In preview mode, return false by default
sb.AppendLine("bool {0} = false;", GetVariableNameForSlot(k_OutputSlotId));
return;
}
sb.AppendLine("bool {0} = _UIE_FORCE_GAMMA;", GetVariableNameForSlot(k_OutputSlotId));
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1b7813ff9ac575f4d993f1b44f854eab
@@ -0,0 +1,188 @@
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
using SlotType = UnityEditor.Graphing.SlotType;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Render Type Branch")]
[SubTargetFilter(typeof(IUISubTarget))]
class RenderTypeBranchNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
public RenderTypeBranchNode()
{
name = "Render Type Branch";
synonyms = new [] { "toggle", "uber" };
UpdateNodeAfterDeserialization();
}
const int k_InputSlotIdSolid = 0;
const int k_InputSlotIdTexture = 1;
const int k_InputSlotIdSdfText = 2;
const int k_InputSlotIdBitmapText = 3;
const int k_InputSlotIdGradient = 4;
const int k_OutputSlotIdColor = 5;
const int k_OutputSlotIdAlpha = 6;
const string k_InputSlotNameSolid = "Solid";
const string k_InputSlotNameTexture = "Texture";
const string k_InputSlotNameSdfText = "SDF Text";
const string k_InputSlotNameBitmapText = "Bitmap Text";
const string k_InputSlotNameGradient = "Gradient";
const string k_ColorOutputSlotName = "Color";
const string k_AlphaOutputSlotName = "Alpha";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdSolid, k_InputSlotNameSolid, k_InputSlotNameSolid));
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdTexture, k_InputSlotNameTexture, k_InputSlotNameTexture));
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdSdfText, k_InputSlotNameSdfText, k_InputSlotNameSdfText));
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdBitmapText, k_InputSlotNameBitmapText, k_InputSlotNameBitmapText));
AddSlot(new DefaultVector4MaterialSlot(k_InputSlotIdGradient, k_InputSlotNameGradient, k_InputSlotNameGradient));
AddSlot(new ColorRGBMaterialSlot(k_OutputSlotIdColor, k_ColorOutputSlotName, k_ColorOutputSlotName, SlotType.Output, Color.white, Internal.ColorMode.Default, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(k_OutputSlotIdAlpha, k_AlphaOutputSlotName, k_AlphaOutputSlotName, SlotType.Output, 1.0f, ShaderStageCapability.Fragment));
RemoveSlotsNameNotMatching(new[] { k_InputSlotIdSolid, k_InputSlotIdTexture, k_InputSlotIdSdfText, k_InputSlotIdBitmapText, k_InputSlotIdGradient, k_OutputSlotIdColor, k_OutputSlotIdAlpha });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string outputVarNameColor = GetVariableNameForSlot(k_OutputSlotIdColor);
string outputVarNameAlpha = GetVariableNameForSlot(k_OutputSlotIdAlpha);
sb.AppendLine("float3 {0} = float3(1, 1, 1);", outputVarNameColor);
sb.AppendLine("float {0} = 1.0;", outputVarNameAlpha);
if (generationMode == GenerationMode.Preview)
{
// In preview mode the UITK render-type macros don't exist.
// Output the Solid input if connected.
if (GetInputNodeFromSlot(k_InputSlotIdSolid) != null)
{
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdSolid, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdSolid, generationMode));
}
return;
}
sb.AppendLine("[branch] if (_UIE_RENDER_TYPE_SOLID || _UIE_RENDER_TYPE_ANY && TestType(IN.typeTexSettings.x, k_FragTypeSolid))");
using (sb.BlockScope())
{
if (GetInputNodeFromSlot(k_InputSlotIdSolid) != null)
{
// TODO: We are not switching the computation, only the result. This is a performance problem. Same story for the other render types.
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdSolid, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdSolid, generationMode));
}
else
{
sb.AppendLine("SolidFragInput Unity_UIE_RenderTypeSwitchNode_Solid_Input;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Solid_Input.tint = IN.color;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Solid_Input.isArc = false;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Solid_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Solid_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_solid(Unity_UIE_RenderTypeSwitchNode_Solid_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.rgb;", outputVarNameColor);
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.a;", outputVarNameAlpha);
}
}
sb.AppendLine("else [branch] if (_UIE_RENDER_TYPE_TEXTURE || _UIE_RENDER_TYPE_ANY && TestType(IN.typeTexSettings.x, k_FragTypeTexture))");
using (sb.BlockScope())
{
if (GetInputNodeFromSlot(k_InputSlotIdTexture) != null)
{
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdTexture, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdTexture, generationMode));
}
else
{
sb.AppendLine("TextureFragInput Unity_UIE_RenderTypeSwitchNode_Texture_Input;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.tint = IN.color;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.isArc = false;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_Texture_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_texture(Unity_UIE_RenderTypeSwitchNode_Texture_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.rgb;", outputVarNameColor);
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.a;", outputVarNameAlpha);
}
}
sb.AppendLine("else [branch] if (_UIE_RENDER_TYPE_TEXT || _UIE_RENDER_TYPE_ANY && TestType(IN.typeTexSettings.x, k_FragTypeText))");
using (sb.BlockScope())
{
sb.AppendLine("[branch] if (GetTextureInfo(IN.typeTexSettings.y).sdfScale > 0.0)");
using (sb.BlockScope())
{
if (GetInputNodeFromSlot(k_InputSlotIdSdfText) != null)
{
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdSdfText, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdSdfText, generationMode));
}
else
{
sb.AppendLine("SdfTextFragInput Unity_UIE_RenderTypeSwitchNode_SdfText_Input;");
// Straight tint -> premultiplied face color (moved out of the vertex); opacity at frag-end.
sb.AppendLine("float4 Unity_UIE_RenderTypeSwitchNode_SdfText_Tint = IN.color;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Tint.rgb *= Unity_UIE_RenderTypeSwitchNode_SdfText_Tint.a;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.tint = Unity_UIE_RenderTypeSwitchNode_SdfText_Tint;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.extraDilate = IN.circle.x;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.textCoreLoc = round(IN.textCoreLoc);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SdfText_Input.opacity = 1.0;");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_sdf_text(Unity_UIE_RenderTypeSwitchNode_SdfText_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.rgb;", outputVarNameColor);
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.a;", outputVarNameAlpha);
}
}
sb.AppendLine("else");
using (sb.BlockScope())
{
if (GetInputNodeFromSlot(k_InputSlotIdBitmapText) != null)
{
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdBitmapText, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdBitmapText, generationMode));
}
else
{
sb.AppendLine("BitmapTextFragInput Unity_UIE_RenderTypeSwitchNode_BitmapText_Input;");
// Straight tint; opacity is applied at the end of the fragment, so pass 1 here.
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_BitmapText_Input.tint = IN.color;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_BitmapText_Input.textureSlot = IN.typeTexSettings.y;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_BitmapText_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_BitmapText_Input.opacity = 1.0;");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_bitmap_text(Unity_UIE_RenderTypeSwitchNode_BitmapText_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.rgb;", outputVarNameColor);
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.a;", outputVarNameAlpha);
}
}
}
sb.AppendLine("else"); // k_FragTypeSvgGradient
using (sb.BlockScope())
{
if (GetInputNodeFromSlot(k_InputSlotIdGradient) != null)
{
sb.AppendLine("{0} = {1}.rgb;", outputVarNameColor, GetSlotValue(k_InputSlotIdGradient, generationMode));
sb.AppendLine("{0} = {1}.a;", outputVarNameAlpha, GetSlotValue(k_InputSlotIdGradient, generationMode));
}
else
{
sb.AppendLine("SvgGradientFragInput Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.settingIndex = round(IN.typeTexSettings.z);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.textureSlot = round(IN.typeTexSettings.y);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.uv = IN.uvClip.xy;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.isArc = false;");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.outer = float2(-10000, -10000);");
sb.AppendLine("Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input.inner = float2(-10000, -10000);");
sb.AppendLine("CommonFragOutput Unity_UIE_RenderTypeSwitchNode_Output = uie_std_frag_svg_gradient(Unity_UIE_RenderTypeSwitchNode_SvgGradient_Input);");
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.rgb * IN.color.rgb;", outputVarNameColor);
sb.AppendLine("{0} = Unity_UIE_RenderTypeSwitchNode_Output.color.a * IN.color.a;", outputVarNameAlpha);
}
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d76d31d3abf64e1085969d0a4ccca4c5
timeCreated: 1752518750
@@ -0,0 +1,66 @@
using UnityEditor.Graphing;
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("UI", "Render Type")]
[SubTargetFilter(typeof(IUISubTarget))]
class RenderTypeNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
{
const int k_OutputSlotIdSolid = 0;
const int k_OutputSlotIdTexture = 1;
const int k_OutputSlotIdSDFText = 2;
const int k_OutputSlotIdBitmapText = 3;
const int k_OutputSlotIdGradient = 4;
const string k_OutputSlotNameSolid = "Solid";
const string k_OutputSlotNameTexture = "Texture";
const string k_OutputSlotNameSDFText = "SDF Text";
const string k_OutputSlotNameBitmapText = "Bitmap Text";
const string k_OutputSlotNameGradient = "Gradient";
public RenderTypeNode()
{
name = "Render Type";
synonyms = new string[] { };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new BooleanMaterialSlot(k_OutputSlotIdSolid, k_OutputSlotNameSolid, k_OutputSlotNameSolid, SlotType.Output, true));
AddSlot(new BooleanMaterialSlot(k_OutputSlotIdTexture, k_OutputSlotNameTexture, k_OutputSlotNameTexture, SlotType.Output, false));
AddSlot(new BooleanMaterialSlot(k_OutputSlotIdSDFText, k_OutputSlotNameSDFText, k_OutputSlotNameSDFText, SlotType.Output, false));
AddSlot(new BooleanMaterialSlot(k_OutputSlotIdBitmapText, k_OutputSlotNameBitmapText, k_OutputSlotNameBitmapText, SlotType.Output, false));
AddSlot(new BooleanMaterialSlot(k_OutputSlotIdGradient, k_OutputSlotNameGradient, k_OutputSlotNameGradient, SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { k_OutputSlotIdSolid, k_OutputSlotIdTexture, k_OutputSlotIdSDFText, k_OutputSlotIdBitmapText, k_OutputSlotIdGradient });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode == GenerationMode.Preview)
{
// In preview mode the UITK render-type macros don't exist.
// Default to Solid render type.
sb.AppendLine("bool {0} = true;", GetVariableNameForSlot(k_OutputSlotIdSolid));
sb.AppendLine("bool {0} = false;", GetVariableNameForSlot(k_OutputSlotIdTexture));
sb.AppendLine("bool {0} = false;", GetVariableNameForSlot(k_OutputSlotIdSDFText));
sb.AppendLine("bool {0} = false;", GetVariableNameForSlot(k_OutputSlotIdBitmapText));
sb.AppendLine("bool {0} = false;", GetVariableNameForSlot(k_OutputSlotIdGradient));
return;
}
sb.AppendLine("bool {0} = _UIE_RENDER_TYPE_SOLID || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeSolid;", GetVariableNameForSlot(k_OutputSlotIdSolid));
sb.AppendLine("bool {0} = _UIE_RENDER_TYPE_TEXTURE || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeTexture;", GetVariableNameForSlot(k_OutputSlotIdTexture));
sb.AppendLine("bool {0} = (_UIE_RENDER_TYPE_TEXT || _UIE_RENDER_TYPE_ANY) && round(IN.typeTexSettings.x) == k_FragTypeText && (GetTextureInfo(IN.typeTexSettings.y).sdfScale > 0.0);", GetVariableNameForSlot(k_OutputSlotIdSDFText));
sb.AppendLine("bool {0} = (_UIE_RENDER_TYPE_TEXT || _UIE_RENDER_TYPE_ANY) && round(IN.typeTexSettings.x) == k_FragTypeText && (!(GetTextureInfo(IN.typeTexSettings.y).sdfScale > 0.0));", GetVariableNameForSlot(k_OutputSlotIdBitmapText));
sb.AppendLine("bool {0} = _UIE_RENDER_TYPE_GRADIENT || _UIE_RENDER_TYPE_ANY && round(IN.typeTexSettings.x) == k_FragTypeSvgGradient;", GetVariableNameForSlot(k_OutputSlotIdGradient));
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 829e23fe5395446c81c68d0a333437d2
timeCreated: 1752521117
@@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.Rendering.UITK.ShaderGraph;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
enum ElementTextureMipSamplingMode
{
Standard,
LOD
}
[Title("UI", "Sample Element Texture")]
[SubTargetFilter(typeof(IUISubTarget))]
class SampleElementTextureNode : AbstractMaterialNode, IGeneratesFunction, IGeneratesBodyCode, IMayRequireUITK
{
const int kMinSampleCount = 1;
const int kMaxSampleCount = 32;
// Fixed-id inputs that don't scale with the sample count.
public const int LODInputId = 4;
public const int SamplerInputId = 5;
const string kLODSlotName = "LOD";
const string kSamplerSlotName = "Sampler";
// The first 4 UV/Color slots keep their original ids so graphs authored before the count became
// configurable (which always had 4 samples) keep their connections; extra slots use disjoint ranges.
static int UVSlotId(int i) => i < 4 ? i : 1000 + i;
static int ColorSlotId(int i) => i < 4 ? 10 + i : 2000 + i;
public override bool hasPreview { get { return false; } }
public SampleElementTextureNode()
{
name = "Sample Element Texture";
synonyms = new string[] { };
UpdateNodeAfterDeserialization();
}
[SerializeField]
private int m_SampleCount = 4;
internal int sampleCount
{
get { return Mathf.Clamp(m_SampleCount, kMinSampleCount, kMaxSampleCount); }
set
{
int clamped = Mathf.Clamp(value, kMinSampleCount, kMaxSampleCount);
if (m_SampleCount == clamped)
return;
m_SampleCount = clamped;
UpdateNodeAfterDeserialization();
}
}
[SerializeField]
private ElementTextureMipSamplingMode m_MipSamplingMode = ElementTextureMipSamplingMode.Standard;
internal ElementTextureMipSamplingMode mipSamplingMode
{
set { m_MipSamplingMode = value; UpdateNodeAfterDeserialization(); }
get { return m_MipSamplingMode; }
}
public override void UpdateNodeAfterDeserialization()
{
int count = sampleCount;
var ids = new List<int>();
for (int i = 0; i < count; i++)
{
AddSlot(new Vector2MaterialSlot(UVSlotId(i), $"UV {i}", $"UV {i}", SlotType.Input, Vector2.zero));
ids.Add(UVSlotId(i));
}
// Optional sampler override. When left unconnected the node, element texture's own sampler is used.
AddSlot(new SamplerStateMaterialSlot(SamplerInputId, kSamplerSlotName, kSamplerSlotName, SlotType.Input));
ids.Add(SamplerInputId);
bool lod = m_MipSamplingMode == ElementTextureMipSamplingMode.LOD;
if (lod)
{
AddSlot(new Vector1MaterialSlot(LODInputId, kLODSlotName, kLODSlotName, SlotType.Input, 0.0f));
ids.Add(LODInputId);
}
for (int i = 0; i < count; i++)
{
AddSlot(new Vector4MaterialSlot(ColorSlotId(i), $"Color {i}", $"Color {i}", SlotType.Output, Vector4.zero));
ids.Add(ColorSlotId(i));
}
// Lowering the count legitimately drops slots; suppress the "Removing Invalid MaterialSlot" warning.
RemoveSlotsNameNotMatching(ids, supressWarnings: true);
SetSlotOrder(ids);
}
// Per-sample expression used inside the dispatch macro. _Texture##index resolves to the element
// texture slot picked by UIE_BRANCH; s/lod reference the function parameters when present.
static string SampleExpression(int i, bool lod, bool hasSampler)
{
if (hasSampler)
return lod
? $"SAMPLE_TEXTURE2D_LOD(_Texture##index, s, uv{i}, lod)"
: $"SAMPLE_TEXTURE2D(_Texture##index, s, uv{i})";
return lod
? $"UNITY_SAMPLE_TEX2D_LOD(_Texture##index, uv{i}, lod)"
: $"UNITY_SAMPLE_TEX2D(_Texture##index, uv{i})";
}
// Name encodes the count and the sampling variant so graphs mixing configurations don't collide on
// a single macro/function definition.
static string FunctionName(int count, bool lod, bool hasSampler)
=> $"Unity_UIE_SampleElementTexture_{count}{(lod ? "_LOD" : "")}{(hasSampler ? "_S" : "")}";
static string MacroName(int count, bool lod, bool hasSampler)
=> $"UIE_SAMPLE_{count}{(lod ? "_LOD" : "")}{(hasSampler ? "_S" : "")}";
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
int count = sampleCount;
bool lod = m_MipSamplingMode == ElementTextureMipSamplingMode.LOD;
bool hasSampler = IsSlotConnected(SamplerInputId);
string fn = FunctionName(count, lod, hasSampler);
string macro = MacroName(count, lod, hasSampler);
registry.ProvideFunction(fn, sb =>
{
sb.AppendLine($"#define {macro}(index) \\");
for (int i = 0; i < count; i++)
{
string cont = (i < count - 1) ? " \\" : "";
sb.AppendLine($" c{i} = {SampleExpression(i, lod, hasSampler)};{cont}");
}
sb.AppendLine("");
var prms = new List<string> { "half index" };
for (int i = 0; i < count; i++)
prms.Add($"float2 uv{i}");
if (hasSampler)
prms.Add("SamplerState s");
if (lod)
prms.Add("float lod");
for (int i = 0; i < count; i++)
prms.Add($"out float4 c{i}");
sb.AppendLine($"void {fn}({string.Join(", ", prms)})");
using (sb.BlockScope())
{
sb.AppendLine($"UIE_BRANCH({macro})");
}
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
int count = sampleCount;
if (generationMode == GenerationMode.Preview)
{
// In preview mode, return white
for (int i = 0; i < count; i++)
sb.AppendLine("$precision4 {0} = $precision4(1, 1, 1, 1);", GetVariableNameForSlot(ColorSlotId(i)));
return;
}
for (int i = 0; i < count; i++)
sb.AppendLine("$precision4 {0};", GetVariableNameForSlot(ColorSlotId(i)));
bool lod = m_MipSamplingMode == ElementTextureMipSamplingMode.LOD;
bool hasSampler = IsSlotConnected(SamplerInputId);
using (sb.BlockScope())
{
sb.AppendLine("half Unity_UIE_TextureSlotIndex = IN.typeTexSettings.y;");
var args = new List<string> { "Unity_UIE_TextureSlotIndex" };
for (int i = 0; i < count; i++)
args.Add(GetSlotValue(UVSlotId(i), generationMode));
if (hasSampler)
args.Add($"{GetSlotValue(SamplerInputId, generationMode)}.samplerstate");
if (lod)
args.Add(GetSlotValue(LODInputId, generationMode));
for (int i = 0; i < count; i++)
args.Add(GetVariableNameForSlot(ColorSlotId(i)));
sb.AppendLine($"{FunctionName(count, lod, hasSampler)}({string.Join(", ", args)});");
sb.AppendLine("#if _UIE_FORCE_GAMMA");
for (int i = 0; i < count; i++)
{
string c = GetVariableNameForSlot(ColorSlotId(i));
sb.AppendLine("{0}.rgb = uie_linear_to_gamma({1}.rgb);", c, c);
}
sb.AppendLine("#endif");
}
}
public bool RequiresUITK(ShaderStageCapability stageCapability)
{
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 765e7483c0e20b7458fe66a1716a37a8