-
Notifications
You must be signed in to change notification settings - Fork 869
Expand file tree
/
Copy pathShaderPreprocessor.cs
More file actions
1116 lines (964 loc) · 52.1 KB
/
ShaderPreprocessor.cs
File metadata and controls
1116 lines (964 loc) · 52.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
#if XR_MANAGEMENT_4_0_1_OR_NEWER
using UnityEditor.XR.Management;
#endif
namespace UnityEditor.Rendering.Universal
{
[Flags]
enum ShaderFeatures : long
{
None = 0,
MainLight = (1L << 0),
MainLightShadows = (1L << 1),
AdditionalLights = (1L << 2),
AdditionalLightShadows = (1L << 3),
VertexLighting = (1L << 4),
SoftShadows = (1L << 5),
MixedLighting = (1L << 6),
TerrainHoles = (1L << 7),
DeferredShading = (1L << 8), // DeferredRenderer is in the list of renderer
AccurateGbufferNormals = (1L << 9),
ScreenSpaceOcclusion = (1L << 10),
ScreenSpaceShadows = (1L << 11),
UseFastSRGBLinearConversion = (1L << 12),
LightLayers = (1L << 13),
ReflectionProbeBlending = (1L << 14),
ReflectionProbeBoxProjection = (1L << 15),
DBufferMRT1 = (1L << 16),
DBufferMRT2 = (1L << 17),
DBufferMRT3 = (1L << 18),
DecalScreenSpace = (1L << 19),
DecalGBuffer = (1L << 20),
DecalNormalBlendLow = (1L << 21),
DecalNormalBlendMedium = (1L << 22),
DecalNormalBlendHigh = (1L << 23),
ForwardPlus = (1L << 24),
RenderPassEnabled = (1L << 25),
MainLightShadowsCascade = (1L << 26),
DrawProcedural = (1L << 27),
ScreenSpaceOcclusionAfterOpaque = (1L << 28),
AdditionalLightsKeepOffVariants = (1L << 29),
ShadowsKeepOffVariants = (1L << 30),
LODCrossFade = (1L << 31),
DecalLayers = (1L << 32),
OpaqueWriteRenderingLayers = (1L << 33),
GBufferWriteRenderingLayers = (1L << 34),
DepthNormalPassRenderingLayers = (1L << 35),
LightCookies = (1L << 36),
}
[Flags]
enum VolumeFeatures
{
None = 0,
Calculated = (1 << 0),
LensDistortion = (1 << 1),
Bloom = (1 << 2),
ChromaticAberration = (1 << 3),
ToneMaping = (1 << 4),
FilmGrain = (1 << 5),
DepthOfField = (1 << 6),
CameraMotionBlur = (1 << 7),
PaniniProjection = (1 << 8),
}
internal class ShaderPreprocessor : IShaderVariantStripper, IShaderVariantStripperScope
{
public static readonly string kPassNameGBuffer = "GBuffer";
public static readonly string kPassNameForwardLit = "ForwardLit";
public static readonly string kPassNameDepthNormals = "DepthNormals";
public static readonly string kTerrainShaderName = "Universal Render Pipeline/Terrain/Lit";
LocalKeyword m_MainLightShadows;
LocalKeyword m_MainLightShadowsCascades;
LocalKeyword m_MainLightShadowsScreen;
LocalKeyword m_AdditionalLightsVertex;
LocalKeyword m_AdditionalLightsPixel;
LocalKeyword m_AdditionalLightShadows;
LocalKeyword m_ReflectionProbeBlending;
LocalKeyword m_ReflectionProbeBoxProjection;
LocalKeyword m_CastingPunctualLightShadow;
LocalKeyword m_SoftShadows;
LocalKeyword m_MixedLightingSubtractive;
LocalKeyword m_LightmapShadowMixing;
LocalKeyword m_ShadowsShadowMask;
LocalKeyword m_Lightmap;
LocalKeyword m_DynamicLightmap;
LocalKeyword m_DirectionalLightmap;
LocalKeyword m_AlphaTestOn;
LocalKeyword m_DeferredStencil;
LocalKeyword m_GbufferNormalsOct;
LocalKeyword m_ScreenSpaceOcclusion;
LocalKeyword m_UseFastSRGBLinearConversion;
LocalKeyword m_LightLayers;
LocalKeyword m_DecalLayers;
LocalKeyword m_WriteRenderingLayers;
LocalKeyword m_RenderPassEnabled;
LocalKeyword m_DebugDisplay;
LocalKeyword m_DBufferMRT1;
LocalKeyword m_DBufferMRT2;
LocalKeyword m_DBufferMRT3;
LocalKeyword m_DecalNormalBlendLow;
LocalKeyword m_DecalNormalBlendMedium;
LocalKeyword m_DecalNormalBlendHigh;
LocalKeyword m_ForwardPlus;
LocalKeyword m_FoveatedRenderingNonUniformRaster;
LocalKeyword m_EditorVisualization;
LocalKeyword m_LODFadeCrossFade;
LocalKeyword m_LightCookies;
LocalKeyword m_LocalDetailMulx2;
LocalKeyword m_LocalDetailScaled;
LocalKeyword m_LocalClearCoat;
LocalKeyword m_LocalClearCoatMap;
LocalKeyword m_LensDistortion;
LocalKeyword m_ChromaticAberration;
LocalKeyword m_BloomLQ;
LocalKeyword m_BloomHQ;
LocalKeyword m_BloomLQDirt;
LocalKeyword m_BloomHQDirt;
LocalKeyword m_HdrGrading;
LocalKeyword m_ToneMapACES;
LocalKeyword m_ToneMapNeutral;
LocalKeyword m_FilmGrain;
LocalKeyword m_ScreenCoordOverride;
Shader m_BokehDepthOfField = Shader.Find("Hidden/Universal Render Pipeline/BokehDepthOfField");
Shader m_GaussianDepthOfField = Shader.Find("Hidden/Universal Render Pipeline/GaussianDepthOfField");
Shader m_CameraMotionBlur = Shader.Find("Hidden/Universal Render Pipeline/CameraMotionBlur");
Shader m_PaniniProjection = Shader.Find("Hidden/Universal Render Pipeline/PaniniProjection");
Shader m_Bloom = Shader.Find("Hidden/Universal Render Pipeline/Bloom");
Shader StencilDeferred = Shader.Find("Hidden/Universal Render Pipeline/StencilDeferred");
LocalKeyword TryGetLocalKeyword(Shader shader, string name)
{
return shader.keywordSpace.FindKeyword(name);
}
public void InitializeLocalShaderKeywords([DisallowNull] Shader shader)
{
m_MainLightShadows = TryGetLocalKeyword(shader, ShaderKeywordStrings.MainLightShadows);
m_MainLightShadowsCascades = TryGetLocalKeyword(shader, ShaderKeywordStrings.MainLightShadowCascades);
m_MainLightShadowsScreen = TryGetLocalKeyword(shader, ShaderKeywordStrings.MainLightShadowScreen);
m_AdditionalLightsVertex = TryGetLocalKeyword(shader, ShaderKeywordStrings.AdditionalLightsVertex);
m_AdditionalLightsPixel = TryGetLocalKeyword(shader, ShaderKeywordStrings.AdditionalLightsPixel);
m_AdditionalLightShadows = TryGetLocalKeyword(shader, ShaderKeywordStrings.AdditionalLightShadows);
m_ReflectionProbeBlending = TryGetLocalKeyword(shader, ShaderKeywordStrings.ReflectionProbeBlending);
m_ReflectionProbeBoxProjection = TryGetLocalKeyword(shader, ShaderKeywordStrings.ReflectionProbeBoxProjection);
m_CastingPunctualLightShadow = TryGetLocalKeyword(shader, ShaderKeywordStrings.CastingPunctualLightShadow);
m_SoftShadows = TryGetLocalKeyword(shader, ShaderKeywordStrings.SoftShadows);
m_MixedLightingSubtractive = TryGetLocalKeyword(shader, ShaderKeywordStrings.MixedLightingSubtractive);
m_LightmapShadowMixing = TryGetLocalKeyword(shader, ShaderKeywordStrings.LightmapShadowMixing);
m_ShadowsShadowMask = TryGetLocalKeyword(shader, ShaderKeywordStrings.ShadowsShadowMask);
m_Lightmap = TryGetLocalKeyword(shader, ShaderKeywordStrings.LIGHTMAP_ON);
m_DynamicLightmap = TryGetLocalKeyword(shader, ShaderKeywordStrings.DYNAMICLIGHTMAP_ON);
m_DirectionalLightmap = TryGetLocalKeyword(shader, ShaderKeywordStrings.DIRLIGHTMAP_COMBINED);
m_AlphaTestOn = TryGetLocalKeyword(shader, ShaderKeywordStrings._ALPHATEST_ON);
m_DeferredStencil = TryGetLocalKeyword(shader, ShaderKeywordStrings._DEFERRED_STENCIL);
m_GbufferNormalsOct = TryGetLocalKeyword(shader, ShaderKeywordStrings._GBUFFER_NORMALS_OCT);
m_ScreenSpaceOcclusion = TryGetLocalKeyword(shader, ShaderKeywordStrings.ScreenSpaceOcclusion);
m_UseFastSRGBLinearConversion = TryGetLocalKeyword(shader, ShaderKeywordStrings.UseFastSRGBLinearConversion);
m_LightLayers = TryGetLocalKeyword(shader, ShaderKeywordStrings.LightLayers);
m_DecalLayers = TryGetLocalKeyword(shader, ShaderKeywordStrings.DecalLayers);
m_WriteRenderingLayers = TryGetLocalKeyword(shader, ShaderKeywordStrings.WriteRenderingLayers);
m_RenderPassEnabled = TryGetLocalKeyword(shader, ShaderKeywordStrings.RenderPassEnabled);
m_DebugDisplay = TryGetLocalKeyword(shader, ShaderKeywordStrings.DEBUG_DISPLAY);
m_DBufferMRT1 = TryGetLocalKeyword(shader, ShaderKeywordStrings.DBufferMRT1);
m_DBufferMRT2 = TryGetLocalKeyword(shader, ShaderKeywordStrings.DBufferMRT2);
m_DBufferMRT3 = TryGetLocalKeyword(shader, ShaderKeywordStrings.DBufferMRT3);
m_DecalNormalBlendLow = TryGetLocalKeyword(shader, ShaderKeywordStrings.DecalNormalBlendLow);
m_DecalNormalBlendMedium = TryGetLocalKeyword(shader, ShaderKeywordStrings.DecalNormalBlendMedium);
m_DecalNormalBlendHigh = TryGetLocalKeyword(shader, ShaderKeywordStrings.DecalNormalBlendHigh);
m_ForwardPlus = TryGetLocalKeyword(shader, ShaderKeywordStrings.ForwardPlus);
m_FoveatedRenderingNonUniformRaster = TryGetLocalKeyword(shader, ShaderKeywordStrings.FoveatedRenderingNonUniformRaster);
m_EditorVisualization = TryGetLocalKeyword(shader, ShaderKeywordStrings.EDITOR_VISUALIZATION);
m_LODFadeCrossFade = TryGetLocalKeyword(shader, ShaderKeywordStrings.LOD_FADE_CROSSFADE);
m_LightCookies = TryGetLocalKeyword(shader, ShaderKeywordStrings.LightCookies);
m_LocalDetailMulx2 = TryGetLocalKeyword(shader, ShaderKeywordStrings._DETAIL_MULX2);
m_LocalDetailScaled = TryGetLocalKeyword(shader, ShaderKeywordStrings._DETAIL_SCALED);
m_LocalClearCoat = TryGetLocalKeyword(shader, ShaderKeywordStrings._CLEARCOAT);
m_LocalClearCoatMap = TryGetLocalKeyword(shader, ShaderKeywordStrings._CLEARCOATMAP);
// Post processing
m_LensDistortion = TryGetLocalKeyword(shader, ShaderKeywordStrings.Distortion);
m_ChromaticAberration = TryGetLocalKeyword(shader, ShaderKeywordStrings.ChromaticAberration);
m_BloomLQ = TryGetLocalKeyword(shader, ShaderKeywordStrings.BloomLQ);
m_BloomHQ = TryGetLocalKeyword(shader, ShaderKeywordStrings.BloomHQ);
m_BloomLQDirt = TryGetLocalKeyword(shader, ShaderKeywordStrings.BloomLQDirt);
m_BloomHQDirt = TryGetLocalKeyword(shader, ShaderKeywordStrings.BloomHQDirt);
m_HdrGrading = TryGetLocalKeyword(shader, ShaderKeywordStrings.HDRGrading);
m_ToneMapACES = TryGetLocalKeyword(shader, ShaderKeywordStrings.TonemapACES);
m_ToneMapNeutral = TryGetLocalKeyword(shader, ShaderKeywordStrings.TonemapNeutral);
m_FilmGrain = TryGetLocalKeyword(shader, ShaderKeywordStrings.FilmGrain);
m_ScreenCoordOverride = TryGetLocalKeyword(shader, ShaderKeywordStrings.SCREEN_COORD_OVERRIDE);
}
bool IsFeatureEnabled(ShaderFeatures featureMask, ShaderFeatures feature)
{
return (featureMask & feature) != 0;
}
bool IsFeatureEnabled(VolumeFeatures featureMask, VolumeFeatures feature)
{
return (featureMask & feature) != 0;
}
bool IsGLDevice(ShaderCompilerData compilerData)
{
return compilerData.shaderCompilerPlatform == ShaderCompilerPlatform.GLES20 ||
compilerData.shaderCompilerPlatform == ShaderCompilerPlatform.GLES3x ||
compilerData.shaderCompilerPlatform == ShaderCompilerPlatform.OpenGLCore;
}
bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
// Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission.
if (snippetData.passType == PassType.Meta)
{
if (SupportedRenderingFeatures.active.enlighten == false ||
((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0)
return true;
}
if (snippetData.passType == PassType.ShadowCaster)
if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) && !IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows))
return true;
// Do not strip GL passes as there are only screen space forward
if (compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.GLES3x &&
compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.GLES20 &&
compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.OpenGLCore)
{
// DBuffer
if (snippetData.passName == DecalShaderPassNames.DBufferMesh || snippetData.passName == DecalShaderPassNames.DBufferProjector ||
snippetData.passName == DecalShaderPassNames.DecalMeshForwardEmissive || snippetData.passName == DecalShaderPassNames.DecalProjectorForwardEmissive)
if (!IsFeatureEnabled(features, ShaderFeatures.DBufferMRT1) && !IsFeatureEnabled(features, ShaderFeatures.DBufferMRT2) && !IsFeatureEnabled(features, ShaderFeatures.DBufferMRT3))
return true;
// Decal Screen Space
if (snippetData.passName == DecalShaderPassNames.DecalScreenSpaceMesh || snippetData.passName == DecalShaderPassNames.DecalScreenSpaceProjector)
if (!IsFeatureEnabled(features, ShaderFeatures.DecalScreenSpace))
return true;
// Decal GBuffer
if (snippetData.passName == DecalShaderPassNames.DecalGBufferMesh || snippetData.passName == DecalShaderPassNames.DecalGBufferProjector)
if (!IsFeatureEnabled(features, ShaderFeatures.DecalGBuffer))
return true;
}
return false;
}
struct StripTool<T> where T : System.Enum
{
T m_Features;
Shader m_Shader;
ShaderKeywordSet m_KeywordSet;
ShaderSnippetData m_SnippetData;
ShaderCompilerPlatform m_ShaderCompilerPlatform;
bool m_stripUnusedVariants;
public StripTool(T features, Shader shader, ShaderSnippetData snippetData, in ShaderKeywordSet keywordSet, bool stripUnusedVariants, ShaderCompilerPlatform shaderCompilerPlatform)
{
m_Features = features;
m_Shader = shader;
m_SnippetData = snippetData;
m_KeywordSet = keywordSet;
m_stripUnusedVariants = stripUnusedVariants;
m_ShaderCompilerPlatform = shaderCompilerPlatform;
}
bool ContainsKeyword(in LocalKeyword kw)
{
return ShaderUtil.PassHasKeyword(m_Shader, m_SnippetData.pass, kw, m_SnippetData.shaderType, m_ShaderCompilerPlatform);
}
public bool StripMultiCompileKeepOffVariant(in LocalKeyword kw, T feature, in LocalKeyword kw2, T feature2, in LocalKeyword kw3, T feature3)
{
if (StripMultiCompileKeepOffVariant(kw, feature))
return true;
if (StripMultiCompileKeepOffVariant(kw2, feature2))
return true;
if (StripMultiCompileKeepOffVariant(kw3, feature3))
return true;
return false;
}
public bool StripMultiCompile(in LocalKeyword kw, T feature, in LocalKeyword kw2, T feature2, in LocalKeyword kw3, T feature3)
{
if (StripMultiCompileKeepOffVariant(kw, feature, kw2, feature2, kw3, feature3))
return true;
bool containsKeywords = ContainsKeyword(kw) && ContainsKeyword(kw2) && ContainsKeyword(kw3);
bool keywordsDisabled = !m_KeywordSet.IsEnabled(kw) && !m_KeywordSet.IsEnabled(kw2) && !m_KeywordSet.IsEnabled(kw3);
bool hasAnyFeatureEnabled = m_Features.HasFlag(feature) || m_Features.HasFlag(feature2) || m_Features.HasFlag(feature3);
return m_stripUnusedVariants && containsKeywords && keywordsDisabled && hasAnyFeatureEnabled;
}
public bool StripMultiCompileKeepOffVariant(in LocalKeyword kw, T feature, in LocalKeyword kw2, T feature2)
{
if (StripMultiCompileKeepOffVariant(kw, feature))
return true;
if (StripMultiCompileKeepOffVariant(kw2, feature2))
return true;
return false;
}
public bool StripMultiCompile(in LocalKeyword kw, T feature, in LocalKeyword kw2, T feature2)
{
if (StripMultiCompileKeepOffVariant(kw, feature, kw2, feature2))
return true;
bool containsKeywords = ContainsKeyword(kw) && ContainsKeyword(kw2);
bool keywordsDisabled = !m_KeywordSet.IsEnabled(kw) && !m_KeywordSet.IsEnabled(kw2);
bool hasAnyFeatureEnabled = m_Features.HasFlag(feature) || m_Features.HasFlag(feature2);
return m_stripUnusedVariants && containsKeywords && keywordsDisabled && hasAnyFeatureEnabled;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool StripMultiCompileKeepOffVariant(in LocalKeyword kw, T feature)
{
return !m_Features.HasFlag(feature) && m_KeywordSet.IsEnabled(kw);
}
public bool StripMultiCompile(in LocalKeyword kw, T feature)
{
if (!m_Features.HasFlag(feature))
{
if (m_KeywordSet.IsEnabled(kw))
return true;
}
else if (m_stripUnusedVariants)
{
if (!m_KeywordSet.IsEnabled(kw) && ContainsKeyword(kw))
return true;
}
return false;
}
}
bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
var globalSettings = UniversalRenderPipelineGlobalSettings.instance;
bool stripDebugDisplayShaders = !Debug.isDebugBuild || (globalSettings == null || globalSettings.stripDebugVariants);
#if XR_MANAGEMENT_4_0_1_OR_NEWER
var buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Standalone);
if (buildTargetSettings != null && buildTargetSettings.AssignedSettings != null && buildTargetSettings.AssignedSettings.activeLoaders.Count > 0)
{
stripDebugDisplayShaders = true;
}
// XRTODO: We need to figure out what's the proper way to detect HL target platform when building. For now, HL is the only XR platform available on WSA so we assume this case targets HL platform.
var wsaTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.WSA);
if (wsaTargetSettings != null && wsaTargetSettings.AssignedSettings != null && wsaTargetSettings.AssignedSettings.activeLoaders.Count > 0)
{
// Due to the performance consideration, keep addtional light off variant to avoid extra ALU cost related to dummy additional light handling.
features |= ShaderFeatures.AdditionalLightsKeepOffVariants;
}
var questTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Android);
if (questTargetSettings != null && questTargetSettings.AssignedSettings != null && questTargetSettings.AssignedSettings.activeLoaders.Count > 0)
{
// Due to the performance consideration, keep addtional light off variant to avoid extra ALU cost related to dummy additional light handling.
features |= ShaderFeatures.AdditionalLightsKeepOffVariants;
}
#endif
if (stripDebugDisplayShaders && compilerData.shaderKeywordSet.IsEnabled(m_DebugDisplay))
{
return true;
}
if (globalSettings != null && globalSettings.stripScreenCoordOverrideVariants && compilerData.shaderKeywordSet.IsEnabled(m_ScreenCoordOverride))
{
return true;
}
var stripUnusedVariants = UniversalRenderPipelineGlobalSettings.instance?.stripUnusedVariants == true;
var stripTool = new StripTool<ShaderFeatures>(features, shader, snippetData, compilerData.shaderKeywordSet, stripUnusedVariants, compilerData.shaderCompilerPlatform);
// strip main light shadows, cascade and screen variants
if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(
m_MainLightShadows, ShaderFeatures.MainLightShadows,
m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade,
m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows))
return true;
}
else
{
if (stripTool.StripMultiCompile(
m_MainLightShadows, ShaderFeatures.MainLightShadows,
m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade,
m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows))
return true;
}
// TODO: Strip off variants once we have global soft shadows option for forcing instead as support
if (stripTool.StripMultiCompileKeepOffVariant(m_SoftShadows, ShaderFeatures.SoftShadows))
return true;
// Left for backward compatibility
if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) &&
!IsFeatureEnabled(features, ShaderFeatures.MixedLighting))
return true;
if (stripTool.StripMultiCompile(m_UseFastSRGBLinearConversion, ShaderFeatures.UseFastSRGBLinearConversion))
return true;
// Strip here only if mixed lighting is disabled
// No need to check here if actually used by scenes as this taken care by builtin stripper
if ((compilerData.shaderKeywordSet.IsEnabled(m_LightmapShadowMixing) ||
compilerData.shaderKeywordSet.IsEnabled(m_ShadowsShadowMask)) &&
!IsFeatureEnabled(features, ShaderFeatures.MixedLighting))
return true;
if (compilerData.shaderCompilerPlatform == ShaderCompilerPlatform.GLES20)
{
// GLES2 does not support bitwise operations.
if (compilerData.shaderKeywordSet.IsEnabled(m_LightLayers))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_LightLayers, ShaderFeatures.LightLayers))
return true;
}
if (stripTool.StripMultiCompile(m_RenderPassEnabled, ShaderFeatures.RenderPassEnabled))
return true;
// No additional light shadows
if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows))
return true;
}
if (stripTool.StripMultiCompile(m_ReflectionProbeBlending, ShaderFeatures.ReflectionProbeBlending))
return true;
if (stripTool.StripMultiCompile(m_ReflectionProbeBoxProjection, ShaderFeatures.ReflectionProbeBoxProjection))
return true;
// Shadow caster punctual light strip
if (snippetData.passType == PassType.ShadowCaster && ShaderUtil.PassHasKeyword(shader, snippetData.pass, m_CastingPunctualLightShadow, snippetData.shaderType, compilerData.shaderCompilerPlatform))
{
if (!IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows) && compilerData.shaderKeywordSet.IsEnabled(m_CastingPunctualLightShadow))
return true;
bool mainLightShadows =
!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) &&
!IsFeatureEnabled(features, ShaderFeatures.MainLightShadowsCascade) &&
!IsFeatureEnabled(features, ShaderFeatures.ScreenSpaceShadows);
if (mainLightShadows && !compilerData.shaderKeywordSet.IsEnabled(m_CastingPunctualLightShadow))
return true;
}
// Additional light are shaded per-vertex or per-pixel.
if (IsFeatureEnabled(ShaderFeatures.AdditionalLightsKeepOffVariants, features))
{
if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting,
m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting,
m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights))
return true;
}
if (stripTool.StripMultiCompile(m_ForwardPlus, ShaderFeatures.ForwardPlus))
return true;
// Strip Foveated Rendering variants on all platforms (except PS5)
// TODO: add a way to communicate this requirement from the xr plugin directly
#if ENABLE_VR && ENABLE_XR_MODULE
if (compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.PS5NGGC)
#endif
{
if (compilerData.shaderKeywordSet.IsEnabled(m_FoveatedRenderingNonUniformRaster))
return true;
}
// Screen Space Occlusion
if (IsFeatureEnabled(features, ShaderFeatures.ScreenSpaceOcclusionAfterOpaque))
{
// SSAO after opaque setting requires off variants
if (stripTool.StripMultiCompileKeepOffVariant(m_ScreenSpaceOcclusion, ShaderFeatures.ScreenSpaceOcclusion))
return true;
}
else
{
if (stripTool.StripMultiCompile(m_ScreenSpaceOcclusion, ShaderFeatures.ScreenSpaceOcclusion))
return true;
}
if (IsGLDevice(compilerData))
{
// Decal DBuffer is not supported on gl
if (compilerData.shaderKeywordSet.IsEnabled(m_DBufferMRT1) ||
compilerData.shaderKeywordSet.IsEnabled(m_DBufferMRT2) ||
compilerData.shaderKeywordSet.IsEnabled(m_DBufferMRT3))
return true;
}
else
{
// Decal DBuffer
if (stripTool.StripMultiCompile(
m_DBufferMRT1, ShaderFeatures.DBufferMRT1,
m_DBufferMRT2, ShaderFeatures.DBufferMRT2,
m_DBufferMRT3, ShaderFeatures.DBufferMRT3))
return true;
}
if (IsGLDevice(compilerData))
{
// Rendering layers are not supported on gl
if (compilerData.shaderKeywordSet.IsEnabled(m_DecalLayers))
return true;
}
else
{
// Decal Layers
if (stripTool.StripMultiCompile(m_DecalLayers, ShaderFeatures.DecalLayers))
return true;
}
// TODO: Test against lightMode tag instead.
if (snippetData.passName == kPassNameGBuffer)
{
if (!IsFeatureEnabled(features, ShaderFeatures.DeferredShading))
return true;
}
// Do not strip accurateGbufferNormals on Mobile Vulkan as some GPUs do not support R8G8B8A8_SNorm, which then force us to use accurateGbufferNormals
if (compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.Vulkan &&
stripTool.StripMultiCompile(m_GbufferNormalsOct, ShaderFeatures.AccurateGbufferNormals))
return true;
// Decal Normal Blend
if (stripTool.StripMultiCompile(
m_DecalNormalBlendLow, ShaderFeatures.DecalNormalBlendLow,
m_DecalNormalBlendMedium, ShaderFeatures.DecalNormalBlendMedium,
m_DecalNormalBlendHigh, ShaderFeatures.DecalNormalBlendHigh))
return true;
var stripUnusedLODCrossFadeVariants = UniversalRenderPipelineGlobalSettings.instance?.stripUnusedLODCrossFadeVariants == true;
if (stripUnusedLODCrossFadeVariants &&
stripTool.StripMultiCompileKeepOffVariant(m_LODFadeCrossFade, ShaderFeatures.LODCrossFade))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_LightCookies, ShaderFeatures.LightCookies))
return true;
string keywordNames = "";
foreach (var keyword in compilerData.shaderKeywordSet.GetShaderKeywords())
{
keywordNames += " " + keyword.name;
}
// Write Rendering Layers
if (IsGLDevice(compilerData))
{
// Rendering layers are not supported on gl
if (compilerData.shaderKeywordSet.IsEnabled(m_WriteRenderingLayers))
return true;
}
else
{
if (snippetData.passName == kPassNameDepthNormals)
{
if (stripTool.StripMultiCompile(m_WriteRenderingLayers, ShaderFeatures.DepthNormalPassRenderingLayers))
return true;
}
if (snippetData.passName == kPassNameForwardLit)
{
if (stripTool.StripMultiCompile(m_WriteRenderingLayers, ShaderFeatures.OpaqueWriteRenderingLayers))
return true;
}
if (snippetData.passName == kPassNameGBuffer)
{
if (stripTool.StripMultiCompile(m_WriteRenderingLayers, ShaderFeatures.GBufferWriteRenderingLayers))
return true;
}
}
return false;
}
bool StripVolumeFeatures(VolumeFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
var stripUnusedVariants = UniversalRenderPipelineGlobalSettings.instance?.stripUnusedVariants == true;
var stripTool = new StripTool<VolumeFeatures>(features, shader, snippetData, compilerData.shaderKeywordSet, stripUnusedVariants, compilerData.shaderCompilerPlatform);
if (stripTool.StripMultiCompileKeepOffVariant(m_LensDistortion, VolumeFeatures.LensDistortion))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_ChromaticAberration, VolumeFeatures.ChromaticAberration))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_BloomLQ, VolumeFeatures.Bloom))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_BloomHQ, VolumeFeatures.Bloom))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_BloomLQDirt, VolumeFeatures.Bloom))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_BloomHQDirt, VolumeFeatures.Bloom))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_HdrGrading, VolumeFeatures.ToneMaping))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_ToneMapACES, VolumeFeatures.ToneMaping))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_ToneMapNeutral, VolumeFeatures.ToneMaping))
return true;
if (stripTool.StripMultiCompileKeepOffVariant(m_FilmGrain, VolumeFeatures.FilmGrain))
return true;
// Strip post processing shaders
if (shader == m_BokehDepthOfField && !IsFeatureEnabled(ShaderBuildPreprocessor.volumeFeatures, VolumeFeatures.DepthOfField))
return true;
if (shader == m_GaussianDepthOfField && !IsFeatureEnabled(ShaderBuildPreprocessor.volumeFeatures, VolumeFeatures.DepthOfField))
return true;
if (shader == m_CameraMotionBlur && !IsFeatureEnabled(ShaderBuildPreprocessor.volumeFeatures, VolumeFeatures.CameraMotionBlur))
return true;
if (shader == m_PaniniProjection && !IsFeatureEnabled(ShaderBuildPreprocessor.volumeFeatures, VolumeFeatures.PaniniProjection))
return true;
if (shader == m_Bloom && !IsFeatureEnabled(ShaderBuildPreprocessor.volumeFeatures, VolumeFeatures.Bloom))
return true;
return false;
}
bool StripUnsupportedVariants(ShaderCompilerData compilerData)
{
// We can strip variants that have directional lightmap enabled but not static nor dynamic lightmap.
if (compilerData.shaderKeywordSet.IsEnabled(m_DirectionalLightmap) &&
!(compilerData.shaderKeywordSet.IsEnabled(m_Lightmap) ||
compilerData.shaderKeywordSet.IsEnabled(m_DynamicLightmap)))
return true;
// As GLES2 has low amount of registers, we strip:
if (compilerData.shaderCompilerPlatform == ShaderCompilerPlatform.GLES20)
{
// Cascade shadows
if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadowsCascades))
return true;
// Screen space shadows
if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadowsScreen))
return true;
// Detail
if (compilerData.shaderKeywordSet.IsEnabled(m_LocalDetailMulx2) || compilerData.shaderKeywordSet.IsEnabled(m_LocalDetailScaled))
return true;
// Clear Coat
if (compilerData.shaderKeywordSet.IsEnabled(m_LocalClearCoat) || compilerData.shaderKeywordSet.IsEnabled(m_LocalClearCoatMap))
return true;
}
// Editor visualization is only used in scene view debug modes.
return compilerData.shaderKeywordSet.IsEnabled(m_EditorVisualization);
}
bool StripInvalidVariants(ShaderCompilerData compilerData)
{
bool isMainShadowNoCascades = compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadows);
bool isMainShadowCascades = compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadowsCascades);
bool isMainShadowScreen = compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadowsScreen);
bool isMainShadow = isMainShadowNoCascades || isMainShadowCascades || isMainShadowScreen;
bool isAdditionalShadow = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);
if (isAdditionalShadow && !(compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel) || compilerData.shaderKeywordSet.IsEnabled(m_ForwardPlus) || compilerData.shaderKeywordSet.IsEnabled(m_DeferredStencil)))
return true;
bool isShadowVariant = isMainShadow || isAdditionalShadow;
return !isShadowVariant && compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows);
}
bool StripUnusedShaders(ShaderFeatures features, Shader shader)
{
if (!IsFeatureEnabled(features, ShaderFeatures.DeferredShading))
{
if (shader == StencilDeferred)
return true;
}
return false;
}
bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
if (StripUnusedFeatures(features, shader, snippetData, compilerData))
return true;
if (StripInvalidVariants(compilerData))
return true;
if (StripUnsupportedVariants(compilerData))
return true;
if (StripUnusedPass(features, snippetData, compilerData))
return true;
if (UniversalRenderPipelineGlobalSettings.instance?.stripUnusedVariants == true)
{
if (StripUnusedShaders(features, shader))
return true;
}
// Strip terrain holes
// TODO: checking for the string name here is expensive
// maybe we can rename alpha clip keyword name to be specific to terrain?
return compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
!IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) &&
shader.name.Contains(kTerrainShaderName);
}
public bool active => UniversalRenderPipeline.asset != null;
public bool CanRemoveVariant([DisallowNull] Shader shader, ShaderSnippetData shaderVariant, ShaderCompilerData shaderCompilerData)
{
bool removeInput = true;
foreach (var supportedFeatures in ShaderBuildPreprocessor.supportedFeaturesList)
{
if (!StripUnused(supportedFeatures, shader, shaderVariant, shaderCompilerData))
{
removeInput = false;
break;
}
}
if (UniversalRenderPipelineGlobalSettings.instance?.stripUnusedPostProcessingVariants == true)
{
if (!removeInput && StripVolumeFeatures(ShaderBuildPreprocessor.volumeFeatures, shader,
shaderVariant, shaderCompilerData))
{
removeInput = true;
}
}
return removeInput;
}
public void BeforeShaderStripping(Shader shader)
{
InitializeLocalShaderKeywords(shader);
}
public void AfterShaderStripping(Shader shader) {}
}
class ShaderBuildPreprocessor : IPreprocessBuildWithReport
#if PROFILE_BUILD
, IPostprocessBuildWithReport
#endif
{
public static List<ShaderFeatures> supportedFeaturesList
{
get
{
if (s_SupportedFeaturesList.Count == 0)
FetchAllSupportedFeatures();
return s_SupportedFeaturesList;
}
}
private static List<ShaderFeatures> s_SupportedFeaturesList = new List<ShaderFeatures>();
public static VolumeFeatures volumeFeatures
{
get
{
if (s_VolumeFeatures == VolumeFeatures.None)
FetchAllSupportedFeaturesFromVolumes();
return s_VolumeFeatures;
}
}
private static VolumeFeatures s_VolumeFeatures;
public int callbackOrder { get { return 0; } }
#if PROFILE_BUILD
public void OnPostprocessBuild(BuildReport report)
{
Profiler.enabled = false;
}
#endif
public void OnPreprocessBuild(BuildReport report)
{
FetchAllSupportedFeatures();
FetchAllSupportedFeaturesFromVolumes();
#if PROFILE_BUILD
Profiler.enableBinaryLog = true;
Profiler.logFile = "profilerlog.raw";
Profiler.enabled = true;
#endif
}
private static void FetchAllSupportedFeatures()
{
using (ListPool<UniversalRenderPipelineAsset>.Get(out var urps))
{
EditorUserBuildSettings.activeBuildTarget.TryGetRenderPipelineAssets(urps);
s_SupportedFeaturesList.Clear();
foreach (UniversalRenderPipelineAsset urp in urps)
{
if (urp != null)
{
int rendererCount = urp.m_RendererDataList.Length;
for (int i = 0; i < rendererCount; ++i)
s_SupportedFeaturesList.Add(GetSupportedShaderFeatures(urp, i));
}
}
}
}
private static void FetchAllSupportedFeaturesFromVolumes()
{
if (UniversalRenderPipelineGlobalSettings.instance?.stripUnusedPostProcessingVariants == false)
return;
s_VolumeFeatures = VolumeFeatures.Calculated;
var guids = AssetDatabase.FindAssets("t:VolumeProfile");
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
// We only care what is in assets folder
if (!path.StartsWith("Assets"))
continue;
var asset = AssetDatabase.LoadAssetAtPath<VolumeProfile>(path);
if (asset == null)
continue;
if (asset.Has<LensDistortion>())
s_VolumeFeatures |= VolumeFeatures.LensDistortion;
if (asset.Has<Bloom>())
s_VolumeFeatures |= VolumeFeatures.Bloom;
if (asset.Has<Tonemapping>())
s_VolumeFeatures |= VolumeFeatures.ToneMaping;
if (asset.Has<FilmGrain>())
s_VolumeFeatures |= VolumeFeatures.FilmGrain;
if (asset.Has<DepthOfField>())
s_VolumeFeatures |= VolumeFeatures.DepthOfField;
if (asset.Has<MotionBlur>())
s_VolumeFeatures |= VolumeFeatures.CameraMotionBlur;
if (asset.Has<PaniniProjection>())
s_VolumeFeatures |= VolumeFeatures.PaniniProjection;
if (asset.Has<ChromaticAberration>())
s_VolumeFeatures |= VolumeFeatures.ChromaticAberration;
}
}
private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset, int rendererIndex)
{
ShaderFeatures shaderFeatures;
shaderFeatures = ShaderFeatures.MainLight;
if (pipelineAsset.supportsMainLightShadows)
{
// User can change cascade count at runtime, so we have to include both of them for now
shaderFeatures |= ShaderFeatures.MainLightShadows;
shaderFeatures |= ShaderFeatures.MainLightShadowsCascade;
}
if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
{
shaderFeatures |= ShaderFeatures.VertexLighting;
}
else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
{
shaderFeatures |= ShaderFeatures.AdditionalLights;
}
if (pipelineAsset.supportsMixedLighting)
shaderFeatures |= ShaderFeatures.MixedLighting;
if (pipelineAsset.supportsTerrainHoles)
shaderFeatures |= ShaderFeatures.TerrainHoles;
if (pipelineAsset.useFastSRGBLinearConversion)
shaderFeatures |= ShaderFeatures.UseFastSRGBLinearConversion;
if (pipelineAsset.useRenderingLayers)
shaderFeatures |= ShaderFeatures.LightLayers;
if (pipelineAsset.enableLODCrossFade)
shaderFeatures |= ShaderFeatures.LODCrossFade;
if (pipelineAsset.supportsLightCookies)
shaderFeatures |= ShaderFeatures.LightCookies;
bool hasScreenSpaceShadows = false;
bool hasScreenSpaceOcclusion = false;
bool hasDeferredRenderer = false;
bool accurateGbufferNormals = false;
bool forwardPlus = false;
bool usesRenderPass = false;
{
ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
if (renderer is UniversalRenderer)
{
UniversalRenderer universalRenderer = (UniversalRenderer)renderer;
if (universalRenderer.renderingModeRequested == RenderingMode.Deferred)
{
hasDeferredRenderer |= true;
accurateGbufferNormals |= universalRenderer.accurateGbufferNormals;
usesRenderPass |= universalRenderer.useRenderPassEnabled;
if (pipelineAsset.useRenderingLayers)
{
shaderFeatures |= ShaderFeatures.GBufferWriteRenderingLayers;
}
}
}
if (!renderer.stripShadowsOffVariants)
shaderFeatures |= ShaderFeatures.ShadowsKeepOffVariants;
if (!renderer.stripAdditionalLightOffVariants)
shaderFeatures |= ShaderFeatures.AdditionalLightsKeepOffVariants;
ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
if (rendererData != null)
{
for (int rendererFeatureIndex = 0; rendererFeatureIndex < rendererData.rendererFeatures.Count; rendererFeatureIndex++)
{
ScriptableRendererFeature rendererFeature = rendererData.rendererFeatures[rendererFeatureIndex];
ScreenSpaceShadows ssshadows = rendererFeature as ScreenSpaceShadows;
hasScreenSpaceShadows |= ssshadows != null;
// Check for Screen Space Ambient Occlusion Renderer Feature
ScreenSpaceAmbientOcclusion ssao = rendererFeature as ScreenSpaceAmbientOcclusion;
hasScreenSpaceOcclusion |= ssao != null;
if (ssao?.afterOpaque ?? false)
shaderFeatures |= ShaderFeatures.ScreenSpaceOcclusionAfterOpaque;
// Check for Decal Renderer Feature
DecalRendererFeature decal = rendererFeature as DecalRendererFeature;
if (decal != null)
{
var technique = decal.GetTechnique(renderer);
switch (technique)
{
case DecalTechnique.DBuffer:
shaderFeatures |= GetFromDecalSurfaceData(decal.GetDBufferSettings().surfaceData);
break;
case DecalTechnique.ScreenSpace:
shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
shaderFeatures |= ShaderFeatures.DecalScreenSpace;
break;
case DecalTechnique.GBuffer:
shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
shaderFeatures |= ShaderFeatures.DecalGBuffer;
//shaderFeatures |= ShaderFeatures.DecalScreenSpace; // In case deferred is not supported it will fallback to forward
break;
}
if (decal.requiresDecalLayers)
shaderFeatures |= ShaderFeatures.DecalLayers;
}
}
if (rendererData is UniversalRendererData universalRendererData)