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,10 @@
namespace UnityEditor.Rendering.UITK.ShaderGraph
{
/// <summary>
/// Sub-target used to filter UI-specific nodes
/// </summary>
public interface IUISubTarget
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 32198450093a7204c9552deba467bbf4
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9fbee1430c92c48f793957a37a515e30
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,120 @@
// UITK variant of the shared BuildVertexDescriptionInputs template, included explicitly by
// PassUI.template (mirrors how TerrainPass uses BuildTerrainVertexDescriptionInputs). The only
// difference from the shared copy is the world-space position: UITK vertices are element-local, so
// the world read must apply the per-element transform (translation -> bone -> group -> world) rather
// than the group-only TransformObjectToWorld(input.positionOS). Object space is already element-local.
// World position for a UITK element vertex: group * bone * (local + translation). In the ShaderGraph
// preview there is no ElementInfo record bound, so fall back to the plain object->world transform to
// avoid sampling unbound tables.
float3 uie_world_from_attributes(Attributes input)
{
#if defined(SHADERGRAPH_PREVIEW)
return TransformObjectToWorld(input.positionOS);
#else
appdata_t uieInput = (appdata_t)0;
uieInput.vertex = float4(input.positionOS, 1.0f);
uieInput.packedIds = input.uv4;
uint transformId, opacityId;
float2 translation;
uie_load_element_info(uieInput, transformId, opacityId, translation);
return TransformObjectToWorld(uie_local_to_world(uieInput.vertex, transformId, translation));
#endif
}
VertexDescriptionInputs BuildVertexDescriptionInputs(Attributes input)
{
VertexDescriptionInputs output;
ZERO_INITIALIZE(VertexDescriptionInputs, output);
// Texture UV (static field) so the Element Texture UV node works in the vertex stage. The
// fragment gets this from the uvClip varying that uie_std_vert writes; here we compute it
// directly from the vertex inputs, including the dynamic-texture texel-size scaling.
output.uvClip.xy = uie_element_texture_uv(input.uv0, input.uv4);
// Resolved tint (static field) so the Element Color node works in the vertex stage; the fragment
// reads the carried tint varying. Dead-code-eliminated when no node reads it.
output.color = uie_element_tint(input.color, input.uv4);
// Per-element opacity (static field) for the Element Color node's Opacity output in the vertex
// stage. Dead-code-eliminated when no node reads it.
output.opacity = uie_element_opacity(input.uv4);
// Layout-rect UV (static field) so the Element Layout UV node works in the vertex stage. It is
// packed into uv0.zw, the same source the fragment reads via the texCoord6 varying.
output.layoutUV = input.uv0.zw;
// Render type in typeTexSettings.x and texture slot in typeTexSettings.y (static field) so the
// Render Type and Element Texture Size nodes work in the vertex stage; they read IN.typeTexSettings.x
// and .y. The .z/.w components aren't read by any vertex node.
output.typeTexSettings.x = uie_element_frag_type(input.uv4);
output.typeTexSettings.y = uie_element_texture_slot(input.uv4);
$VertexDescriptionInputs.ObjectSpaceNormal: output.ObjectSpaceNormal = input.normalOS;
$VertexDescriptionInputs.WorldSpaceNormal: output.WorldSpaceNormal = TransformObjectToWorldNormal(input.normalOS);
$VertexDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = TransformWorldToViewDir(output.WorldSpaceNormal);
$VertexDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f);
$VertexDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = input.tangentOS.xyz;
$VertexDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = TransformObjectToWorldDir(input.tangentOS.xyz);
$VertexDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent);
$VertexDescriptionInputs.TangentSpaceTangent: output.TangentSpaceTangent = float3(1.0f, 0.0f, 0.0f);
$VertexDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = normalize(cross(input.normalOS, input.tangentOS.xyz) * (input.tangentOS.w > 0.0f ? 1.0f : -1.0f) * GetOddNegativeScale());
$VertexDescriptionInputs.WorldSpaceBiTangent: output.WorldSpaceBiTangent = TransformObjectToWorldDir(output.ObjectSpaceBiTangent);
$VertexDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$VertexDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f);
$VertexDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = input.positionOS;
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = uie_world_from_attributes(input);
$VertexDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(output.WorldSpacePosition);
$VertexDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f);
$VertexDescriptionInputs.AbsoluteWorldSpacePosition: output.AbsoluteWorldSpacePosition = GetAbsolutePositionWS(TransformObjectToWorld(input.positionOS));
$VertexDescriptionInputs.ObjectSpacePositionPredisplacement: output.ObjectSpacePositionPredisplacement = input.positionOS;
$VertexDescriptionInputs.WorldSpacePositionPredisplacement: output.WorldSpacePositionPredisplacement = uie_world_from_attributes(input);
$VertexDescriptionInputs.ViewSpacePositionPredisplacement: output.ViewSpacePositionPredisplacement = TransformWorldToView(output.WorldSpacePosition);
$VertexDescriptionInputs.TangentSpacePositionPredisplacement: output.TangentSpacePositionPredisplacement = float3(0.0f, 0.0f, 0.0f);
$VertexDescriptionInputs.AbsoluteWorldSpacePositionPredisplacement: output.AbsoluteWorldSpacePositionPredisplacement = GetAbsolutePositionWS(TransformObjectToWorld(input.positionOS));
$VertexDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = GetWorldSpaceNormalizeViewDir(output.WorldSpacePosition);
$VertexDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection);
$VertexDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection);
$VertexDescriptionInputs.TangentSpaceViewDirection: float3x3 tangentSpaceTransform = float3x3(output.WorldSpaceTangent,output.WorldSpaceBiTangent,output.WorldSpaceNormal);
$VertexDescriptionInputs.TangentSpaceViewDirection: output.TangentSpaceViewDirection = TransformWorldToTangent(output.WorldSpaceViewDirection, tangentSpaceTransform);
$VertexDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(output.WorldSpacePosition), _ProjectionParams.x);
$VertexDescriptionInputs.NDCPosition: output.NDCPosition = output.ScreenPosition.xy / output.ScreenPosition.w;
$VertexDescriptionInputs.PixelPosition: output.PixelPosition = float2(output.NDCPosition.x, 1.0f - output.NDCPosition.y) * GetScaledScreenParams().xy;
$VertexDescriptionInputs.ClipPosition: output.ClipPosition = TransformWorldToHClip(output.WorldSpacePosition).xy;
$VertexDescriptionInputs.uv0: output.uv0 = input.uv0;
$VertexDescriptionInputs.uv1: output.uv1 = input.uv1;
$VertexDescriptionInputs.uv2: output.uv2 = input.uv2;
$VertexDescriptionInputs.uv3: output.uv3 = input.uv3;
$VertexDescriptionInputs.uv4: output.uv4 = input.uv4;
$VertexDescriptionInputs.uv5: output.uv5 = input.uv5;
$VertexDescriptionInputs.uv6: output.uv6 = input.uv6;
$VertexDescriptionInputs.uv7: output.uv7 = input.uv7;
$VertexDescriptionInputs.VertexColor: output.VertexColor = input.color;
$VertexDescriptionInputs.TimeParameters: output.TimeParameters = _TimeParameters.xyz;
$VertexDescriptionInputs.BoneWeights: output.BoneWeights = input.weights;
$VertexDescriptionInputs.BoneIndices: output.BoneIndices = input.indices;
$VertexDescriptionInputs.VertexID: output.VertexID = input.vertexID;
#if UNITY_ANY_INSTANCING_ENABLED
$VertexDescriptionInputs.InstanceID: output.InstanceID = unity_InstanceID;
#else // TODO: XR support for procedural instancing because in this case UNITY_ANY_INSTANCING_ENABLED is not defined and instanceID is incorrect.
$VertexDescriptionInputs.InstanceID: output.InstanceID = input.instanceID;
#endif
return output;
}
// Runs the shader-graph vertex stage and returns the (possibly graph-modified) element-local
// position; custom interpolators are forwarded into the Varyings. uie_custom_vert writes the result
// into the vertex, then uie_std_vert applies the element transform (translation -> bone -> group ->
// clip). This is only included when FEATURES_GRAPH_VERTEX is set, so the caller guards on it too.
float3 uie_build_vertex(Attributes input, inout Varyings varyings)
{
VertexDescriptionInputs vertexDescriptionInputs = BuildVertexDescriptionInputs(input);
VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
#if defined(CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC)
CustomInterpolatorPassThroughFunc(varyings, vertexDescription);
#endif
return vertexDescription.Position;
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 95bb7cbbf6b9eaf408a1c4c3d0a8735c
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,129 @@
Pass
{
$splice(PassName)
Tags
{
$splice(LightMode)
}
// Render State
$splice(RenderState)
// Debug
$splice(Debug)
// --------------------------------------------------
// Pass
HLSLPROGRAM
// Pragmas
$splice(PassPragmas)
// Keywords
$splice(PassKeywords)
$splice(GraphKeywords)
#define UITK_SHADERGRAPH
// Defines
#define _SURFACE_TYPE_TRANSPARENT 1
$AlphaClip: #define _AlphaClip 1
$Normal: #define _NORMALMAP 1
$BlendMode.Add: #define _BLENDMODE_ADD 1
$BlendMode.Premultiply: #define _ALPHAPREMULTIPLY_ON 1
$Attributes.normalOS: #define ATTRIBUTES_NEED_NORMAL
$Attributes.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$Attributes.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
$Attributes.uv1: #define ATTRIBUTES_NEED_TEXCOORD1
$Attributes.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$Attributes.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$Attributes.uv4: #define ATTRIBUTES_NEED_TEXCOORD4
$Attributes.uv5: #define ATTRIBUTES_NEED_TEXCOORD5
$Attributes.color: #define ATTRIBUTES_NEED_COLOR
$Attributes.vertexID: #define ATTRIBUTES_NEED_VERTEXID
$Attributes.instanceID: #define ATTRIBUTES_NEED_INSTANCEID
$Varyings.positionWS: #define VARYINGS_NEED_POSITION_WS
$Varyings.positionPredisplacementWS: #define VARYINGS_NEED_POSITIONPREDISPLACEMENT_WS
$Varyings.normalWS: #define VARYINGS_NEED_NORMAL_WS
$Varyings.tangentWS: #define VARYINGS_NEED_TANGENT_WS
$Varyings.texCoord0: #define VARYINGS_NEED_TEXCOORD0
$Varyings.texCoord1: #define VARYINGS_NEED_TEXCOORD1
$Varyings.texCoord2: #define VARYINGS_NEED_TEXCOORD2
$Varyings.texCoord3: #define VARYINGS_NEED_TEXCOORD3
$Varyings.color: #define VARYINGS_NEED_COLOR
$Varyings.opacity: #define VARYINGS_NEED_OPACITY
$Varyings.vertexID: #define VARYINGS_NEED_VERTEXID
$Varyings.instanceID: #define VARYINGS_NEED_INSTANCEID
$Varyings.bitangentWS: #define VARYINGS_NEED_BITANGENT_WS
$Varyings.screenPosition: #define VARYINGS_NEED_SCREENPOSITION
$Varyings.fogFactorAndVertexLight: #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
$features.graphVertex: #define FEATURES_GRAPH_VERTEX
$features.graphColorInterp: #define FEATURES_GRAPH_COLOR_INTERP
$Universal.UseLegacySpriteBlocks: #define UNIVERSAL_USELEGACYSPRITEBLOCKS
#define REQUIRE_DEPTH_TEXTURE
#define REQUIRE_NORMAL_TEXTURE
$splice(GraphDefines)
$splice(PreGraphIncludes)
// --------------------------------------------------
// Structs and Packing
$splice(PassStructs)
$splice(InterpolatorPack)
// -- Property used by ScenePickingPass
#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif
// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif
//UGUI has no keyword for when a renderer has "bloom", so its nessecary to hardcore it here, like all the base UI shaders.
half4 _TextureSampleAdd;
// --------------------------------------------------
// Graph
// Graph Properties
$splice(GraphProperties)
// Graph Includes
$splice(GraphIncludes)
// Graph Functions
$splice(GraphFunctions)
$splice(CustomInterpolatorPreVertex)
// Graph Vertex
$splice(GraphVertex)
$splice(CustomInterpolatorPreSurface)
// Graph Pixel
$splice(GraphPixel)
// --------------------------------------------------
// Build Graph Inputs
$features.graphVertex: $include("BuildUIVertexDescriptionInputs.template.hlsl")
$features.graphPixel: $include("BuildSurfaceDescriptionInputs.template.hlsl")
// --------------------------------------------------
// Main
$splice(PostGraphIncludes)
ENDHLSL
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3b060531fe7ce41768321dd4c68d7f75
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using UnityEditor.ShaderGraph;
using UnityEngine;
using static UnityEditor.Rendering.BuiltIn.ShaderUtils;
using UnityEditor.Rendering.BuiltIn;
using System;
using UnityEditor.ShaderGraph.Serialization;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.UITK.ShaderGraph
{
internal class UIData : JsonObject
{
public enum Version
{
Initial,
}
[SerializeField] Version m_Version = Version.Initial;
public Version version
{
get => m_Version;
set => m_Version = value;
}
// When true (default), uie_custom_frag multiplies the final alpha by the per-element opacity.
// When false, the author applies opacity instead (e.g. via the Element Color node's Opacity output).
[SerializeField] bool m_AutomaticOpacity = true;
public bool automaticOpacity
{
get => m_AutomaticOpacity;
set => m_AutomaticOpacity = value;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4b189bed5251f48aba03003f19b692df
@@ -0,0 +1,153 @@
namespace UnityEditor.ShaderGraph
{
internal static class UIStructs
{
// Per-element opacity carried to the fragment (custom shaders only). The default shader bakes
// opacity into the color in uie_std_vert; the custom path keeps the tint straight and applies
// opacity at the end of the fragment, so it needs its own interpolant (packed by the packer).
internal static readonly FieldDescriptor OpacityVarying = new FieldDescriptor(
"Varyings", "opacity", "VARYINGS_NEED_OPACITY", ShaderValueType.Float,
subscriptOptions: StructFieldOptions.Optional);
public static StructDescriptor Varyings = new StructDescriptor()
{
name = "Varyings",
packFields = true,
populateWithCustomInterpolators = true,
fields = new[]
{
StructFields.Varyings.positionCS,
StructFields.Varyings.positionWS,
StructFields.Varyings.screenPosition,
StructFields.Varyings.texCoord0,
StructFields.Varyings.texCoord1,
StructFields.Varyings.texCoord2,
StructFields.Varyings.texCoord3,
StructFields.Varyings.texCoord4,
StructFields.Varyings.texCoord5,
StructFields.Varyings.texCoord6,
StructFields.Varyings.texCoord7,
StructFields.Varyings.color,
OpacityVarying,
StructFields.Varyings.instanceID,
StructFields.Varyings.vertexID,
StructFields.Varyings.stereoTargetEyeIndexAsBlendIdx0,
StructFields.Varyings.stereoTargetEyeIndexAsRTArrayIdx,
}
};
// Overrides the default Float4 uv4 with Uint4 because UIE packs integer IDs into TEXCOORD4.
internal static readonly FieldDescriptor PackedIdsAttribute = new FieldDescriptor(
"Attributes", "uv4", "ATTRIBUTES_NEED_TEXCOORD4", ShaderValueType.Uint4,
"TEXCOORD4", subscriptOptions: StructFieldOptions.Optional);
public static StructDescriptor Attributes = new StructDescriptor()
{
name = "Attributes",
packFields = false,
fields = new FieldDescriptor[]
{
StructFields.Attributes.positionOS,
StructFields.Attributes.color,
StructFields.Attributes.uv0, // .xy = uv, .zw = layoutUV
PackedIdsAttribute, // .x:[xform|clip] .y:[opacity|textcoreOrGrad] .z:[tex|flags] .w:reserved
StructFields.Attributes.uv5, // .xy outer | .zw inner | .x text-extra-dilate
StructFields.Attributes.uv1, // optional stream-1 ExtraVertexChannels.TexCoord1
StructFields.Attributes.uv2, // optional stream-1 ExtraVertexChannels.TexCoord2
StructFields.Attributes.uv3, // optional stream-1 ExtraVertexChannels.TexCoord3
StructFields.Attributes.normalOS, // optional stream-1 ExtraVertexChannels.Normal
StructFields.Attributes.tangentOS, // optional stream-1 ExtraVertexChannels.Tangent
StructFields.Attributes.instanceID,
StructFields.Attributes.vertexID,
}
};
public static StructDescriptor UITKVertexDescriptionInputs = new StructDescriptor()
{
name = "VertexDescriptionInputs",
packFields = false,
fields = new FieldDescriptor[]
{
//static required
new FieldDescriptor("VertexDescriptionInputs", "vertexPosition", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "vertexColor", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "uv", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "packedIds", "", ShaderValueType.Uint4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "circle", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
// Texture UV (dynamic-texture-patched), mirrors SurfaceDescriptionInputs.uvClip so the
// Element Texture UV node reads IN.uvClip.xy in the vertex stage as it does in fragment.
new FieldDescriptor("VertexDescriptionInputs", "uvClip", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
// Resolved tint (vertexColor * dynamicColor), mirrors SurfaceDescriptionInputs.color so the
// Element Color node reads IN.color in the vertex stage; the fragment uses the carried tint.
new FieldDescriptor("VertexDescriptionInputs", "color", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
// Per-element opacity, mirrors SurfaceDescriptionInputs.opacity so the Element Color node
// reads IN.opacity in the vertex stage.
new FieldDescriptor("VertexDescriptionInputs", "opacity", "", ShaderValueType.Float, subscriptOptions: StructFieldOptions.Static),
// Layout-rect UV, mirrors SurfaceDescriptionInputs.layoutUV so the Element Layout UV node
// reads IN.layoutUV.xy in the vertex stage as it does in fragment.
new FieldDescriptor("VertexDescriptionInputs", "layoutUV", "", ShaderValueType.Float2, subscriptOptions: StructFieldOptions.Static),
// Type/texture settings, mirrors SurfaceDescriptionInputs.typeTexSettings so the Render
// Type node reads IN.typeTexSettings.x (the render type) and the Element Texture Size node
// reads IN.typeTexSettings.y (the texture slot) in the vertex stage.
new FieldDescriptor("VertexDescriptionInputs", "typeTexSettings", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
// optionals
StructFields.VertexDescriptionInputs.VertexID,
StructFields.VertexDescriptionInputs.InstanceID,
// Element-local position read (PositionNode Object space) and the per-element world
// position (PositionNode World space, built in BuildUIVertexDescriptionInputs).
// ObjectSpacePosition is also the default of the always-active Position block.
StructFields.VertexDescriptionInputs.ObjectSpacePosition,
StructFields.VertexDescriptionInputs.WorldSpacePosition,
StructFields.VertexDescriptionInputs.ObjectSpaceNormal,
StructFields.VertexDescriptionInputs.ObjectSpaceTangent,
StructFields.VertexDescriptionInputs.uv0, // Element Texture UV node reads IN.uv0 in preview
StructFields.VertexDescriptionInputs.uv1,
StructFields.VertexDescriptionInputs.uv2,
StructFields.VertexDescriptionInputs.uv3,
StructFields.VertexDescriptionInputs.NDCPosition,
StructFields.VertexDescriptionInputs.PixelPosition,
StructFields.VertexDescriptionInputs.TimeParameters, // e.g. a Time-driven vertex Position offset
}
};
public static StructDescriptor UITKSurfaceDescriptionInputs = new StructDescriptor()
{
name = "SurfaceDescriptionInputs",
packFields = false,
populateWithCustomInterpolators = true,
fields = new FieldDescriptor[]
{
//static required
new FieldDescriptor("SurfaceDescriptionInputs", "color", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("SurfaceDescriptionInputs", "typeTexSettings", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("SurfaceDescriptionInputs", "textCoreLoc", "", ShaderValueType.Float2, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("SurfaceDescriptionInputs", "circle", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("SurfaceDescriptionInputs", "uvClip", "", ShaderValueType.Float4, subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("SurfaceDescriptionInputs", "layoutUV", "", ShaderValueType.Float2, subscriptOptions: StructFieldOptions.Static),
// Per-element opacity carried from the vertex; read by the Element Color node and applied
// at the end of uie_custom_frag (unless disabled).
new FieldDescriptor("SurfaceDescriptionInputs", "opacity", "", ShaderValueType.Float, subscriptOptions: StructFieldOptions.Static),
StructFields.SurfaceDescriptionInputs.uv0,
StructFields.SurfaceDescriptionInputs.uv1,
StructFields.SurfaceDescriptionInputs.uv2,
StructFields.SurfaceDescriptionInputs.uv3,
StructFields.SurfaceDescriptionInputs.uv4,
StructFields.SurfaceDescriptionInputs.uv5,
StructFields.SurfaceDescriptionInputs.uv6,
StructFields.SurfaceDescriptionInputs.uv7,
StructFields.SurfaceDescriptionInputs.WorldSpacePosition,
StructFields.SurfaceDescriptionInputs.ScreenPosition,
StructFields.SurfaceDescriptionInputs.NDCPosition,
StructFields.SurfaceDescriptionInputs.PixelPosition,
StructFields.SurfaceDescriptionInputs.TimeParameters,
}
};
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e6e2bf465150c49dcb38fd02cece3a88
@@ -0,0 +1,792 @@
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEngine.UIElements;
using UnityEditor.Rendering.BuiltIn.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Slots;
namespace UnityEditor.Rendering.UITK.ShaderGraph
{
[GenerateBlocks("UI")]
struct UITKBlocks
{
public static BlockFieldDescriptor coverage = new(BlockFields.SurfaceDescription.name, "Coverage", "Coverage",
"SURFACEDESCRIPTION_COVERAGE", new FloatControl(1), ShaderStage.Fragment, true);
}
internal abstract class UISubTarget<T> : SubTarget<T>, IUISubTarget, INodeValidationExtension, IRequiresData<UIData> where T : Target
{
const string kAssetGuid = "a5150c3db0b6942f6a0b1f7a9ce97d5c"; // UISubTarget.cs
#region Includes
static readonly string[] kSharedTemplateDirectories = GetUITKTemplateDirectories();
private static string[] GetUITKTemplateDirectories()
{
var shared = GenerationUtils.GetDefaultSharedTemplateDirectories();
var uitkTemplateDirectories = new string[shared.Length + 1];
uitkTemplateDirectories[shared.Length] = "Packages/com.unity.shadergraph/Editor/Generation/Targets/UITK/Templates";
for(int i = 0; i < shared.Length; ++i)
{
uitkTemplateDirectories[i] = shared[i];
}
return uitkTemplateDirectories;
}
//HLSL Includes
protected static readonly string kTemplatePath = "Packages/com.unity.shadergraph/Editor/Generation/Targets/UITK/Templates/PassUI.template";
protected static readonly string kCommon = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl";
protected static readonly string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl";
protected static readonly string kTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl";
protected static readonly string kInstancing = "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl";
protected static readonly string kPacking = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl";
protected static readonly string kSpaceTransforms = "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl";
protected static readonly string kFunctions = "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl";
protected static readonly string kTextureStack = "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl";
protected static readonly string kUIShim = "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/UIShim.hlsl";
#endregion
UIData m_UIData;
UIData IRequiresData<UIData>.data
{
get => m_UIData;
set => m_UIData = value;
}
public UIData uiData
{
get => m_UIData;
set => m_UIData = value;
}
protected bool TargetsVFX() => false;
protected virtual IncludeCollection pregraphIncludes => new IncludeCollection();
protected virtual IncludeCollection postgraphIncludes => new IncludeCollection();
protected abstract string pipelineTag { get; }
public virtual string identifier => GetType().Name;
public override bool IsActive() => true;
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(new GUID(kAssetGuid), AssetCollection.Flags.SourceDependency);
context.AddSubShader(GenerateDefaultSubshader());
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
// Position is always active so the graph vertex stage can read/write element-local
// position. An untouched block defaults to the object-space position, so the pass output
// is unchanged for graphs that don't drive Position.
context.AddBlock(BlockFields.VertexDescription.Position);
context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
}
public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode)
{
base.CollectShaderProperties(collector, generationMode);
CollectRenderStateShaderProperties(collector, generationMode);
}
public void CollectRenderStateShaderProperties(PropertyCollector collector, GenerationMode generationMode)
{
base.CollectShaderProperties(collector, generationMode);
}
public override void GetFields(ref TargetFieldContext context)
{
context.AddField(UnityEditor.ShaderGraph.Fields.GraphPixel);
}
public virtual SubShaderDescriptor GenerateDefaultSubshader(bool isSRP = true )
{
var result = new SubShaderDescriptor()
{
pipelineTag = pipelineTag,
renderQueue = "Transparent",
IgnoreProjector = "True",
renderType = "Transparent",
PreviewType = "Plane",
shaderFallback = "",
CanUseSpriteAtlas = "True",
generatesPreview = true,
customTags = "\"isCustomUITKShader\"=\"true\"",
passes = new PassCollection(),
};
result.passes.Add(GenerateUIPassDescriptor(isSRP));
result.passes.Add(GenerateSceneSelectionPassDescriptor(isSRP));
result.passes.Add(GenerateScenePickingPassDescriptor(isSRP));
return result;
}
public IncludeCollection AdditionalIncludesOnly()
{
return new IncludeCollection
{
{ pregraphIncludes },
{ postgraphIncludes },
};
}
public IncludeCollection SRPCoreIncludes()
{
return new IncludeCollection
{
// Pre-graph
SRPPreGraphIncludes(),
// Post-graph
SRPPostGraphIncludes(),
};
}
public virtual IncludeCollection SRPPreGraphIncludes()
{
return new IncludeCollection
{
{kCommon, IncludeLocation.Pregraph},
{kColor, IncludeLocation.Pregraph},
{kTexture, IncludeLocation.Pregraph},
{kTextureStack, IncludeLocation.Pregraph},
{ pregraphIncludes },
{kSpaceTransforms, IncludeLocation.Pregraph},
{kFunctions, IncludeLocation.Pregraph},
};
}
public virtual IncludeCollection SRPPostGraphIncludes()
{
return new IncludeCollection
{
{ postgraphIncludes },
};
}
static readonly KeywordDescriptor s_AutomaticOpacity = new KeywordDescriptor()
{
displayName = "Automatic Opacity",
referenceName = "UITK_AUTOMATIC_OPACITY",
type = KeywordType.Boolean,
};
protected virtual DefineCollection GetPassDefines()
{
var defines = new DefineCollection();
if (uiData == null || uiData.automaticOpacity)
defines.Add(s_AutomaticOpacity, 1);
return defines;
}
protected virtual KeywordCollection GetPassKeywords()
=> new KeywordCollection();
public virtual PassDescriptor GenerateUIPassDescriptor(bool isSRP)
{
var DefaultUITKPass = new PassDescriptor()
{
// Definition
displayName = "Default",
referenceName = "SHADERPASS_CUSTOM_UI",
useInPreview = true,
// Templates
passTemplatePath = kTemplatePath,
sharedTemplateDirectories = kSharedTemplateDirectories,
// Port Mask
validVertexBlocks = UITKBlockMasks.Vertex,
validPixelBlocks = UITKBlockMasks.Fragment,
// Collections
// Fields
structs = UITKStructCollections.Default,
requiredFields = UITKRequiredFields.Default,
fieldDependencies = FieldDependencies.Default,
//Conditional State
renderStates = UITKRenderStates.GenerateRenderStateDeclaration(),
pragmas = UITKPragmas.Default,
keywords = UITKKeywords.Default,
includes = AdditionalIncludesOnly(),
//definitions
defines = GetPassDefines(),
customInterpolators = UITKCustomInterpolators.Common,
};
return DefaultUITKPass;
}
// The Scene view selection outline and picking only position UITK's element-local vertices
// correctly when the material provides its own SceneSelectionPass/Picking pass; otherwise the
// editor falls back to a replacement material that skips the element transform and draws the
// geometry mispositioned (UUM-146911). These passes reuse the Default pass vertex path
// (uie_custom_vert, including the graph vertex stage). The selection pass mirrors
// Internal-UIRDefault.shader's SceneSelectionPass; that shader has no picking pass, so the
// picking pass follows URP's CorePasses.ScenePicking instead.
protected virtual PassDescriptor GenerateSceneSelectionPassDescriptor(bool isSRP)
{
var pass = GenerateUIPassDescriptor(isSRP);
pass.displayName = "SceneSelectionPass";
pass.lightMode = "SceneSelectionPass";
pass.useInPreview = false;
// Fixed states: URP overrides the Default pass blend per alphaMode, but the selection
// output (_ObjectId, _PassValue, 1, 1) must not depend on it. Alpha is 1, so the
// standard SrcAlpha OneMinusSrcAlpha blend overwrites the destination.
pass.renderStates = UITKRenderStates.GenerateRenderStateDeclaration();
pass.keywords = UITKKeywords.SelectionAndPicking;
pass.defines.Add(UITKKeywords.SceneSelectionPass, 1);
return pass;
}
protected virtual PassDescriptor GenerateScenePickingPassDescriptor(bool isSRP)
{
var pass = GenerateUIPassDescriptor(isSRP);
pass.displayName = "ScenePickingPass";
pass.lightMode = "Picking";
pass.useInPreview = false;
pass.renderStates = UITKRenderStates.GenerateScenePickingRenderStateDeclaration();
pass.keywords = UITKKeywords.SelectionAndPicking;
pass.defines.Add(UITKKeywords.ScenePickingPass, 1);
return pass;
}
// We don't need the save context / update materials for nows
public override object saveContext => null;
public UISubTarget()
{
displayName = "UI";
}
System.Collections.Generic.HashSet<Type> m_UnsupportedNodes;
public string GetValidatorKey()
{
return "UISubTarget";
}
const string kUVErrorMessageNode = "UI Material only supports UV0-UV3. To use UV1-3, enable the matching channel under PanelSettings.extraVertexChannels.";
const string kUVErrorMessageSubGraph = "UI Material only supports UV0-UV3 in the subgraph. To use UV1-3, enable the matching channel under PanelSettings.extraVertexChannels.";
const string kGeometryFragmentStageError = "{0} cannot be used in the fragment stage on UI Toolkit shaders. UI Toolkit does not provide a per-element transform that would make the value meaningful in the fragment shader. Route the value through a Custom Interpolator (vertex stage to fragment stage) to read the raw vertex data in the fragment shader.";
const string kGeometryNonObjectSpaceError = "{0}'s Space must be set to Object on UI Toolkit shaders. UI Toolkit does not provide a meaningful per-element world transform; other spaces would apply the batched-group transform and produce incorrect data. The Object space option returns the value as it was packed into the vertex stream.";
const string kPositionSpaceError = "{0}'s Space must be set to Object or World on UI Toolkit shaders. Object returns the element-local position; World applies the element transform (translation, bone and group). View, Tangent and Absolute World are not supported.";
const string kPositionObjectFragmentError = "{0} in Object space is the element-local position and is only available in the vertex stage on UI Toolkit shaders. Use World space to read the position in the fragment stage, or route the Object-space value through a Custom Interpolator (vertex stage to fragment stage).";
const string kSampleElementTextureVertexError = "{0} in Standard mip sampling mode samples with implicit derivatives, which the vertex stage does not provide. Set its Mip Sampling Mode to LOD to sample the element texture in the vertex stage.";
static bool IsAllowedUVChannel(UnityEditor.ShaderGraph.Internal.UVChannel channel)
{
return channel == UnityEditor.ShaderGraph.Internal.UVChannel.UV0
|| channel == UnityEditor.ShaderGraph.Internal.UVChannel.UV1
|| channel == UnityEditor.ShaderGraph.Internal.UVChannel.UV2
|| channel == UnityEditor.ShaderGraph.Internal.UVChannel.UV3;
}
public INodeValidationExtension.Status GetValidationStatus(AbstractMaterialNode node, out string msg)
{
if (node.owner == null)
{
msg = null;
return INodeValidationExtension.Status.None;
}
if (!IsIUISubTarget(node))
{
msg = null;
return INodeValidationExtension.Status.None;
}
if (!HasUVMaterialSlotOrIsUVNode(node))
{
msg = null;
return INodeValidationExtension.Status.None;
}
node.owner.messageManager.ClearNodesFromProvider(node.owner, new[] { node });
node.owner.messageManager.ClearNodesFromProvider(this, new[] { node });
foreach (var item in node.owner.activeTargets)
{
if (item.prefersUITKPreview)
{
if (ValidateUV(node, out msg))
{
return INodeValidationExtension.Status.Warning;
}
}
}
msg = null;
return INodeValidationExtension.Status.None;
}
static bool IsIUISubTarget(AbstractMaterialNode node)
{
bool isIUISubTarget = false;
foreach (var target in node.owner.activeTargets)
{
var subTarget = target.activeSubTarget;
if (subTarget is IUISubTarget)
{
isIUISubTarget = true;
break;
}
}
return isIUISubTarget;
}
static bool HasUVMaterialSlotOrIsUVNode(AbstractMaterialNode node)
{
List<UVMaterialSlot> uvSlots = new();
node.GetInputSlots<UVMaterialSlot>(uvSlots);
if (uvSlots.Count > 0)
{
return true;
}
UVNode uvNode = node as UVNode;
if (uvNode != null)
{
return true;
}
return false;
}
static bool ValidateUV(AbstractMaterialNode node, out string warningMessage)
{
if (!IsIUISubTarget(node))
{
warningMessage = null;
return false;
}
if (!HasUVMaterialSlotOrIsUVNode(node))
{
warningMessage = null;
return false;
}
List<UVMaterialSlot> uvSlots = new();
node.GetInputSlots<UVMaterialSlot>(uvSlots);
foreach (var uvSlot in uvSlots)
{
if (!IsAllowedUVChannel(uvSlot.channel))
{
warningMessage = kUVErrorMessageNode;
return true;
}
}
UVNode uvNode = node as UVNode;
if (uvNode != null)
{
if (!IsAllowedUVChannel(uvNode.uvChannel))
{
warningMessage = kUVErrorMessageNode;
return true;
}
}
warningMessage = null;
return false;
}
static bool ValidateGeometryNode(AbstractMaterialNode node, out string errorMessage)
{
errorMessage = null;
if (node is not GeometryNode geometryNode)
return false;
// Object (element-local) and World (group * bone * (local + translation)) are the only
// meaningful UITK position spaces; View/Tangent/AbsoluteWorld would apply an unrelated
// transform.
if (geometryNode is PositionNode)
{
if (geometryNode.space != CoordinateSpace.Object && geometryNode.space != CoordinateSpace.World)
{
errorMessage = string.Format(kPositionSpaceError, node.name);
return true;
}
// Object is element-local and only available in the vertex stage: the fragment can't
// recover it from the panel-root world varying (inverting UNITY_MATRIX_M only reaches
// group space). World rides the positionWS varying, so it works in both stages.
if (geometryNode.space == CoordinateSpace.Object)
{
var positionOutput = node.FindOutputSlot<MaterialSlot>(0);
if (positionOutput != null)
{
var positionCapability = NodeUtils.GetEffectiveShaderStageCapability(positionOutput, goingBackwards: false);
if (positionCapability != ShaderStageCapability.All && (positionCapability & ShaderStageCapability.Fragment) != 0)
{
errorMessage = string.Format(kPositionObjectFragmentError, node.name);
return true;
}
}
}
return false;
}
// ViewDirectionNode is blocked outright via m_UnsupportedNodes; only the three vector
// nodes reach this point on UITK.
if (geometryNode is not (NormalVectorNode or TangentVectorNode or BitangentVectorNode))
return false;
var outputSlot = node.FindOutputSlot<MaterialSlot>(0);
if (outputSlot == null)
return false;
var capability = NodeUtils.GetEffectiveShaderStageCapability(outputSlot, goingBackwards: false);
// capability == All means disconnected (no edges traversed); only flag actual fragment-stage paths.
if (capability != ShaderStageCapability.All && (capability & ShaderStageCapability.Fragment) != 0)
{
errorMessage = string.Format(kGeometryFragmentStageError, node.name);
return true;
}
if (geometryNode.space != CoordinateSpace.Object)
{
errorMessage = string.Format(kGeometryNonObjectSpaceError, node.name);
return true;
}
return false;
}
static bool ValidateSampleElementTextureNode(AbstractMaterialNode node, out string errorMessage)
{
errorMessage = null;
if (node is not SampleElementTextureNode sampleNode)
return false;
// LOD sampling takes an explicit mip and is valid in both stages; only Standard sampling
// (implicit derivatives) is fragment-only, so it's the only mode that needs flagging.
if (sampleNode.mipSamplingMode != ElementTextureMipSamplingMode.Standard)
return false;
var outputs = new List<MaterialSlot>();
node.GetOutputSlots(outputs);
foreach (var slot in outputs)
{
var capability = NodeUtils.GetEffectiveShaderStageCapability(slot, goingBackwards: false);
// capability == All means disconnected (no edges traversed); only flag actual vertex paths.
if (capability != ShaderStageCapability.All && (capability & ShaderStageCapability.Vertex) != 0)
{
errorMessage = string.Format(kSampleElementTextureVertexError, node.name);
return true;
}
}
return false;
}
static bool ValidateSubGraph(AbstractMaterialNode node, out string warningMessage)
{
warningMessage = null;
if (node is not SubGraphNode subGraphNode)
return false;
SubGraphAsset subGraphAsset = subGraphNode.asset;
if (subGraphAsset == null)
return false;
foreach (var item in subGraphAsset.requirements.requiresMeshUVs)
{
if (!IsAllowedUVChannel(item))
{
warningMessage = kUVErrorMessageSubGraph;
return true;
}
}
return false;
}
public override bool ValidateNodeCompatibility(AbstractMaterialNode node, out string warningMessage, out Rendering.ShaderCompilerMessageSeverity severity)
{
severity = ShaderCompilerMessageSeverity.Warning;
if (ValidateGeometryNode(node, out warningMessage))
{
severity = ShaderCompilerMessageSeverity.Error;
return true;
}
if (ValidateSampleElementTextureNode(node, out warningMessage))
{
severity = ShaderCompilerMessageSeverity.Error;
return true;
}
if (ValidateUV(node, out warningMessage))
return true;
if (ValidateSubGraph(node, out warningMessage))
return true;
warningMessage = null;
return false;
}
public override bool IsNodeAllowedBySubTarget(Type nodeType)
{
if (m_UnsupportedNodes == null)
{
m_UnsupportedNodes = new HashSet<Type>();
m_UnsupportedNodes.Add(typeof(BakedGINode));
m_UnsupportedNodes.Add(typeof(ParallaxMappingNode));
m_UnsupportedNodes.Add(typeof(ParallaxOcclusionMappingNode));
m_UnsupportedNodes.Add(typeof(TriplanarNode));
m_UnsupportedNodes.Add(typeof(IsFrontFaceNode));
// Nodes deriving from GeometryNode.
// Normal / Tangent / Bitangent are now allowed: the corresponding streams are
// opt-in via PanelSettings.extraVertexChannels (Normal, Tangent). When the
// matching channel isn't enabled the stream is zero, so the user is responsible
// for opting in to get meaningful values.
// Position is allowed too (Object = element-local, World = element transform); its
// spaces are validated in ValidateGeometryNode. ViewDirection stays blocked (no view).
m_UnsupportedNodes.Add(typeof(ViewDirectionNode));
// Vertex attribute related node which cannot be correctly handled in UITK.
m_UnsupportedNodes.Add(typeof(VertexIDNode));
m_UnsupportedNodes.Add(typeof(ComputeDeformNode));
m_UnsupportedNodes.Add(typeof(LinearBlendSkinningNode));
}
var interfaces = nodeType.GetInterfaces();
int numInterfaces = interfaces.Length;
// Subgraph nodes inherits all the interfaces including vertex ones.
if (m_UnsupportedNodes.Contains(nodeType))
return false;
if (nodeType == typeof(SubGraphNode))
return true;
for (int i = 0; i < numInterfaces; i++)
{
if (interfaces[i] == typeof(IMayRequireVertexSkinning)) return false;
}
return true;
}
}
#region PortMasks
class UITKBlockMasks
{
// Port Mask
public static BlockFieldDescriptor[] Vertex =
{
BlockFields.VertexDescription.Position,
};
public static BlockFieldDescriptor[] Fragment =
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.Alpha,
};
}
#endregion
#region StructCollections
static class UITKStructCollections
{
public static StructCollection Default = new StructCollection()
{
UIStructs.Attributes,
UIStructs.UITKSurfaceDescriptionInputs,
UIStructs.Varyings,
UIStructs.UITKVertexDescriptionInputs,
};
}
#endregion
#region RequiredFields
static class UITKRequiredFields
{
public static FieldCollection Default = new FieldCollection()
{
StructFields.Attributes.positionOS,
StructFields.Attributes.color,
StructFields.Attributes.uv0,
UIStructs.PackedIdsAttribute, // Uint4 instead of Float4
StructFields.Attributes.uv5,
StructFields.Varyings.positionCS,
StructFields.Varyings.color,
// UITK internals: texCoord4 = uvClip, texCoord5 = typeTexSettings, texCoord6 = textCoreLoc + layoutUV, texCoord7 = circle.
// texCoord0-3 are reserved for user UV0-UV3 (opt-in via PanelSettings.extraVertexChannels) and only pulled in on demand.
StructFields.Varyings.texCoord4,
StructFields.Varyings.texCoord5,
StructFields.Varyings.texCoord6,
StructFields.Varyings.texCoord7,
UIStructs.OpacityVarying, // per-element opacity, applied at the end of the fragment
// uie_custom_frag always computes AA coverage and rect clipping from these, so they must be
// copied into SurfaceDescriptionInputs even when no graph node reads them. Otherwise they stay
// zero (a constant-color graph loses arc carving and edge AA) — the requiresUITK ConditionalFields
// in GenerationUtils only populate them when an IMayRequireUITK node happens to be present.
StructFields.SurfaceDescriptionInputs.typeTexSettings,
StructFields.SurfaceDescriptionInputs.circle,
StructFields.SurfaceDescriptionInputs.uvClip,
};
}
#endregion
#region Keywords
static class UITKKeywords
{
public static KeywordDescriptor ForceGamma = new()
{
displayName = "Force Gamma",
referenceName = "",
type = KeywordType.Enum,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Local,
entries = new KeywordEntry[]
{
new(){ displayName = "Disabled", referenceName = "" },
new(){ displayName = "Enabled", referenceName = "UIE_FORCE_GAMMA" },
}
};
public static KeywordDescriptor ForceTextureSlotCount = new()
{
displayName = "Force Texture Slot Count",
referenceName = "",
type = KeywordType.Enum,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Local,
entries = new KeywordEntry[]
{
new(){ displayName = "8 Dynamic Texture Slots", referenceName = "" },
new(){ displayName = "4 Dynamic Texture Slots", referenceName = "UIE_TEXTURE_SLOT_COUNT_4" },
new(){ displayName = "2 Dynamic Texture Slots", referenceName = "UIE_TEXTURE_SLOT_COUNT_2" },
new(){ displayName = "No Dynamic Texture Slot", referenceName = "UIE_TEXTURE_SLOT_COUNT_1" },
}
};
public static KeywordDescriptor ForceRenderType = new()
{
displayName = "Force Render Type",
referenceName = "",
type = KeywordType.Enum,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Local,
entries = new KeywordEntry[]
{
new(){ displayName = "Any Render Type", referenceName = "" },
new(){ displayName = "Force Solid", referenceName = "UIE_RENDER_TYPE_SOLID" },
new(){ displayName = "Force Texture", referenceName = "UIE_RENDER_TYPE_TEXTURE" },
new(){ displayName = "Force Text", referenceName = "UIE_RENDER_TYPE_TEXT" },
new(){ displayName = "Force Gradient", referenceName = "UIE_RENDER_TYPE_GRADIENT" },
}
};
public static KeywordCollection Default = new()
{
ForceGamma,
ForceTextureSlotCount,
ForceRenderType,
};
public static KeywordDescriptor SceneSelectionPass = new()
{
displayName = "Scene Selection Pass",
referenceName = "SCENESELECTIONPASS",
type = KeywordType.Boolean,
};
public static KeywordDescriptor ScenePickingPass = new()
{
displayName = "Scene Picking Pass",
referenceName = "SCENEPICKINGPASS",
type = KeywordType.Boolean,
};
// ForceGamma is omitted: these passes only run for world-space panels, which never render
// with forced gamma (UIRRenderTreeManager only enables it when !drawInCameras). The keyword
// is therefore off in the Default pass too, so both passes evaluate the graph identically.
public static KeywordCollection SelectionAndPicking = new()
{
ForceTextureSlotCount,
ForceRenderType,
};
}
#endregion
#region RenderStates
static class UITKRenderStates
{
public static RenderStateCollection GenerateRenderStateDeclaration()
{
return new RenderStateCollection
{
{RenderState.Cull(Cull.Off)},
{RenderState.ZWrite(ZWrite.Off)},
{RenderState.Blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha)},
};
}
public static RenderStateCollection GenerateScenePickingRenderStateDeclaration()
{
return new RenderStateCollection
{
{RenderState.Cull(Cull.Off)},
// Picking reads back exact ids: ZWrite On resolves overlaps by depth, and
// Blend One Zero prevents blending from corrupting the id (_SelectionID.a is
// not 1). Mirrors URP's CorePasses.ScenePicking and the built-in particle
// shaders' ScenePickingPass (Internal-UIRDefault.shader has no picking pass).
{RenderState.ZWrite(ZWrite.On)},
{RenderState.Blend(Blend.One, Blend.Zero)},
};
}
}
#endregion
#region Pragmas
static class UITKPragmas
{
public static PragmaCollection Default = new PragmaCollection
{
{Pragma.Target(ShaderModel.Target35)},
{Pragma.Vertex("uie_custom_vert")},
{Pragma.Fragment("uie_custom_frag")},
};
}
#endregion
#region CustomInterpolators
static class UITKCustomInterpolators
{
// CopyToSDI: pass-through assignments that copy each custom interpolator from Varyings
// to SurfaceDescriptionInputs inside BuildSurfaceDescriptionInputs.
// PreSurface: defines CustomInterpolatorPassThroughFunc(Varyings, VertexDescription),
// which uie_custom_vert calls to copy custom interpolators from the vertex graph
// output into the Varyings before packing.
public static readonly CustomInterpSubGen.Collection Common = new CustomInterpSubGen.Collection
{
CustomInterpSubGen.Descriptor.MakeBlock(CustomInterpSubGen.Splice.k_spliceCopyToSDI, "output", "input"),
CustomInterpSubGen.Descriptor.MakeFunc(CustomInterpSubGen.Splice.k_splicePreSurface, "CustomInterpolatorPassThroughFunc", "Varyings", "VertexDescription", "CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC", "FEATURES_GRAPH_VERTEX"),
};
}
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a5150c3db0b6942f6a0b1f7a9ce97d5c