Skip to content

Commit 3220970

Browse files
cprasad-rythmosEvergreen
authored andcommitted
Overdraw support
To add overdraw support for TextMeshPro shaders. To add overdraw support for couple of URP shaders, which missed the support. To add overdraw support for non-sprite 2d lit shaders generated by Shader Graph tool. Bug: https://jira.unity3d.com/browse/UUM-64493 Port: https://jira.unity3d.com/browse/UUM-64893
1 parent a55b816 commit 3220970

18 files changed

+200
-13
lines changed

Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
#if defined(DEBUG_DISPLAY)
3+
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl"
4+
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
5+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
6+
#endif
7+
18
PackedVaryings vert(Attributes input)
29
{
310
Varyings output = (Varyings)0;
@@ -24,5 +31,20 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
2431
#endif
2532

2633
half4 color = half4(surfaceDescription.BaseColor, alpha);
34+
35+
#if defined(DEBUG_DISPLAY)
36+
SurfaceData2D surfaceData;
37+
InitializeSurfaceData(color.rgb, color.a, surfaceData);
38+
InputData2D inputData;
39+
InitializeInputData(unpacked.positionCS.xy, half2(unpacked.positionCS.xy), inputData);
40+
half4 debugColor = 0;
41+
42+
SETUP_DEBUG_DATA_2D(inputData, unpacked.positionCS, unpacked.positionCS);
43+
44+
if (CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
45+
{
46+
return debugColor;
47+
}
48+
#endif
2749
return color;
2850
}

Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public static SubShaderDescriptor LitSubShader(UniversalTarget target, WorkflowM
371371
// UI shaders to render correctly. Verify [1352225] before changing this order.
372372
result.passes.Add(PassVariant(CorePasses.SceneSelection(target), CorePragmas.Default));
373373
result.passes.Add(PassVariant(CorePasses.ScenePicking(target), CorePragmas.Default));
374-
result.passes.Add(PassVariant(LitPasses._2D(target), CorePragmas.Default));
374+
result.passes.Add(LitPasses._2D(target, LitKeywords._2D));
375375

376376
return result;
377377
}
@@ -580,7 +580,7 @@ public static PassDescriptor Meta(UniversalTarget target)
580580
return result;
581581
}
582582

583-
public static PassDescriptor _2D(UniversalTarget target)
583+
public static PassDescriptor _2D(UniversalTarget target, KeywordCollection keywords)
584584
{
585585
var result = new PassDescriptor()
586586
{
@@ -603,9 +603,9 @@ public static PassDescriptor _2D(UniversalTarget target)
603603

604604
// Conditional State
605605
renderStates = CoreRenderStates.UberSwitchedRenderState(target),
606-
pragmas = CorePragmas.Instanced,
606+
pragmas = CorePragmas._2DDefault,
607607
defines = new DefineCollection(),
608-
keywords = new KeywordCollection(),
608+
keywords = new KeywordCollection { keywords },
609609
includes = LitIncludes._2D,
610610

611611
// Custom Interpolator Support
@@ -869,6 +869,11 @@ static class LitKeywords
869869
{ CoreKeywordDescriptors.RenderPassEnabled },
870870
{ CoreKeywordDescriptors.DebugDisplay },
871871
};
872+
873+
public static readonly KeywordCollection _2D = new KeywordCollection
874+
{
875+
{ CoreKeywordDescriptors.DebugDisplay },
876+
};
872877
}
873878
#endregion
874879

Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SpriteMaskShared.hlsl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#if !defined(SPRITE_MASK_SHARED)
33
#define SPRITE_MASK_SHARED
44

5-
5+
#if defined(DEBUG_DISPLAY)
6+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
7+
#endif
68
// alpha below which a mask should discard a pixel, thereby preventing the stencil buffer from being marked with the Mask's presence
79
half _Cutoff;
810

@@ -36,7 +38,16 @@ half4 MaskRenderingFragment(Varyings input) : SV_Target
3638
half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
3739
// for masks: discard pixel if alpha falls below MaskingCutoff
3840
clip(c.a - _Cutoff);
39-
41+
#if defined(DEBUG_DISPLAY)
42+
half4 debugColor = 0;
43+
SurfaceData2D surfaceData;
44+
InitializeSurfaceData(1.0f, 1.0f, surfaceData);
45+
InputData2D inputData;
46+
InitializeInputData(input.positionCS, input.uv, inputData);
47+
48+
if(CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
49+
return debugColor;
50+
#endif
4051
return half4(1, 1, 1, 0.2);
4152
}
4253

Packages/com.unity.render-pipelines.universal/Shaders/2D/Sprite-Mask.shader

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Shader "Universal Render Pipeline/2D/Sprite-Mask"
3434
HLSLPROGRAM
3535
#pragma vertex MaskRenderingVertex
3636
#pragma fragment MaskRenderingFragment
37+
#pragma multi_compile _ DEBUG_DISPLAY
3738

3839
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SpriteMaskShared.hlsl"
3940
ENDHLSL
@@ -44,6 +45,7 @@ Shader "Universal Render Pipeline/2D/Sprite-Mask"
4445
HLSLPROGRAM
4546
#pragma vertex MaskRenderingVertex
4647
#pragma fragment MaskRenderingFragment
48+
#pragma multi_compile _ DEBUG_DISPLAY
4749

4850
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SpriteMaskShared.hlsl"
4951
ENDHLSL
@@ -54,6 +56,7 @@ Shader "Universal Render Pipeline/2D/Sprite-Mask"
5456
HLSLPROGRAM
5557
#pragma vertex MaskRenderingVertex
5658
#pragma fragment MaskRenderingFragment
59+
#pragma multi_compile _ DEBUG_DISPLAY
5760

5861
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SpriteMaskShared.hlsl"
5962
ENDHLSL

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_Bitmap-Custom-Atlas.shader

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ SubShader{
5252

5353
#pragma multi_compile __ UNITY_UI_CLIP_RECT
5454
#pragma multi_compile __ UNITY_UI_ALPHACLIP
55-
55+
#pragma multi_compile _ DEBUG_DISPLAY
5656

5757
#include "UnityCG.cginc"
5858

59+
#if defined(DEBUG_DISPLAY)
60+
#include "Debugging2D.cginc"
61+
#endif
62+
5963
struct appdata_t
6064
{
6165
float4 vertex : POSITION;
@@ -129,6 +133,11 @@ SubShader{
129133
clip(color.a - 0.001);
130134
#endif
131135

136+
#if defined(DEBUG_DISPLAY)
137+
fixed4 debugColor = 0;
138+
if(CanDebugOverrideOutputColor(debugColor))
139+
return debugColor;
140+
#endif
132141
return color;
133142
}
134143
ENDCG

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_Bitmap-Mobile.shader

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ SubShader {
5252

5353
#pragma multi_compile __ UNITY_UI_CLIP_RECT
5454
#pragma multi_compile __ UNITY_UI_ALPHACLIP
55-
55+
#pragma multi_compile _ DEBUG_DISPLAY
5656

5757
#include "UnityCG.cginc"
5858

59+
#if defined(DEBUG_DISPLAY)
60+
#include "Debugging2D.cginc"
61+
#endif
62+
5963
struct appdata_t
6064
{
6165
float4 vertex : POSITION;
@@ -123,7 +127,11 @@ SubShader {
123127
#if UNITY_UI_ALPHACLIP
124128
clip(color.a - 0.001);
125129
#endif
126-
130+
#if defined(DEBUG_DISPLAY)
131+
fixed4 debugColor = 0;
132+
if(CanDebugOverrideOutputColor(debugColor))
133+
return debugColor;
134+
#endif
127135
return color;
128136
}
129137
ENDCG

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_Bitmap.shader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ SubShader{
4949
#pragma vertex vert
5050
#pragma fragment frag
5151

52+
#pragma multi_compile _ DEBUG_DISPLAY
5253
#pragma multi_compile __ UNITY_UI_CLIP_RECT
5354
#pragma multi_compile __ UNITY_UI_ALPHACLIP
5455

5556

5657
#include "UnityCG.cginc"
5758

59+
#if defined(DEBUG_DISPLAY)
60+
#include "Debugging2D.cginc"
61+
#endif
62+
5863
struct appdata_t
5964
{
6065
float4 vertex : POSITION;
@@ -129,6 +134,12 @@ SubShader{
129134
clip(color.a - 0.001);
130135
#endif
131136

137+
#if defined(DEBUG_DISPLAY)
138+
fixed4 debugColor = 0;
139+
if(CanDebugOverrideOutputColor(debugColor))
140+
return debugColor;
141+
#endif
142+
132143
return color;
133144
}
134145
ENDCG

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_SDF Overlay.shader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ SubShader {
119119
#pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER
120120
#pragma shader_feature __ GLOW_ON
121121

122+
#pragma multi_compile _ DEBUG_DISPLAY
122123
#pragma multi_compile __ UNITY_UI_CLIP_RECT
123124
#pragma multi_compile __ UNITY_UI_ALPHACLIP
124125

@@ -127,6 +128,10 @@ SubShader {
127128
#include "TMPro_Properties.cginc"
128129
#include "TMPro.cginc"
129130

131+
#if defined(DEBUG_DISPLAY)
132+
#include "Debugging2D.cginc"
133+
#endif
134+
130135
struct vertex_t
131136
{
132137
UNITY_VERTEX_INPUT_INSTANCE_ID
@@ -310,6 +315,12 @@ SubShader {
310315
clip(faceColor.a - 0.001);
311316
#endif
312317

318+
#if defined(DEBUG_DISPLAY)
319+
fixed4 debugColor = 0;
320+
if(CanDebugOverrideOutputColor(debugColor))
321+
return debugColor;
322+
#endif
323+
313324
return faceColor * input.color.a;
314325
}
315326
ENDCG

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_SDF SSD.shader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,17 @@ SubShader {
122122

123123
#pragma multi_compile __ UNITY_UI_CLIP_RECT
124124
#pragma multi_compile __ UNITY_UI_ALPHACLIP
125+
#pragma multi_compile _ DEBUG_DISPLAY
125126

126127
#include "UnityCG.cginc"
127128
#include "UnityUI.cginc"
128129
#include "TMPro_Properties.cginc"
129130
#include "TMPro.cginc"
130131

132+
#if defined(DEBUG_DISPLAY)
133+
#include "Debugging2D.cginc"
134+
#endif
135+
131136
struct vertex_t
132137
{
133138
UNITY_VERTEX_INPUT_INSTANCE_ID
@@ -305,6 +310,12 @@ SubShader {
305310
clip(faceColor.a - 0.001);
306311
#endif
307312

313+
#if defined(DEBUG_DISPLAY)
314+
fixed4 debugColor = 0;
315+
if(CanDebugOverrideOutputColor(debugColor))
316+
return debugColor;
317+
#endif
318+
308319
return faceColor * input.color.a;
309320
}
310321
ENDCG

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/TextMesh Pro/Shaders/TMP_SDF-Mobile Masking.shader

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ SubShader {
9393

9494
#pragma multi_compile __ UNITY_UI_CLIP_RECT
9595
#pragma multi_compile __ UNITY_UI_ALPHACLIP
96-
96+
#pragma multi_compile _ DEBUG_DISPLAY
9797

9898
#include "UnityCG.cginc"
9999
#include "UnityUI.cginc"
100100
#include "TMPro_Properties.cginc"
101101

102+
#if defined(DEBUG_DISPLAY)
103+
#include "Debugging2D.cginc"
104+
#endif
105+
102106
struct vertex_t
103107
{
104108
float4 vertex : POSITION;
@@ -243,6 +247,12 @@ SubShader {
243247
clip(c.a - 0.001);
244248
#endif
245249

250+
#if defined(DEBUG_DISPLAY)
251+
fixed4 debugColor = 0;
252+
if(CanDebugOverrideOutputColor(debugColor))
253+
return debugColor;
254+
#endif
255+
246256
return c;
247257
}
248258
ENDCG

0 commit comments

Comments
 (0)