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,3 @@
fileFormatVersion: 2
guid: 094f15b4a6654154bb5755294694cb46
timeCreated: 1682462567
@@ -0,0 +1,26 @@
using System;
using UnityEditor.ShaderGraph;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.BuiltIn.ShaderGraph
{
static class CreateCanvasShadergraph
{
[MenuItem("Assets/Create/Shader Graph/BuiltIn/Canvas Shader Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority + 2)]
public static void CreateUnlitGraph()
{
var target = (BuiltInTarget)Activator.CreateInstance(typeof(BuiltInTarget));
target.TrySetActiveSubTarget(typeof(BuiltInCanvasSubTarget));
var blockDescriptors = new[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.Emission,
BlockFields.SurfaceDescription.Alpha,
BlockFields.SurfaceDescription.AlphaClipThreshold,
};
GraphUtil.CreateNewGraphWithOutputs(new[] { target }, blockDescriptors);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77f0b7eb337d453f907ab78780c7372e
timeCreated: 1682462586
@@ -0,0 +1,41 @@
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.Canvas.ShaderGraph
{
internal class CanvasData : JsonObject
{
public enum Version
{
Initial,
}
[SerializeField] Version m_Version = Version.Initial;
public Version version
{
get => m_Version;
set => m_Version = value;
}
[SerializeField]
bool m_AlphaClip = false;
public bool alphaClip
{
get => m_AlphaClip;
set => m_AlphaClip = value;
}
[SerializeField]
bool m_DisableTint = false;
public bool disableTint
{
get => m_DisableTint;
set => m_DisableTint = value;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 470e3787e0cd4e3f8dba9518074b91da
timeCreated: 1670294928
@@ -0,0 +1,12 @@
using System;
using UnityEngine;
using UnityEditor.Rendering.BuiltIn;
namespace UnityEditor.Rendering.Canvas.ShaderGraph
{
[Serializable]
public class CanvasMetaData : ScriptableObject
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: da16dde8cdd249ec84572d6ca66d29e6
timeCreated: 1670297192
@@ -0,0 +1,128 @@
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
static class CanvasProperties
{
public static readonly Vector1ShaderProperty StencilComp = new Vector1ShaderProperty()
{
overrideReferenceName = "_StencilComp",
displayName = "Stencil Comparison",
floatType = FloatType.Default,
hidden = true,
value = 8,
generatePropertyBlock = true,
overrideHLSLDeclaration = true,
hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
};
public static readonly Vector1ShaderProperty Stencil = new Vector1ShaderProperty()
{
overrideReferenceName = "_Stencil",
displayName = "Stencil ID",
floatType = FloatType.Default,
hidden = true,
value = 0,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty StencilOp = new Vector1ShaderProperty()
{
overrideReferenceName = "_StencilOp",
displayName = "Stencil Operation",
floatType = FloatType.Default,
hidden = true,
value = 0,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty StencilWriteMask = new Vector1ShaderProperty()
{
overrideReferenceName = "_StencilWriteMask",
displayName = "Stencil Write Mask",
floatType = FloatType.Default,
hidden = true,
value = 255,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty StencilReadMask = new Vector1ShaderProperty()
{
overrideReferenceName = "_StencilReadMask",
displayName = "Stencil Read Mask",
floatType = FloatType.Default,
hidden = true,
value = 255,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty ColorMask = new Vector1ShaderProperty()
{
overrideReferenceName = "_ColorMask",
displayName = "ColorMask",
floatType = FloatType.Default,
hidden = true,
value = 15,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty UIMaskSoftnessX = new Vector1ShaderProperty()
{
overrideReferenceName = "_UIMaskSoftnessX",
displayName = "UIMaskSoftnessX",
floatType = FloatType.Default,
hidden = true,
value = 1.0f,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty UIMaskSoftnessY = new Vector1ShaderProperty()
{
overrideReferenceName = "_UIMaskSoftnessY",
displayName = "UIMaskSoftnessY",
floatType = FloatType.Default,
hidden = true,
value = 1.0f,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector4ShaderProperty ClipRect = new Vector4ShaderProperty()
{
overrideReferenceName = "_ClipRect",
displayName = "ClipRect",
hidden = true,
generatePropertyBlock = true,
overrideHLSLDeclaration = false,
};
public static readonly Vector1ShaderProperty AlphaTest = new Vector1ShaderProperty()
{
floatType = FloatType.Default,
hidden = true,
overrideHLSLDeclaration = true,
value = 0.5f,
hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
displayName = "_AlphaClip",
overrideReferenceName = "_AlphaClip",
};
public static readonly Texture2DShaderProperty MainTex = new Texture2DShaderProperty()
{
overrideReferenceName = "_MainTex",
displayName = "MainTex",
generatePropertyBlock = true,
defaultType = Texture2DShaderProperty.DefaultType.White,
value = new SerializableTexture(),
hidden = true,
overrideHLSLDeclaration = false,
};
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 56ecc48707f64a748df0de0d71df4039
timeCreated: 1657595328
@@ -0,0 +1,119 @@
namespace UnityEditor.ShaderGraph
{
internal static class CanvasStructs
{
public static StructDescriptor Varyings = new StructDescriptor()
{
name = "Varyings",
packFields = true,
populateWithCustomInterpolators = false,
fields = new[]
{
StructFields.Varyings.positionCS,
StructFields.Varyings.positionWS,
StructFields.Varyings.positionPredisplacementWS,
StructFields.Varyings.normalWS,
StructFields.Varyings.tangentWS,
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,
StructFields.Varyings.instanceID,
StructFields.Varyings.vertexID,
StructFields.Varyings.stereoTargetEyeIndexAsBlendIdx0,
StructFields.Varyings.stereoTargetEyeIndexAsRTArrayIdx,
}
};
public static StructDescriptor Attributes = new StructDescriptor()
{
name = "Attributes",
packFields = false,
fields = new FieldDescriptor[]
{
StructFields.Attributes.positionOS,
StructFields.Attributes.tangentOS,
StructFields.Attributes.normalOS,
StructFields.Attributes.color,
StructFields.Attributes.uv0,
StructFields.Attributes.uv1,
StructFields.Attributes.uv2,
StructFields.Attributes.uv3,
StructFields.Attributes.uv4,
StructFields.Attributes.uv5,
StructFields.Attributes.uv6,
StructFields.Attributes.uv7,
StructFields.Attributes.instanceID,
StructFields.Attributes.vertexID,
}
};
//todo: Delete
public static StructDescriptor CanvasVertexDescriptionInputs = new StructDescriptor()
{
name = "VertexDescriptionInputs",
packFields = false,
fields = new FieldDescriptor[]
{
//static required
new FieldDescriptor("VertexDescriptionInputs", "ObjectSpacePosition", "", ShaderValueType.Float3,
subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "VertexColor", "", ShaderValueType.Float4,
subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "uv0", "", ShaderValueType.Float4,
subscriptOptions: StructFieldOptions.Static),
new FieldDescriptor("VertexDescriptionInputs", "uv1", "", ShaderValueType.Float4,
subscriptOptions: StructFieldOptions.Static),
//optionals
StructFields.VertexDescriptionInputs.ObjectSpaceNormal,
StructFields.VertexDescriptionInputs.NDCPosition,
StructFields.VertexDescriptionInputs.PixelPosition,
StructFields.VertexDescriptionInputs.uv2,
StructFields.VertexDescriptionInputs.uv3,
StructFields.VertexDescriptionInputs.uv4,
StructFields.VertexDescriptionInputs.uv5,
StructFields.VertexDescriptionInputs.uv6,
StructFields.VertexDescriptionInputs.uv7,
StructFields.VertexDescriptionInputs.TimeParameters,
StructFields.VertexDescriptionInputs.VertexID,
StructFields.VertexDescriptionInputs.InstanceID,
}
};
public static StructDescriptor CanvasSurfaceDescriptionInputs = new StructDescriptor()
{
name = "SurfaceDescriptionInputs",
packFields = false,
populateWithCustomInterpolators = true,
fields = new FieldDescriptor[]
{
StructFields.SurfaceDescriptionInputs.ScreenPosition,
StructFields.SurfaceDescriptionInputs.NDCPosition,
StructFields.SurfaceDescriptionInputs.PixelPosition,
StructFields.SurfaceDescriptionInputs.ObjectSpacePosition,
StructFields.SurfaceDescriptionInputs.ViewSpacePosition,
StructFields.SurfaceDescriptionInputs.WorldSpacePosition,
StructFields.SurfaceDescriptionInputs.TangentSpacePosition,
StructFields.SurfaceDescriptionInputs.AbsoluteWorldSpacePosition,
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.VertexColor,
StructFields.SurfaceDescriptionInputs.TimeParameters,
}
};
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b68a530597ac466094e3c7d015e0ed47
timeCreated: 1669249457
@@ -0,0 +1,448 @@
using UnityEditor.ShaderGraph;
using UnityEngine;
using System;
using UnityEngine.UIElements;
using UnityEditor.Rendering.BuiltIn.ShaderGraph;
namespace UnityEditor.Rendering.Canvas.ShaderGraph
{
#region CanvasUniforms
internal static class CanvasUniforms
{
// Uniforms
public static readonly string Lighting = "Off";
public static string ColorMask = "ColorMask [_ColorMask]";
public static string ZTest = "[unity_GUIZTestMode]";
//stencil Props
public static string Ref = "[_Stencil]";
public static string Comp = "[_StencilComp]";
public static string Pass = "[_StencilOp]";
public static string ReadMask = "[_StencilReadMask]";
public static string WriteMask = "[_StencilWriteMask]";
}
#endregion
internal abstract class CanvasSubTarget<T> : SubTarget<T>, IRequiresData<CanvasData>, IHasMetadata where T : Target
{
const string kAssetGuid = "3ab5e3f315cd4041b2aa8600df09dd3e"; // CanvasSubTarget.cs
#region Includes
static readonly string[] kSharedTemplateDirectories = GetCanvasTemplateDirectories();
private static string[] GetCanvasTemplateDirectories()
{
var shared = GenerationUtils.GetDefaultSharedTemplateDirectories();
var canvasTemplateDirectories = new string[shared.Length + 1];
canvasTemplateDirectories[shared.Length] = "Packages/com.unity.shadergraph/Editor/Generation/Targets/Canvas/Templates";
for(int i = 0; i < shared.Length; ++i)
{
canvasTemplateDirectories[i] = shared[i];
}
return canvasTemplateDirectories;
}
//HLSL Includes
protected static readonly string kTemplatePath = "Packages/com.unity.shadergraph/Editor/Generation/Targets/Canvas/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";
#endregion
CanvasData m_CanvasData;
CanvasData IRequiresData<CanvasData>.data
{
get => m_CanvasData;
set => m_CanvasData = value;
}
public CanvasData canvasData
{
get => m_CanvasData;
set => m_CanvasData = value;
}
protected bool TargetsVFX() => false;
protected virtual IncludeCollection pregraphIncludes => new IncludeCollection();
protected virtual IncludeCollection postgraphIncludes => new IncludeCollection();
protected virtual KeywordCollection GetAdditionalKeywords() => new KeywordCollection();
protected abstract string pipelineTag { get; }
protected virtual Type GetDefaultShaderGUI() => typeof(CanvasShaderGUI);
public virtual string identifier => GetType().Name;
public virtual ScriptableObject GetMetadataObject(GraphDataReadOnly graph)
{
var canvasMetadata = ScriptableObject.CreateInstance<CanvasMetaData>();
return canvasMetadata;
}
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)
{
//Core Fragment Blocks
context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
context.AddBlock(BlockFields.SurfaceDescription.Emission);
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);
collector.AddShaderProperty(CanvasProperties.MainTex);
collector.AddShaderProperty(CanvasProperties.StencilComp);
collector.AddShaderProperty(CanvasProperties.Stencil);
collector.AddShaderProperty(CanvasProperties.StencilOp);
collector.AddShaderProperty(CanvasProperties.StencilWriteMask);
collector.AddShaderProperty(CanvasProperties.StencilReadMask);
collector.AddShaderProperty(CanvasProperties.ColorMask);
collector.AddShaderProperty(CanvasProperties.ClipRect);
collector.AddShaderProperty(CanvasProperties.UIMaskSoftnessX);
collector.AddShaderProperty(CanvasProperties.UIMaskSoftnessY);
}
public override void GetFields(ref TargetFieldContext context)
{
context.AddField(UnityEditor.ShaderGraph.Fields.GraphPixel);
}
protected virtual DefineCollection GetAdditionalDefines()
{
var result = new DefineCollection();
if (canvasData.disableTint)
result.Add(CanvasKeywords.DisableTint, 1);
return result;
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<string> registerUndo)
{
context.AddProperty("Alpha Clipping", new Toggle() { value = canvasData.alphaClip }, (evt) =>
{
if (Equals(canvasData.alphaClip, evt.newValue))
return;
registerUndo("Alpha Clip");
canvasData.alphaClip = evt.newValue;
onChange();
});
context.AddProperty("Disable Color Tint", new Toggle() { value = canvasData.disableTint }, (evt) =>
{
if (Equals(canvasData.disableTint, evt.newValue))
return;
registerUndo("Disable Tint");
canvasData.disableTint = evt.newValue;
onChange();
});
}
public virtual SubShaderDescriptor GenerateDefaultSubshader(bool isSRP = true )
{
var result = new SubShaderDescriptor()
{
pipelineTag = pipelineTag,
renderQueue = "Transparent",
IgnoreProjector = "True",
renderType = "Transparent",
PreviewType = "Plane",
CanUseSpriteAtlas = "True",
generatesPreview = true,
passes = new PassCollection(),
};
result.passes.Add(GenerateUIPassDescriptor(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 },
};
}
protected virtual DefineCollection GetPassDefines()
=> new DefineCollection();
protected virtual KeywordCollection GetPassKeywords()
=> new KeywordCollection();
public virtual PassDescriptor GenerateUIPassDescriptor(bool isSRP)
{
var DefaultCanvasPass = new PassDescriptor()
{
// Definition
displayName = "Default",
referenceName = "SHADERPASS_CUSTOM_UI",
useInPreview = true,
// Templates
passTemplatePath = kTemplatePath,
sharedTemplateDirectories = kSharedTemplateDirectories,
// Port Mask
validVertexBlocks = CanvasBlockMasks.Vertex,
validPixelBlocks = CanvasBlockMasks.Fragment,
// Collections
// Fields
structs = CanvasStructCollections.Default,
requiredFields = CanvasRequiredFields.Default,
fieldDependencies = FieldDependencies.Default,
//Conditional State
renderStates = CanvasRenderStates.GenerateRenderStateDeclaration(),
pragmas = CanvasPragmas.Default,
includes = isSRP ? SRPCoreIncludes() : AdditionalIncludesOnly(),
//definitions
defines = GetPassDefines(),
keywords = CanvasKeywords.GenerateCoreKeywords(),
};
DefaultCanvasPass.defines.Add(GetAdditionalDefines());
DefaultCanvasPass.keywords.Add(GetAdditionalKeywords());
return DefaultCanvasPass;
}
// We don't need the save context / update materials for now
public override object saveContext => null;
public CanvasSubTarget()
{
displayName = "Canvas";
}
public override bool IsNodeAllowedBySubTarget(Type nodeType)
{
var interfaces = nodeType.GetInterfaces();
int numInterfaces = interfaces.Length;
// Subgraph nodes inherits all the interfaces including vertex ones.
if (nodeType == typeof(BitangentVectorNode))
return false;
if (nodeType == typeof(TangentVectorNode))
return false;
if (nodeType == typeof(SubGraphNode))
return true;
if (nodeType == typeof(BakedGINode))
return false;
if (nodeType == typeof(ParallaxMappingNode))
return false;
if (nodeType == typeof(ParallaxOcclusionMappingNode))
return false;
if (nodeType == typeof(TriplanarNode))
return false;
if (nodeType == typeof(IsFrontFaceNode))
return false;
for (int i = 0; i < numInterfaces; i++)
{
if (interfaces[i] == typeof(IMayRequireVertexSkinning)) return false;
}
return true;
}
#region KeywordDescriptors
internal static class CanvasKeywords
{
public static KeywordCollection GenerateCoreKeywords()
{
return new KeywordCollection()
{
UIAlphaClipKeyword,
UIClipRectKeyword,
};
}
static KeywordDescriptor UIClipRectKeyword = new KeywordDescriptor()
{
displayName = "UIClipRect",
referenceName = "UNITY_UI_CLIP_RECT",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Local,
};
static KeywordDescriptor UIAlphaClipKeyword = new KeywordDescriptor()
{
displayName = "UIAlphaClip",
referenceName = "UNITY_UI_ALPHACLIP",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Local,
};
public static readonly KeywordDescriptor DisableTint = new KeywordDescriptor()
{
displayName = "Disable Tint",
referenceName = "_DISABLE_COLOR_TINT",
type = KeywordType.Boolean,
definition = KeywordDefinition.ShaderFeature,
scope = KeywordScope.Local,
stages = KeywordShaderStage.All,
};
}
#endregion
}
#region PortMasks
class CanvasBlockMasks
{
// Port Mask
public static BlockFieldDescriptor[] Vertex = null;
public static BlockFieldDescriptor[] Fragment = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.Alpha,
BlockFields.SurfaceDescription.Emission,
BlockFields.SurfaceDescription.AlphaClipThreshold
};
}
#endregion
#region StructCollections
static class CanvasStructCollections
{
public static StructCollection Default = new StructCollection()
{
CanvasStructs.Attributes,
Structs.SurfaceDescriptionInputs,
CanvasStructs.Varyings,
Structs.VertexDescriptionInputs,
};
}
#endregion
#region RequiredFields
static class CanvasRequiredFields
{
public static FieldCollection Default = new FieldCollection()
{
StructFields.Varyings.positionCS,
StructFields.Varyings.normalWS,
StructFields.Varyings.positionWS,
StructFields.Varyings.color,
StructFields.Varyings.texCoord0,
StructFields.Varyings.texCoord1,
StructFields.Attributes.color,
StructFields.Attributes.uv0, // Always need texCoord0, for UI image
StructFields.Attributes.uv1, // Always need texCoord1 for UI Clip Mask
StructFields.Attributes.positionOS,
StructFields.Attributes.normalOS,
StructFields.Attributes.instanceID,
StructFields.Attributes.vertexID,
};
}
#endregion
#region RenderStates
static class CanvasRenderStates
{
public static RenderStateCollection GenerateRenderStateDeclaration()
{
return new RenderStateCollection
{
{RenderState.Cull(Cull.Off)},
{RenderState.ZWrite(ZWrite.Off)},
{RenderState.ZTest(CanvasUniforms.ZTest)},
{RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha)},
{RenderState.ColorMask(CanvasUniforms.ColorMask)},
{RenderState.Stencil(new StencilDescriptor()
{
Ref = CanvasUniforms.Ref,
Comp = CanvasUniforms.Comp,
Pass = CanvasUniforms.Pass,
ReadMask = CanvasUniforms.ReadMask,
WriteMask = CanvasUniforms.WriteMask,
})
}
};
}
}
#endregion
#region Pragmas
static class CanvasPragmas
{
public static PragmaCollection Default = new PragmaCollection
{
{Pragma.Target(ShaderModel.Target20)},
{Pragma.Vertex("vert")},
{Pragma.Fragment("frag")},
};
public static PragmaCollection DefaulDebugt = new PragmaCollection
{
{Pragma.Target(ShaderModel.Target20)},
{Pragma.Vertex("vert")},
{Pragma.Fragment("frag")},
{Pragma.DebugSymbols},
};
}
#endregion
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3ab5e3f315cd4041b2aa8600df09dd3e
timeCreated: 1669678519
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8d975524f8a3461d922a2e20170a1194
timeCreated: 1669153385
@@ -0,0 +1,94 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
using RenderQueue = UnityEngine.Rendering.RenderQueue;
using UnityEditor.ShaderGraph.Drawing;
namespace UnityEditor.Rendering.Canvas.ShaderGraph
{
public class CanvasShaderGUI : ShaderGUI
{
[Flags]
protected enum Expandable
{
SurfaceOptions = 1 << 0,
SurfaceInputs = 1 << 1,
}
protected class Styles
{
// Categories
public static readonly GUIContent SurfaceOptions =
EditorGUIUtility.TrTextContent("Surface Options",
"Controls the rendering states of the fullscreen material.");
public static readonly GUIContent SurfaceInputs = EditorGUIUtility.TrTextContent("Surface Inputs",
"These settings describe the look and feel of the surface itself.");
}
public bool m_FirstTimeApply = true;
// By default, everything is expanded
readonly MaterialHeaderScopeList m_MaterialScopeList = new MaterialHeaderScopeList(uint.MaxValue);
// These have to be stored due to how MaterialHeaderScopeList callbacks work (they don't provide this data in the callbacks)
MaterialEditor m_MaterialEditor;
MaterialProperty[] m_Properties;
private const int queueOffsetRange = 50;
override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
m_MaterialEditor = materialEditor;
m_Properties = properties;
Material targetMat = materialEditor.target as Material;
if (m_FirstTimeApply)
{
OnOpenGUI(targetMat, materialEditor, properties);
m_FirstTimeApply = false;
}
ShaderPropertiesGUI(materialEditor, targetMat, properties);
}
public virtual void OnOpenGUI(Material material, MaterialEditor materialEditor, MaterialProperty[] properties)
{
// Generate the foldouts
m_MaterialScopeList.RegisterHeaderScope(Styles.SurfaceInputs, (uint)Expandable.SurfaceInputs, DrawSurfaceInputs);
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
{
// Clear all keywords for fresh start
// Note: this will nuke user-selected custom keywords when they change shaders
material.shaderKeywords = null;
base.AssignNewShaderToMaterial(material, oldShader, newShader);
// Setup keywords based on the new shader
UnityEditor.Rendering.BuiltIn.ShaderUtils.ResetMaterialKeywords(material);
}
void ShaderPropertiesGUI(MaterialEditor materialEditor, Material material, MaterialProperty[] properties)
{
m_MaterialScopeList.DrawHeaders(materialEditor, material);
}
protected virtual void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(m_MaterialEditor, material, m_Properties);
}
static void DrawShaderGraphProperties(MaterialEditor materialEditor, Material material, MaterialProperty[] properties)
{
if (properties == null)
return;
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(materialEditor, properties);
}
public override void ValidateMaterial(Material material) => SetupSurface(material);
public static void SetupSurface(Material material)
{
// For now there is no keyword in FullScreenShader.
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b2f79c44dead4bc3b025342e56828a27
timeCreated: 1670295364
@@ -0,0 +1,133 @@
Pass
{
$splice(PassName)
Tags
{
$splice(LightMode)
}
// Render State
$splice(RenderState)
// Debug
$splice(Debug)
// --------------------------------------------------
// Pass
HLSLPROGRAM
// Pragmas
$splice(PassPragmas)
// Keywords
$splice(PassKeywords)
$splice(GraphKeywords)
#define CANVAS_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.uv6: #define ATTRIBUTES_NEED_TEXCOORD6
$Attributes.uv7: #define ATTRIBUTES_NEED_TEXCOORD7
$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.texCoord4: #define VARYINGS_NEED_TEXCOORD4
$Varyings.texCoord5: #define VARYINGS_NEED_TEXCOORD5
$Varyings.texCoord6: #define VARYINGS_NEED_TEXCOORD6
$Varyings.texCoord7: #define VARYINGS_NEED_TEXCOORD7
$Varyings.color: #define VARYINGS_NEED_COLOR
$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("BuildVertexDescriptionInputs.template.hlsl")
$features.graphPixel: $include("BuildSurfaceDescriptionInputs.template.hlsl")
// --------------------------------------------------
// Main
$splice(PostGraphIncludes)
ENDHLSL
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3fa60ca3757a4221b2b042165c4696fe
timeCreated: 1655252373