initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 702cc9b492bf4f6da778b0f5c996b7ad
timeCreated: 1614049029

View file

@ -0,0 +1,29 @@
using System;
using UnityEditor.ShaderGraph;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
static class CreateSpriteCustomLitShaderGraph
{
[MenuItem("Assets/Create/Shader Graph/URP/Sprite Custom Lit Shader Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority)]
public static void CreateSpriteLitGraph()
{
var target = (UniversalTarget)Activator.CreateInstance(typeof(UniversalTarget));
target.TrySetActiveSubTarget(typeof(UniversalSpriteCustomLitSubTarget));
var blockDescriptors = new[]
{
BlockFields.VertexDescription.Position,
BlockFields.VertexDescription.Normal,
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
UniversalBlockFields.SurfaceDescription.SpriteMask,
BlockFields.SurfaceDescription.NormalTS,
BlockFields.SurfaceDescription.Alpha,
};
GraphUtil.CreateNewGraphWithOutputs(new[] { target }, blockDescriptors);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a8438a1564134e1fbb2669e697bee11f
timeCreated: 1614570277

View file

@ -0,0 +1,29 @@
using System;
using UnityEditor.ShaderGraph;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
static class CreateSpriteLitShaderGraph
{
[MenuItem("Assets/Create/Shader Graph/URP/Sprite Lit Shader Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority + 1)]
public static void CreateSpriteLitGraph()
{
var target = (UniversalTarget)Activator.CreateInstance(typeof(UniversalTarget));
target.TrySetActiveSubTarget(typeof(UniversalSpriteLitSubTarget));
var blockDescriptors = new[]
{
BlockFields.VertexDescription.Position,
BlockFields.VertexDescription.Normal,
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
UniversalBlockFields.SurfaceDescription.SpriteMask,
BlockFields.SurfaceDescription.NormalTS,
BlockFields.SurfaceDescription.Alpha,
};
GraphUtil.CreateNewGraphWithOutputs(new[] { target }, blockDescriptors);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc7283e53c0339a40adca7609d7985d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,27 @@
using System;
using UnityEditor.ShaderGraph;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
static class CreateSpriteUnlitShaderGraph
{
[MenuItem("Assets/Create/Shader Graph/URP/Sprite Unlit Shader Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority)]
public static void CreateSpriteUnlitGraph()
{
var target = (UniversalTarget)Activator.CreateInstance(typeof(UniversalTarget));
target.TrySetActiveSubTarget(typeof(UniversalSpriteUnlitSubTarget));
var blockDescriptors = new[]
{
BlockFields.VertexDescription.Position,
BlockFields.VertexDescription.Normal,
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.Alpha,
};
GraphUtil.CreateNewGraphWithOutputs(new[] { target }, blockDescriptors);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1d9d11b6a33b4b4e83c36bd926bbb77
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b0e1457667cf4865bf50a0f8567c4d29
timeCreated: 1614049038

View file

@ -0,0 +1,45 @@
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
half4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
#ifdef UNIVERSAL_USELEGACYSPRITEBLOCKS
half4 color = surfaceDescription.SpriteColor;
#else
half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha);
#endif
#if defined(DEBUG_DISPLAY)
SurfaceData2D surfaceData;
InitializeSurfaceData(color.rgb, color.a, surfaceData);
InputData2D inputData;
InitializeInputData(unpacked.positionWS.xy, half2(unpacked.texCoord0.xy), inputData);
half4 debugColor = 0;
SETUP_DEBUG_DATA_2D(inputData, unpacked.positionWS);
if (CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
{
return debugColor;
}
#endif
color *= unpacked.color;
return color;
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4ad8b54817d9f5441910014b5ceb8583
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,55 @@
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
#if USE_SHAPE_LIGHT_TYPE_0
SHAPE_LIGHT(0)
#endif
#if USE_SHAPE_LIGHT_TYPE_1
SHAPE_LIGHT(1)
#endif
#if USE_SHAPE_LIGHT_TYPE_2
SHAPE_LIGHT(2)
#endif
#if USE_SHAPE_LIGHT_TYPE_3
SHAPE_LIGHT(3)
#endif
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
half4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
#ifdef UNIVERSAL_USELEGACYSPRITEBLOCKS
half4 color = surfaceDescription.SpriteColor;
#else
half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha);
#endif
color *= unpacked.color;
SurfaceData2D surfaceData;
InitializeSurfaceData(color.rgb, color.a, surfaceDescription.SpriteMask, surfaceData);
InputData2D inputData;
InitializeInputData(unpacked.texCoord0.xy, half2(unpacked.screenPosition.xy / unpacked.screenPosition.w), inputData);
SETUP_DEBUG_DATA_2D(inputData, unpacked.positionWS);
return CombinedShapeLightShared(surfaceData, inputData);
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3ce18356597793947bd0f671f7363559
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,29 @@
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
output.normalWS = -GetViewForwardDir();
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
half4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
half crossSign = (unpacked.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
half3 bitangent = crossSign * cross(unpacked.normalWS.xyz, unpacked.tangentWS.xyz);
#ifdef UNIVERSAL_USELEGACYSPRITEBLOCKS
half4 color = surfaceDescription.SpriteColor;
#else
half4 color = half4(1.0,1.0,1.0, surfaceDescription.Alpha);
#endif
return NormalsRenderingShared(color, surfaceDescription.NormalTS, unpacked.tangentWS.xyz, bitangent, unpacked.normalWS);
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 39ce338156d9f6b40b4702eb2d26d40d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,47 @@
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
half4 _RendererColor;
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
half4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
#ifdef UNIVERSAL_USELEGACYSPRITEBLOCKS
half4 color = surfaceDescription.SpriteColor;
#else
half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha);
#endif
#if defined(DEBUG_DISPLAY)
SurfaceData2D surfaceData;
InitializeSurfaceData(color.rgb, color.a, surfaceData);
InputData2D inputData;
InitializeInputData(unpacked.positionWS.xy, half2(unpacked.texCoord0.xy), inputData);
half4 debugColor = 0;
SETUP_DEBUG_DATA_2D(inputData, unpacked.positionWS);
if (CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
{
return debugColor;
}
#endif
color *= unpacked.color * _RendererColor;
return color;
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 172e304acf14e434e967133e7ee67273
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f270bf32cbff4c02ae07004a815c5632
timeCreated: 1614049109

View file

@ -0,0 +1,76 @@
using System;
using UnityEditor.Graphing;
using UnityEditor.Rendering.Universal.ShaderGraph;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.Universal
{
enum BlendStyle
{
LightTex0,
LightTex1,
LightTex2,
LightTex3,
}
[Title("Input", "2D", "Light Texture")]
[SubTargetFilterAttribute(new[] { typeof(UniversalSpriteCustomLitSubTarget) })]
class LightTextureNode : AbstractMaterialNode
{
private const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
[SerializeField] private BlendStyle m_BlendStyle = BlendStyle.LightTex0;
[EnumControl("")]
public BlendStyle blendStyle
{
get { return m_BlendStyle; }
set
{
if (m_BlendStyle == value)
return;
m_BlendStyle = value;
Dirty(ModificationScope.Graph);
}
}
public LightTextureNode()
{
name = "2D Light Texture";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Texture2DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
string GetVariableName()
{
return $"_ShapeLightTexture{(int)m_BlendStyle}";
}
public override string GetVariableNameForSlot(int slotId)
{
return $"UnityBuildTexture2DStructNoScale({GetVariableName()})";
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Texture2DShaderProperty()
{
overrideReferenceName = GetVariableName(),
generatePropertyBlock = false,
defaultType = Texture2DShaderProperty.DefaultType.White,
// value = m_Texture,
modifiable = false
});
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e9aa28223a914899adffca20c1ff4226
timeCreated: 1612248219

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6235450d5ad64142aeb12e4f3cac5f72
timeCreated: 1614049047

View file

@ -0,0 +1,309 @@
using System;
using System.Linq;
using UnityEditor.ShaderGraph;
using UnityEditor.UIElements;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
sealed class UniversalSpriteCustomLitSubTarget : SubTarget<UniversalTarget>
{
static readonly GUID kSourceCodeGuid = new GUID("69e608b3e7e0405bbc2f259ad9cfa196"); // UniversalUnlitSubTarget.cs
public UniversalSpriteCustomLitSubTarget()
{
displayName = "Sprite Custom Lit";
}
public override bool IsActive() => true;
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
context.AddSubShader(SubShaders.SpriteLit(target));
}
public override void GetFields(ref TargetFieldContext context)
{
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
var descs = context.blocks.Select(x => x.descriptor);
bool useLegacyBlocks = !descs.Contains(BlockFields.SurfaceDescription.BaseColor) && !descs.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddField(CoreFields.UseLegacySpriteBlocks, useLegacyBlocks);
// Surface Type
context.AddField(UniversalFields.SurfaceTransparent);
context.AddField(Fields.DoubleSided);
// Blend Mode
switch (target.alphaMode)
{
case AlphaMode.Premultiply:
context.AddField(UniversalFields.BlendPremultiply);
break;
case AlphaMode.Additive:
context.AddField(UniversalFields.BlendAdd);
break;
case AlphaMode.Multiply:
context.AddField(UniversalFields.BlendMultiply);
break;
default:
context.AddField(Fields.BlendAlpha);
break;
}
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
bool useLegacyBlocks = !context.currentBlocks.Contains(BlockFields.SurfaceDescription.BaseColor) && !context.currentBlocks.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddBlock(BlockFields.SurfaceDescriptionLegacy.SpriteColor, useLegacyBlocks);
context.AddBlock(UniversalBlockFields.SurfaceDescription.SpriteMask);
context.AddBlock(BlockFields.SurfaceDescription.NormalTS);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = target.alphaMode }, (evt) =>
{
if (Equals(target.alphaMode, evt.newValue))
return;
registerUndo("Change Blend");
target.alphaMode = (AlphaMode)evt.newValue;
onChange();
});
}
#region SubShader
static class SubShaders
{
public static SubShaderDescriptor SpriteLit(UniversalTarget target)
{
SubShaderDescriptor result = new SubShaderDescriptor()
{
pipelineTag = UniversalTarget.kPipelineTag,
customTags = UniversalTarget.kLitMaterialTypeTag,
renderType = $"{RenderType.Transparent}",
renderQueue = $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}",
generatesPreview = true,
passes = new PassCollection
{
{ SpriteLitPasses.Lit },
{ SpriteLitPasses.Normal },
// Currently neither of these passes (selection/picking) can be last for the game view for
// UI shaders to render correctly. Verify [1352225] before changing this order.
{ CorePasses._2DSceneSelection(target) },
{ CorePasses._2DScenePicking(target) },
{ SpriteLitPasses.Forward },
},
};
return result;
}
}
#endregion
#region Passes
static class SpriteLitPasses
{
public static PassDescriptor Lit = new PassDescriptor
{
// Definition
displayName = "Sprite Lit",
referenceName = "SHADERPASS_SPRITELIT",
lightMode = "Universal2D",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentLit,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Lit,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
keywords = SpriteLitKeywords.Lit,
includes = SpriteLitIncludes.Lit,
};
public static PassDescriptor Normal = new PassDescriptor
{
// Definition
displayName = "Sprite Normal",
referenceName = "SHADERPASS_SPRITENORMAL",
lightMode = "NormalsRendering",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentNormal,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Normal,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
includes = SpriteLitIncludes.Normal,
};
public static PassDescriptor Forward = new PassDescriptor
{
// Definition
displayName = "Sprite Forward",
referenceName = "SHADERPASS_SPRITEFORWARD",
lightMode = "UniversalForward",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentForward,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Forward,
keywords = SpriteLitKeywords.Forward,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
includes = SpriteLitIncludes.Forward,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
}
#endregion
#region PortMasks
static class SpriteLitBlockMasks
{
public static BlockFieldDescriptor[] FragmentLit = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescriptionLegacy.SpriteColor,
BlockFields.SurfaceDescription.Alpha,
UniversalBlockFields.SurfaceDescription.SpriteMask,
};
public static BlockFieldDescriptor[] FragmentNormal = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.Alpha,
BlockFields.SurfaceDescription.NormalTS,
};
public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescriptionLegacy.SpriteColor,
BlockFields.SurfaceDescription.Alpha,
BlockFields.SurfaceDescription.NormalTS,
};
}
#endregion
#region RequiredFields
static class SpriteLitRequiredFields
{
public static FieldCollection Lit = new FieldCollection()
{
StructFields.Varyings.color,
StructFields.Varyings.positionWS,
StructFields.Varyings.texCoord0,
StructFields.Varyings.screenPosition,
};
public static FieldCollection Normal = new FieldCollection()
{
StructFields.Varyings.normalWS,
StructFields.Varyings.tangentWS,
};
public static FieldCollection Forward = new FieldCollection()
{
StructFields.Varyings.color,
StructFields.Varyings.positionWS,
StructFields.Varyings.texCoord0,
};
}
#endregion
#region Keywords
static class SpriteLitKeywords
{
public static KeywordCollection Lit = new KeywordCollection
{
{ CoreKeywordDescriptors.DebugDisplay },
};
public static KeywordCollection Forward = new KeywordCollection
{
{ CoreKeywordDescriptors.DebugDisplay },
};
}
#endregion
#region Includes
static class SpriteLitIncludes
{
const string kSpriteUnlitPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteUnlitPass.hlsl";
const string k2DNormal = "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl";
const string kSpriteNormalPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteNormalPass.hlsl";
const string kSpriteForwardPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteForwardPass.hlsl";
public static IncludeCollection Lit = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteUnlitPass, IncludeLocation.Postgraph },
};
public static IncludeCollection Normal = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
{ k2DNormal, IncludeLocation.Pregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteNormalPass, IncludeLocation.Postgraph },
};
public static IncludeCollection Forward = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteForwardPass, IncludeLocation.Postgraph },
};
}
#endregion
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1bbf55e7974743d8babdda480740a760
timeCreated: 1616491424

View file

@ -0,0 +1,337 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Legacy;
using UnityEditor.UIElements;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
sealed class UniversalSpriteLitSubTarget : SubTarget<UniversalTarget>, ILegacyTarget
{
static readonly GUID kSourceCodeGuid = new GUID("ea1514729d7120344b27dcd67fbf34de"); // UniversalSpriteLitSubTarget.cs
public UniversalSpriteLitSubTarget()
{
displayName = "Sprite Lit";
}
public override bool IsActive() => true;
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
context.AddSubShader(SubShaders.SpriteLit(target));
}
public override void GetFields(ref TargetFieldContext context)
{
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
var descs = context.blocks.Select(x => x.descriptor);
bool useLegacyBlocks = !descs.Contains(BlockFields.SurfaceDescription.BaseColor) && !descs.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddField(CoreFields.UseLegacySpriteBlocks, useLegacyBlocks);
// Surface Type
context.AddField(UniversalFields.SurfaceTransparent);
context.AddField(Fields.DoubleSided);
// Blend Mode
switch (target.alphaMode)
{
case AlphaMode.Premultiply:
context.AddField(UniversalFields.BlendPremultiply);
break;
case AlphaMode.Additive:
context.AddField(UniversalFields.BlendAdd);
break;
case AlphaMode.Multiply:
context.AddField(UniversalFields.BlendMultiply);
break;
default:
context.AddField(Fields.BlendAlpha);
break;
}
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
bool useLegacyBlocks = !context.currentBlocks.Contains(BlockFields.SurfaceDescription.BaseColor) && !context.currentBlocks.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddBlock(BlockFields.SurfaceDescriptionLegacy.SpriteColor, useLegacyBlocks);
context.AddBlock(UniversalBlockFields.SurfaceDescription.SpriteMask);
context.AddBlock(BlockFields.SurfaceDescription.NormalTS);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = target.alphaMode }, (evt) =>
{
if (Equals(target.alphaMode, evt.newValue))
return;
registerUndo("Change Blend");
target.alphaMode = (AlphaMode)evt.newValue;
onChange();
});
}
public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
{
blockMap = null;
if (!(masterNode is SpriteLitMasterNode1 spriteLitMasterNode))
return false;
// Set blockmap
blockMap = new Dictionary<BlockFieldDescriptor, int>()
{
{ BlockFields.VertexDescription.Position, 9 },
{ BlockFields.VertexDescription.Normal, 10 },
{ BlockFields.VertexDescription.Tangent, 11 },
{ BlockFields.SurfaceDescriptionLegacy.SpriteColor, 0 },
{ UniversalBlockFields.SurfaceDescription.SpriteMask, 1 },
{ BlockFields.SurfaceDescription.NormalTS, 2 },
};
return true;
}
#region SubShader
static class SubShaders
{
public static SubShaderDescriptor SpriteLit(UniversalTarget target)
{
SubShaderDescriptor result = new SubShaderDescriptor()
{
pipelineTag = UniversalTarget.kPipelineTag,
customTags = UniversalTarget.kLitMaterialTypeTag,
renderType = $"{RenderType.Transparent}",
renderQueue = $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}",
generatesPreview = true,
passes = new PassCollection
{
{ SpriteLitPasses.Lit },
{ SpriteLitPasses.Normal },
// Currently neither of these passes (selection/picking) can be last for the game view for
// UI shaders to render correctly. Verify [1352225] before changing this order.
{ CorePasses._2DSceneSelection(target) },
{ CorePasses._2DScenePicking(target) },
{ SpriteLitPasses.Forward },
},
};
return result;
}
}
#endregion
#region Passes
static class SpriteLitPasses
{
public static PassDescriptor Lit = new PassDescriptor
{
// Definition
displayName = "Sprite Lit",
referenceName = "SHADERPASS_SPRITELIT",
lightMode = "Universal2D",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentLit,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Lit,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
keywords = SpriteLitKeywords.Lit,
includes = SpriteLitIncludes.Lit,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
public static PassDescriptor Normal = new PassDescriptor
{
// Definition
displayName = "Sprite Normal",
referenceName = "SHADERPASS_SPRITENORMAL",
lightMode = "NormalsRendering",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentForwardNormal,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Normal,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
includes = SpriteLitIncludes.Normal,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
public static PassDescriptor Forward = new PassDescriptor
{
// Definition
displayName = "Sprite Forward",
referenceName = "SHADERPASS_SPRITEFORWARD",
lightMode = "UniversalForward",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteLitBlockMasks.FragmentForwardNormal,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteLitRequiredFields.Forward,
keywords = SpriteLitKeywords.Forward,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
includes = SpriteLitIncludes.Forward,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
}
#endregion
#region PortMasks
static class SpriteLitBlockMasks
{
public static BlockFieldDescriptor[] FragmentLit = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescriptionLegacy.SpriteColor,
BlockFields.SurfaceDescription.Alpha,
UniversalBlockFields.SurfaceDescription.SpriteMask,
};
public static BlockFieldDescriptor[] FragmentForwardNormal = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescriptionLegacy.SpriteColor,
BlockFields.SurfaceDescription.Alpha,
BlockFields.SurfaceDescription.NormalTS,
};
}
#endregion
#region RequiredFields
static class SpriteLitRequiredFields
{
public static FieldCollection Lit = new FieldCollection()
{
StructFields.Varyings.color,
StructFields.Varyings.positionWS,
StructFields.Varyings.texCoord0,
StructFields.Varyings.screenPosition,
};
public static FieldCollection Normal = new FieldCollection()
{
StructFields.Varyings.normalWS,
StructFields.Varyings.tangentWS,
};
public static FieldCollection Forward = new FieldCollection()
{
StructFields.Varyings.color,
StructFields.Varyings.positionWS,
StructFields.Varyings.texCoord0,
};
}
#endregion
#region Keywords
static class SpriteLitKeywords
{
public static KeywordCollection Lit = new KeywordCollection
{
{ CoreKeywordDescriptors.ShapeLightType0 },
{ CoreKeywordDescriptors.ShapeLightType1 },
{ CoreKeywordDescriptors.ShapeLightType2 },
{ CoreKeywordDescriptors.ShapeLightType3 },
{ CoreKeywordDescriptors.DebugDisplay },
};
public static KeywordCollection Forward = new KeywordCollection
{
{ CoreKeywordDescriptors.DebugDisplay },
};
}
#endregion
#region Includes
static class SpriteLitIncludes
{
const string k2DLightingUtil = "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl";
const string k2DNormal = "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl";
const string kSpriteLitPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteLitPass.hlsl";
const string kSpriteNormalPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteNormalPass.hlsl";
const string kSpriteForwardPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteForwardPass.hlsl";
public static IncludeCollection Lit = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
{ k2DLightingUtil, IncludeLocation.Pregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteLitPass, IncludeLocation.Postgraph },
};
public static IncludeCollection Normal = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
{ k2DNormal, IncludeLocation.Pregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteNormalPass, IncludeLocation.Postgraph },
};
public static IncludeCollection Forward = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteForwardPass, IncludeLocation.Postgraph },
};
}
#endregion
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea1514729d7120344b27dcd67fbf34de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,244 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Legacy;
using UnityEditor.UIElements;
namespace UnityEditor.Rendering.Universal.ShaderGraph
{
sealed class UniversalSpriteUnlitSubTarget : SubTarget<UniversalTarget>, ILegacyTarget
{
static readonly GUID kSourceCodeGuid = new GUID("ed7c0aacec26e9646b45c96fb318e5a3"); // UniversalSpriteUnlitSubTarget.cs
public UniversalSpriteUnlitSubTarget()
{
displayName = "Sprite Unlit";
}
public override bool IsActive() => true;
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
context.AddSubShader(SubShaders.SpriteUnlit(target));
}
public override void GetFields(ref TargetFieldContext context)
{
var descs = context.blocks.Select(x => x.descriptor);
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
bool useLegacyBlocks = !descs.Contains(BlockFields.SurfaceDescription.BaseColor) && !descs.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddField(CoreFields.UseLegacySpriteBlocks, useLegacyBlocks);
// Surface Type
context.AddField(UniversalFields.SurfaceTransparent);
context.AddField(Fields.DoubleSided);
// Blend Mode
switch (target.alphaMode)
{
case AlphaMode.Premultiply:
context.AddField(UniversalFields.BlendPremultiply);
break;
case AlphaMode.Additive:
context.AddField(UniversalFields.BlendAdd);
break;
case AlphaMode.Multiply:
context.AddField(UniversalFields.BlendMultiply);
break;
default:
context.AddField(Fields.BlendAlpha);
break;
}
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
// Only support SpriteColor legacy block if BaseColor/Alpha are not active
bool useLegacyBlocks = !context.currentBlocks.Contains(BlockFields.SurfaceDescription.BaseColor) && !context.currentBlocks.Contains(BlockFields.SurfaceDescription.Alpha);
context.AddBlock(BlockFields.SurfaceDescriptionLegacy.SpriteColor, useLegacyBlocks);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = target.alphaMode }, (evt) =>
{
if (Equals(target.alphaMode, evt.newValue))
return;
registerUndo("Change Blend");
target.alphaMode = (AlphaMode)evt.newValue;
onChange();
});
}
public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
{
blockMap = null;
if (!(masterNode is SpriteUnlitMasterNode1 spriteUnlitMasterNode))
return false;
// Set blockmap
blockMap = new Dictionary<BlockFieldDescriptor, int>()
{
{ BlockFields.VertexDescription.Position, 9 },
{ BlockFields.VertexDescription.Normal, 10 },
{ BlockFields.VertexDescription.Tangent, 11 },
{ BlockFields.SurfaceDescriptionLegacy.SpriteColor, 0 },
};
return true;
}
#region SubShader
static class SubShaders
{
public static SubShaderDescriptor SpriteUnlit(UniversalTarget target)
{
SubShaderDescriptor result = new SubShaderDescriptor()
{
pipelineTag = UniversalTarget.kPipelineTag,
customTags = UniversalTarget.kUnlitMaterialTypeTag,
renderType = $"{RenderType.Transparent}",
renderQueue = $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}",
generatesPreview = true,
passes = new PassCollection
{
{ SpriteUnlitPasses.Unlit },
// Currently neither of these passes (selection/picking) can be last for the game view for
// UI shaders to render correctly. Verify [1352225] before changing this order.
{ CorePasses._2DSceneSelection(target) },
{ CorePasses._2DScenePicking(target) },
{ SpriteUnlitPasses.Forward },
},
};
return result;
}
}
#endregion
#region Passes
static class SpriteUnlitPasses
{
public static PassDescriptor Unlit = new PassDescriptor
{
// Definition
displayName = "Sprite Unlit",
referenceName = "SHADERPASS_SPRITEUNLIT",
lightMode = "Universal2D",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteUnlitBlockMasks.Fragment,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteUnlitRequiredFields.Unlit,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
keywords = SpriteUnlitKeywords.Unlit,
includes = SpriteUnlitIncludes.Unlit,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
public static PassDescriptor Forward = new PassDescriptor
{
// Definition
displayName = "Sprite Unlit",
referenceName = "SHADERPASS_SPRITEFORWARD",
lightMode = "UniversalForward",
useInPreview = true,
// Template
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Port Mask
validVertexBlocks = CoreBlockMasks.Vertex,
validPixelBlocks = SpriteUnlitBlockMasks.Fragment,
// Fields
structs = CoreStructCollections.Default,
requiredFields = SpriteUnlitRequiredFields.Unlit,
fieldDependencies = CoreFieldDependencies.Default,
// Conditional State
renderStates = CoreRenderStates.Default,
pragmas = CorePragmas._2DDefault,
keywords = SpriteUnlitKeywords.Unlit,
includes = SpriteUnlitIncludes.Unlit,
// Custom Interpolator Support
customInterpolators = CoreCustomInterpDescriptors.Common
};
}
#endregion
#region PortMasks
static class SpriteUnlitBlockMasks
{
public static BlockFieldDescriptor[] Fragment = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescriptionLegacy.SpriteColor,
BlockFields.SurfaceDescription.Alpha,
};
}
#endregion
#region RequiredFields
static class SpriteUnlitRequiredFields
{
public static FieldCollection Unlit = new FieldCollection()
{
StructFields.Attributes.color,
StructFields.Attributes.uv0,
StructFields.Varyings.positionWS,
StructFields.Varyings.color,
StructFields.Varyings.texCoord0,
};
}
#endregion
#region Keywords
static class SpriteUnlitKeywords
{
public static KeywordCollection Unlit = new KeywordCollection
{
{ CoreKeywordDescriptors.DebugDisplay },
};
}
#endregion
#region Includes
static class SpriteUnlitIncludes
{
const string kSpriteUnlitPass = "Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteUnlitPass.hlsl";
public static IncludeCollection Unlit = new IncludeCollection
{
// Pre-graph
{ CoreIncludes.CorePregraph },
{ CoreIncludes.ShaderGraphPregraph },
// Post-graph
{ CoreIncludes.CorePostgraph },
{ kSpriteUnlitPass, IncludeLocation.Postgraph },
};
}
#endregion
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed7c0aacec26e9646b45c96fb318e5a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: