-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathUniversalRenderPipelineAsset.cs
1990 lines (1729 loc) · 76.6 KB
/
UniversalRenderPipelineAsset.cs
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;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using System.IO;
using ShaderKeywordFilter = UnityEditor.ShaderKeywordFilter;
#endif
using System.ComponentModel;
using UnityEngine.Serialization;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering.RenderGraphModule;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// The elements in this enum define how Unity renders shadows.
/// </summary>
public enum ShadowQuality
{
/// <summary>
/// Disables the shadows.
/// </summary>
Disabled,
/// <summary>
/// Shadows have hard edges.
/// </summary>
HardShadows,
/// <summary>
/// Filtering is applied when sampling shadows. Shadows have smooth edges.
/// </summary>
SoftShadows,
}
/// <summary>
/// Softness quality of soft shadows. Higher means better quality, but lower performance.
/// </summary>
public enum SoftShadowQuality
{
/// <summary>
/// Use this to choose the setting set on the pipeline asset.
/// </summary>
[InspectorName("Use settings from Render Pipeline Asset")]
UsePipelineSettings,
/// <summary>
/// Low quality soft shadows. Recommended for mobile. 4 PCF sample filtering.
/// </summary>
Low,
/// <summary>
/// Medium quality soft shadows. The default. 5x5 tent filtering.
/// </summary>
Medium,
/// <summary>
/// High quality soft shadows. Low performance due to high sample count. 7x7 tent filtering.
/// </summary>
High,
}
/// <summary>
/// This controls the size of the shadow map texture.
/// </summary>
public enum ShadowResolution
{
/// <summary>
/// Use this for 256x256 shadow resolution.
/// </summary>
_256 = 256,
/// <summary>
/// Use this for 512x512 shadow resolution.
/// </summary>
_512 = 512,
/// <summary>
/// Use this for 1024x1024 shadow resolution.
/// </summary>
_1024 = 1024,
/// <summary>
/// Use this for 2048x2048 shadow resolution.
/// </summary>
_2048 = 2048,
/// <summary>
/// Use this for 4096x4096 shadow resolution.
/// </summary>
_4096 = 4096,
/// <summary>
/// Use this for 8192x8192 shadow resolution.
/// </summary>
_8192 = 8192,
}
/// <summary>
/// This controls the size of the Light Cookie atlas texture for additional lights (point, spot).
/// </summary>
public enum LightCookieResolution
{
/// <summary>
/// Use this for 256x256 Light Cookie resolution.
/// </summary>
_256 = 256,
/// <summary>
/// Use this for 512x512 Light Cookie resolution.
/// </summary>
_512 = 512,
/// <summary>
/// Use this for 1024x1024 Light Cookie resolution.
/// </summary>
_1024 = 1024,
/// <summary>
/// Use this for 2048x2048 Light Cookie resolution.
/// </summary>
_2048 = 2048,
/// <summary>
/// Use this for 4096x4096 Light Cookie resolution.
/// </summary>
_4096 = 4096
}
/// <summary>
/// Options for selecting the format for the Light Cookie atlas texture for additional lights (point, spot).
/// Low precision saves memory and bandwidth.
/// </summary>
public enum LightCookieFormat
{
/// <summary>
/// Use this to select Grayscale format with low precision.
/// </summary>
GrayscaleLow,
/// <summary>
/// Use this to select Grayscale format with high precision.
/// </summary>
GrayscaleHigh,
/// <summary>
/// Use this to select Color format with low precision.
/// </summary>
ColorLow,
/// <summary>
/// Use this to select Color format with high precision.
/// </summary>
ColorHigh,
/// <summary>
/// Use this to select High Dynamic Range format.
/// </summary>
ColorHDR,
}
/// <summary>
/// The default color buffer format in HDR (only).
/// Affects camera rendering and postprocessing color buffers.
/// </summary>
public enum HDRColorBufferPrecision
{
/// <summary> Typically R11G11B10f for faster rendering. Recommend for mobile.
/// R11G11B10f can cause a subtle blue/yellow banding in some rare cases due to lower precision of the blue component.</summary>
[Tooltip("Use 32-bits per pixel for HDR rendering.")]
_32Bits,
/// <summary>Typically R16G16B16A16f for better quality. Can reduce banding at the cost of memory and performance.</summary>
[Tooltip("Use 64-bits per pixel for HDR rendering.")]
_64Bits,
}
/// <summary>
/// Options for setting MSAA Quality.
/// This defines how many samples URP computes per pixel for evaluating the effect.
/// </summary>
public enum MsaaQuality
{
/// <summary>
/// Disables MSAA.
/// </summary>
Disabled = 1,
/// <summary>
/// Use this for 2 samples per pixel.
/// </summary>
_2x = 2,
/// <summary>
/// Use this for 4 samples per pixel.
/// </summary>
_4x = 4,
/// <summary>
/// Use this for 8 samples per pixel.
/// </summary>
_8x = 8
}
/// <summary>
/// Options for selecting downsampling.
/// </summary>
public enum Downsampling
{
/// <summary>
/// Use this to disable downsampling.
/// </summary>
None,
/// <summary>
/// Use this to produce a half-resolution image with bilinear filtering.
/// </summary>
_2xBilinear,
/// <summary>
/// Use this to produce a quarter-resolution image with box filtering. This produces a softly blurred copy.
/// </summary>
_4xBox,
/// <summary>
/// Use this to produce a quarter-resolution image with bi-linear filtering.
/// </summary>
_4xBilinear
}
internal enum DefaultMaterialType
{
Standard,
Particle,
Terrain,
Sprite,
UnityBuiltinDefault,
SpriteMask,
Decal
}
/// <summary>
/// Options for light rendering mode.
/// </summary>
public enum LightRenderingMode
{
/// <summary>
/// Use this to disable lighting.
/// </summary>
Disabled = 0,
/// <summary>
/// Use this to select lighting to be calculated per vertex.
/// </summary>
PerVertex = 2,
/// <summary>
/// Use this to select lighting to be calculated per pixel.
/// </summary>
PerPixel = 1,
}
/// <summary>
/// Defines if profiling is logged or not. This enum is not longer in use, use the Profiler instead.
/// </summary>
[Obsolete("PipelineDebugLevel is replaced to use the profiler and has no effect.", true)]
public enum PipelineDebugLevel
{
/// <summary>
/// Disabled logging for profiling.
/// </summary>
Disabled,
/// <summary>
/// Enabled logging for profiling.
/// </summary>
Profiling,
}
/// <summary>
/// Options to select the type of Renderer to use.
/// </summary>
public enum RendererType
{
/// <summary>
/// Use this for Custom Renderer.
/// </summary>
Custom,
/// <summary>
/// Use this for Universal Renderer.
/// </summary>
UniversalRenderer,
/// <summary>
/// Use this for 2D Renderer.
/// </summary>
_2DRenderer,
}
/// <summary>
/// Options for selecting Color Grading modes, Low Dynamic Range (LDR) or High Dynamic Range (HDR)
/// </summary>
public enum ColorGradingMode
{
/// <summary>
/// This mode follows a more classic workflow. Unity applies a limited range of color grading after tonemapping.
/// </summary>
LowDynamicRange,
/// <summary>
/// This mode works best for high precision grading similar to movie production workflows. Unity applies color grading before tonemapping.
/// </summary>
HighDynamicRange
}
/// <summary>
/// Defines if Unity discards or stores the render targets of the DrawObjects Passes. Selecting the Store option significantly increases the memory bandwidth on mobile and tile-based GPUs.
/// </summary>
public enum StoreActionsOptimization
{
/// <summary>Unity uses the Discard option by default, and falls back to the Store option if it detects any injected Passes.</summary>
Auto,
/// <summary>Unity discards the render targets of render Passes that are not reused later (lower memory bandwidth).</summary>
Discard,
/// <summary>Unity stores all render targets of each Pass (higher memory bandwidth).</summary>
Store
}
/// <summary>
/// Defines the update frequency for the Volume Framework.
/// </summary>
public enum VolumeFrameworkUpdateMode
{
/// <summary>
/// Use this to have the Volume Framework update every frame.
/// </summary>
[InspectorName("Every Frame")]
EveryFrame = 0,
/// <summary>
/// Use this to disable Volume Framework updates or to update it manually via scripting.
/// </summary>
[InspectorName("Via Scripting")]
ViaScripting = 1,
/// <summary>
/// Use this to choose the setting set on the pipeline asset.
/// </summary>
[InspectorName("Use Pipeline Settings")]
UsePipelineSettings = 2,
}
/// <summary>
/// Defines the upscaling filter selected by the user the universal render pipeline asset.
/// </summary>
public enum UpscalingFilterSelection
{
/// <summary>
/// Unity selects a filtering option automatically based on the Render Scale value and the current screen resolution.
/// </summary>
[InspectorName("Automatic"), Tooltip("Unity selects a filtering option automatically based on the Render Scale value and the current screen resolution.")]
Auto,
/// <summary>
/// Unity uses Bilinear filtering to perform upscaling.
/// </summary>
[InspectorName("Bilinear")]
Linear,
/// <summary>
/// Unity uses Nearest-Neighbour filtering to perform upscaling.
/// </summary>
[InspectorName("Nearest-Neighbor")]
Point,
/// <summary>
/// Unity uses the AMD FSR 1.0 technique to perform upscaling.
/// </summary>
[InspectorName("FidelityFX Super Resolution 1.0"), Tooltip("If the target device does not support Unity shader model 4.5, Unity falls back to the Automatic option.")]
FSR,
/// <summary>
/// Unity uses the Snapdragon Game Super Resolution technique to perform upscaling.
/// </summary>
[InspectorName("Snapdragon Game Super Resolution")]
SGSR,
/// <summary>
/// Unity uses the Spatial-Temporal Post-Processing technique to perform upscaling.
/// </summary>
[InspectorName("Spatial-Temporal Post-Processing"), Tooltip("If the target device does not support compute shaders or is running GLES, Unity falls back to the Automatic option.")]
STP
}
/// <summary>
/// Type of the LOD cross-fade.
/// </summary>
public enum LODCrossFadeDitheringType
{
/// <summary>Unity uses the Bayer matrix texture to compute the LOD cross-fade dithering.</summary>
BayerMatrix,
/// <summary>Unity uses the precomputed blue noise texture to compute the LOD cross-fade dithering.</summary>
BlueNoise
}
/// <summary>
/// The available Probe system used.
/// </summary>
public enum LightProbeSystem
{
/// <summary>The light probe group system.</summary>
[InspectorName("Light Probe Groups")]
LegacyLightProbes = 0,
/// <summary>Adaptive Probe Volumes system.</summary>
[InspectorName("Adaptive Probe Volumes")]
ProbeVolumes = 1,
}
/// <summary>
/// The type of Spherical Harmonics lighting evaluation in a shader.
/// </summary>
public enum ShEvalMode
{
/// <summary>Unity selects a mode automatically.</summary>
Auto = 0,
/// <summary>Evaluate lighting per vertex.</summary>
PerVertex = 1,
/// <summary>Evaluate lighting partially per vertex, partially per pixel.</summary>
Mixed = 2,
/// <summary>Evaluate lighting per pixel.</summary>
PerPixel = 3,
}
internal struct DeprecationMessage
{
internal const string CompatibilityScriptingAPIObsolete = "This rendering path is for compatibility mode only (when Render Graph is disabled). Use Render Graph API instead.";
internal const string CompatibilityScriptingAPIConsoleWarning = "The project currently uses the compatibility mode where the Render Graph API is disabled. Support for this mode will be removed in future Unity versions. Migrate existing ScriptableRenderPasses to the new RenderGraph API. After the migration, disable the compatibility mode in Edit > Projects Settings > Graphics > Render Graph.";
}
#if UNITY_EDITOR
internal class WarnUsingNonRenderGraph
{
[InitializeOnLoadMethod]
internal static void EmitConsoleWarning()
{
RenderGraphSettings rgs = GraphicsSettings.GetRenderPipelineSettings<RenderGraphSettings>();
if (rgs != null && rgs.enableRenderCompatibilityMode)
Debug.LogWarning(DeprecationMessage.CompatibilityScriptingAPIConsoleWarning);
}
}
#endif
/// <summary>
/// The asset that contains the URP setting.
/// You can use this asset as a graphics quality level.
/// </summary>
/// <see cref="RenderPipelineAsset"/>
/// <see cref="UniversalRenderPipeline"/>
[ExcludeFromPreset]
[URPHelpURL("universalrp-asset")]
#if UNITY_EDITOR
[ShaderKeywordFilter.ApplyRulesIfTagsEqual("RenderPipeline", "UniversalPipeline")]
#endif
public partial class UniversalRenderPipelineAsset : RenderPipelineAsset<UniversalRenderPipeline>, ISerializationCallbackReceiver, IProbeVolumeEnabledRenderPipeline, IGPUResidentRenderPipeline, IRenderGraphEnabledRenderPipeline
{
ScriptableRenderer[] m_Renderers = new ScriptableRenderer[1];
internal bool IsAtLastVersion() => k_LastVersion == k_AssetVersion;
private const int k_LastVersion = 12;
// Default values set when a new UniversalRenderPipeline asset is created
[SerializeField] int k_AssetVersion = k_LastVersion;
[SerializeField] int k_AssetPreviousVersion = k_LastVersion;
// Deprecated settings for upgrading sakes
[SerializeField] RendererType m_RendererType = RendererType.UniversalRenderer;
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use m_RendererDataList instead.")]
[SerializeField] internal ScriptableRendererData m_RendererData = null;
// Renderer settings
[SerializeField] internal ScriptableRendererData[] m_RendererDataList = new ScriptableRendererData[1];
[SerializeField] internal int m_DefaultRendererIndex = 0;
// General settings
[SerializeField] bool m_RequireDepthTexture = false;
[SerializeField] bool m_RequireOpaqueTexture = false;
[SerializeField] Downsampling m_OpaqueDownsampling = Downsampling._2xBilinear;
[SerializeField] bool m_SupportsTerrainHoles = true;
// Quality settings
[SerializeField] bool m_SupportsHDR = true;
[SerializeField] HDRColorBufferPrecision m_HDRColorBufferPrecision = HDRColorBufferPrecision._32Bits;
[SerializeField] MsaaQuality m_MSAA = MsaaQuality.Disabled;
[SerializeField] float m_RenderScale = 1.0f;
[SerializeField] UpscalingFilterSelection m_UpscalingFilter = UpscalingFilterSelection.Auto;
[SerializeField] bool m_FsrOverrideSharpness = false;
[SerializeField] float m_FsrSharpness = FSRUtils.kDefaultSharpnessLinear;
#if UNITY_EDITOR // multi_compile _ LOD_FADE_CROSSFADE
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.LOD_FADE_CROSSFADE)]
#endif
[SerializeField] bool m_EnableLODCrossFade = true;
[SerializeField] LODCrossFadeDitheringType m_LODCrossFadeDitheringType = LODCrossFadeDitheringType.BlueNoise;
// ShEvalMode.Auto is handled in shader preprocessor.
#if UNITY_EDITOR // multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
[ShaderKeywordFilter.RemoveIf(ShEvalMode.PerPixel, keywordNames: new [] { ShaderKeywordStrings.EVALUATE_SH_MIXED, ShaderKeywordStrings.EVALUATE_SH_VERTEX })]
[ShaderKeywordFilter.SelectIf(ShEvalMode.Mixed, keywordNames: new [] { ShaderKeywordStrings.EVALUATE_SH_MIXED })]
[ShaderKeywordFilter.SelectIf(ShEvalMode.PerVertex, keywordNames: new [] { ShaderKeywordStrings.EVALUATE_SH_VERTEX })]
#endif
[SerializeField] ShEvalMode m_ShEvalMode = ShEvalMode.Auto;
// Probe volume settings
#if UNITY_EDITOR
[ShaderKeywordFilter.RemoveIf(LightProbeSystem.LegacyLightProbes, keywordNames: new [] { ShaderKeywordStrings.ProbeVolumeL1, ShaderKeywordStrings.ProbeVolumeL2 })]
[ShaderKeywordFilter.SelectIf(LightProbeSystem.ProbeVolumes, keywordNames: new [] { ShaderKeywordStrings.ProbeVolumeL1, ShaderKeywordStrings.ProbeVolumeL2 })]
#endif
[SerializeField] LightProbeSystem m_LightProbeSystem = LightProbeSystem.LegacyLightProbes;
[SerializeField] ProbeVolumeTextureMemoryBudget m_ProbeVolumeMemoryBudget = ProbeVolumeTextureMemoryBudget.MemoryBudgetMedium;
[SerializeField] ProbeVolumeBlendingTextureMemoryBudget m_ProbeVolumeBlendingMemoryBudget = ProbeVolumeBlendingTextureMemoryBudget.MemoryBudgetMedium;
[SerializeField] [FormerlySerializedAs("m_SupportProbeVolumeStreaming")] bool m_SupportProbeVolumeGPUStreaming = false;
[SerializeField] bool m_SupportProbeVolumeDiskStreaming = false;
[SerializeField] bool m_SupportProbeVolumeScenarios = false;
[SerializeField] bool m_SupportProbeVolumeScenarioBlending = false;
#if UNITY_EDITOR
[ShaderKeywordFilter.RemoveIf(ProbeVolumeSHBands.SphericalHarmonicsL1, keywordNames: ShaderKeywordStrings.ProbeVolumeL2)]
[ShaderKeywordFilter.RemoveIf(ProbeVolumeSHBands.SphericalHarmonicsL2, keywordNames: ShaderKeywordStrings.ProbeVolumeL1)]
#endif
[SerializeField] ProbeVolumeSHBands m_ProbeVolumeSHBands = ProbeVolumeSHBands.SphericalHarmonicsL1;
// Main directional light Settings
[SerializeField] LightRenderingMode m_MainLightRenderingMode = LightRenderingMode.PerPixel;
[SerializeField] bool m_MainLightShadowsSupported = true;
[SerializeField] ShadowResolution m_MainLightShadowmapResolution = ShadowResolution._2048;
// Additional lights settings
[SerializeField] LightRenderingMode m_AdditionalLightsRenderingMode = LightRenderingMode.PerPixel;
[SerializeField] int m_AdditionalLightsPerObjectLimit = 4;
[SerializeField] bool m_AdditionalLightShadowsSupported = false;
[SerializeField] ShadowResolution m_AdditionalLightsShadowmapResolution = ShadowResolution._2048;
[SerializeField] int m_AdditionalLightsShadowResolutionTierLow = AdditionalLightsDefaultShadowResolutionTierLow;
[SerializeField] int m_AdditionalLightsShadowResolutionTierMedium = AdditionalLightsDefaultShadowResolutionTierMedium;
[SerializeField] int m_AdditionalLightsShadowResolutionTierHigh = AdditionalLightsDefaultShadowResolutionTierHigh;
// Reflection Probes
#if UNITY_EDITOR // multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
[ShaderKeywordFilter.SelectOrRemove(true, keywordNames: ShaderKeywordStrings.ReflectionProbeBlending)]
#endif
[SerializeField] bool m_ReflectionProbeBlending = false;
#if UNITY_EDITOR // multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
[ShaderKeywordFilter.SelectOrRemove(true, keywordNames: ShaderKeywordStrings.ReflectionProbeBoxProjection)]
#endif
[SerializeField] bool m_ReflectionProbeBoxProjection = false;
// Shadows Settings
[SerializeField] float m_ShadowDistance = 50.0f;
[SerializeField] int m_ShadowCascadeCount = 1;
[SerializeField] float m_Cascade2Split = 0.25f;
[SerializeField] Vector2 m_Cascade3Split = new Vector2(0.1f, 0.3f);
[SerializeField] Vector3 m_Cascade4Split = new Vector3(0.067f, 0.2f, 0.467f);
[SerializeField] float m_CascadeBorder = 0.2f;
[SerializeField] float m_ShadowDepthBias = 1.0f;
[SerializeField] float m_ShadowNormalBias = 1.0f;
#if UNITY_EDITOR // multi_compile_fragment _ _SHADOWS_SOFT
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.SoftShadows)]
[SerializeField] bool m_AnyShadowsSupported = true;
// No option to force soft shadows -> we'll need to keep the off variant around
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.SoftShadows)]
#endif
[SerializeField] bool m_SoftShadowsSupported = false;
[SerializeField] bool m_ConservativeEnclosingSphere = false;
[SerializeField] int m_NumIterationsEnclosingSphere = 64;
[SerializeField] SoftShadowQuality m_SoftShadowQuality = SoftShadowQuality.Medium;
// Light Cookie Settings
[SerializeField] LightCookieResolution m_AdditionalLightsCookieResolution = LightCookieResolution._2048;
[SerializeField] LightCookieFormat m_AdditionalLightsCookieFormat = LightCookieFormat.ColorHigh;
// Advanced settings
[SerializeField] bool m_UseSRPBatcher = true;
[SerializeField] bool m_SupportsDynamicBatching = false;
#if UNITY_EDITOR
// multi_compile _ LIGHTMAP_SHADOW_MIXING
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.LightmapShadowMixing)]
// multi_compile _ SHADOWS_SHADOWMASK
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.ShadowsShadowMask)]
#endif
[SerializeField] bool m_MixedLightingSupported = true;
#if UNITY_EDITOR
// multi_compile_fragment _ _LIGHT_COOKIES
[ShaderKeywordFilter.RemoveIf(false, keywordNames: ShaderKeywordStrings.LightCookies)]
#endif
[SerializeField] bool m_SupportsLightCookies = true;
#if UNITY_EDITOR
// multi_compile_fragment _ _LIGHT_LAYERS
[ShaderKeywordFilter.SelectOrRemove(true, keywordNames: ShaderKeywordStrings.LightLayers)]
#endif
[SerializeField] bool m_SupportsLightLayers = false;
[SerializeField] [Obsolete("",true)] PipelineDebugLevel m_DebugLevel;
[SerializeField] StoreActionsOptimization m_StoreActionsOptimization = StoreActionsOptimization.Auto;
// Adaptive performance settings
[SerializeField] bool m_UseAdaptivePerformance = true;
// Post-processing settings
[SerializeField] ColorGradingMode m_ColorGradingMode = ColorGradingMode.LowDynamicRange;
[SerializeField] int m_ColorGradingLutSize = 32;
#if UNITY_EDITOR // multi_compile_fragment _ _ENABLE_ALPHA_OUTPUT
[ShaderKeywordFilter.SelectOrRemove(true, keywordNames: ShaderKeywordStrings._ENABLE_ALPHA_OUTPUT)]
#endif
[SerializeField] bool m_AllowPostProcessAlphaOutput = false;
#if UNITY_EDITOR // multi_compile_local_fragment _ _USE_FAST_SRGB_LINEAR_CONVERSION
[ShaderKeywordFilter.SelectOrRemove(true, keywordNames: ShaderKeywordStrings.UseFastSRGBLinearConversion)]
#endif
[SerializeField] bool m_UseFastSRGBLinearConversion = false;
[SerializeField] bool m_SupportDataDrivenLensFlare = true;
[SerializeField] bool m_SupportScreenSpaceLensFlare = true;
// GPU Resident Drawer
[FormerlySerializedAs("m_MacroBatcherMode"), SerializeField]
private GPUResidentDrawerMode m_GPUResidentDrawerMode = GPUResidentDrawerMode.Disabled;
[SerializeField] float m_SmallMeshScreenPercentage = 0.0f;
[SerializeField] bool m_GPUResidentDrawerEnableOcclusionCullingInCameras;
GPUResidentDrawerSettings IGPUResidentRenderPipeline.gpuResidentDrawerSettings => new()
{
mode = m_GPUResidentDrawerMode,
enableOcclusionCulling = m_GPUResidentDrawerEnableOcclusionCullingInCameras,
supportDitheringCrossFade = m_EnableLODCrossFade,
allowInEditMode = true,
smallMeshScreenPercentage = m_SmallMeshScreenPercentage,
#if UNITY_EDITOR
pickingShader = Shader.Find("Hidden/Universal Render Pipeline/BRGPicking"),
#endif
errorShader = Shader.Find("Hidden/Universal Render Pipeline/FallbackError"),
loadingShader = Shader.Find("Hidden/Universal Render Pipeline/FallbackLoading"),
};
// Deprecated settings
[SerializeField] ShadowQuality m_ShadowType = ShadowQuality.HardShadows;
[SerializeField] bool m_LocalShadowsSupported = false;
[SerializeField] ShadowResolution m_LocalShadowsAtlasResolution = ShadowResolution._256;
[SerializeField] int m_MaxPixelLights = 0;
[SerializeField] ShadowResolution m_ShadowAtlasResolution = ShadowResolution._256;
[SerializeField] VolumeFrameworkUpdateMode m_VolumeFrameworkUpdateMode = VolumeFrameworkUpdateMode.EveryFrame;
[SerializeField] VolumeProfile m_VolumeProfile;
// Note: A lut size of 16^3 is barely usable with the HDR grading mode. 32 should be the
// minimum, the lut being encoded in log. Lower sizes would work better with an additional
// 1D shaper lut but for now we'll keep it simple.
/// <summary>
/// The minimum color grading LUT (lookup table) size.
/// </summary>
public const int k_MinLutSize = 16;
/// <summary>
/// The maximum color grading LUT (lookup table) size.
/// </summary>
public const int k_MaxLutSize = 65;
internal const int k_ShadowCascadeMinCount = 1;
internal const int k_ShadowCascadeMaxCount = 4;
/// <summary>
/// The default low tier resolution for additional lights shadow texture.
/// </summary>
public static readonly int AdditionalLightsDefaultShadowResolutionTierLow = 256;
/// <summary>
/// The default medium tier resolution for additional lights shadow texture.
/// </summary>
public static readonly int AdditionalLightsDefaultShadowResolutionTierMedium = 512;
/// <summary>
/// The default high tier resolution for additional lights shadow texture.
/// </summary>
public static readonly int AdditionalLightsDefaultShadowResolutionTierHigh = 1024;
/// <summary>
/// The list of renderer data used by this pipeline asset.
/// </summary>
public ReadOnlySpan<ScriptableRendererData> rendererDataList => m_RendererDataList;
/// <summary>
/// The list of renderers used by this pipeline asset.
/// </summary>
public ReadOnlySpan<ScriptableRenderer> renderers => m_Renderers;
static string[] s_Names;
static int[] s_Values;
/// <inheritdoc/>
public bool isImmediateModeSupported => false;
#if UNITY_EDITOR
public static readonly string packagePath = "Packages/com.unity.render-pipelines.universal";
public static UniversalRenderPipelineAsset Create(ScriptableRendererData rendererData = null)
{
// Create Universal RP Asset
var instance = CreateInstance<UniversalRenderPipelineAsset>();
// Initialize default renderer data
instance.m_RendererDataList[0] = (rendererData != null) ? rendererData : CreateInstance<UniversalRendererData>();
// Only enable for new URP assets by default
instance.m_ConservativeEnclosingSphere = true;
ResourceReloader.ReloadAllNullIn(instance, packagePath);
return instance;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812")]
internal class CreateUniversalPipelineAsset : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
//Create asset
AssetDatabase.CreateAsset(Create(CreateRendererAsset(pathName, RendererType.UniversalRenderer)), pathName);
}
}
[MenuItem("Assets/Create/Rendering/URP Asset (with Universal Renderer)", priority = CoreUtils.Sections.section2 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority + 1)]
static void CreateUniversalPipeline()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateUniversalPipelineAsset>(),
"New Universal Render Pipeline Asset.asset", null, null);
}
internal static ScriptableRendererData CreateRendererAsset(string path, RendererType type, bool relativePath = true, string suffix = "Renderer")
{
ScriptableRendererData data = CreateRendererData(type);
string dataPath;
if (relativePath)
dataPath =
$"{Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path))}_{suffix}{Path.GetExtension(path)}";
else
dataPath = path;
AssetDatabase.CreateAsset(data, dataPath);
ResourceReloader.ReloadAllNullIn(data, packagePath);
return data;
}
static ScriptableRendererData CreateRendererData(RendererType type)
{
switch (type)
{
case RendererType.UniversalRenderer:
default:
{
var rendererData = CreateInstance<UniversalRendererData>();
rendererData.postProcessData = PostProcessData.GetDefaultPostProcessData();
return rendererData;
}
}
}
#endif
/// <summary>
/// Use this class to initialize the rendererData element that is required by the renderer.
/// </summary>
/// <param name="type">The <c>RendererType</c> of the new renderer that is initialized within this asset.</param>
/// <returns></returns>
/// <see cref="RendererType"/>
public ScriptableRendererData LoadBuiltinRendererData(RendererType type = RendererType.UniversalRenderer)
{
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
return m_RendererDataList[0] =
CreateRendererAsset("Assets/UniversalRenderer.asset", type, false);
#else
m_RendererDataList[0] = null;
return m_RendererDataList[0];
#endif
}
/// <summary>
/// Ensures Global Settings are ready and registered into GraphicsSettings
/// </summary>
protected override void EnsureGlobalSettings()
{
base.EnsureGlobalSettings();
#if UNITY_EDITOR
UniversalRenderPipelineGlobalSettings.Ensure();
#endif
}
/// <summary>
/// Creates a <c>UniversalRenderPipeline</c> from the <c>UniversalRenderPipelineAsset</c>.
/// </summary>
/// <returns>Returns a <c>UniversalRenderPipeline</c> created from this UniversalRenderPipelineAsset.</returns>
/// <see cref="RenderPipeline"/>
protected override RenderPipeline CreatePipeline()
{
if (m_RendererDataList == null)
m_RendererDataList = new ScriptableRendererData[1];
// If no default data we can't create pipeline instance
if (m_DefaultRendererIndex >= m_RendererDataList.Length || m_RendererDataList[m_DefaultRendererIndex] == null)
{
// If previous version and current version are miss-matched then we are waiting for the upgrader to kick in
if (k_AssetPreviousVersion != k_AssetVersion)
return null;
Debug.LogError(
$"Default Renderer is missing, make sure there is a Renderer assigned as the default on the current Universal RP asset:{UniversalRenderPipeline.asset.name}",
this);
return null;
}
DestroyRenderers();
var pipeline = new UniversalRenderPipeline(this);
CreateRenderers();
IGPUResidentRenderPipeline.ReinitializeGPUResidentDrawer();
return pipeline;
}
internal void DestroyRenderers()
{
if (m_Renderers == null)
return;
for (int i = 0; i < m_Renderers.Length; i++)
DestroyRenderer(ref m_Renderers[i]);
}
void DestroyRenderer(ref ScriptableRenderer renderer)
{
if (renderer != null)
{
renderer.Dispose();
renderer = null;
}
}
/// <summary>
/// Unity calls this function when it loads the asset or when the asset is changed with the Inspector.
/// </summary>
protected override void OnValidate()
{
DestroyRenderers();
// This will call RenderPipelineManager.CleanupRenderPipeline that in turn disposes the render pipeline instance and
// assign pipeline asset reference to null
base.OnValidate();
}
/// <summary>
/// Unity calls this function when the asset is disabled.
/// </summary>
protected override void OnDisable()
{
DestroyRenderers();
// This will call RenderPipelineManager.CleanupRenderPipeline that in turn disposes the render pipeline instance and
// assign pipeline asset reference to null
base.OnDisable();
}
void CreateRenderers()
{
if (m_Renderers != null)
{
for (int i = 0; i < m_Renderers.Length; ++i)
{
if (m_Renderers[i] != null)
Debug.LogError($"Creating renderers but previous instance wasn't properly destroyed: m_Renderers[{i}]");
}
}
if (m_Renderers == null || m_Renderers.Length != m_RendererDataList.Length)
m_Renderers = new ScriptableRenderer[m_RendererDataList.Length];
for (int i = 0; i < m_RendererDataList.Length; ++i)
{
if (m_RendererDataList[i] != null)
m_Renderers[i] = m_RendererDataList[i].InternalCreateRenderer();
}
}
/// <summary>
/// Returns the default renderer being used by this pipeline.
/// </summary>
public ScriptableRenderer scriptableRenderer
{
get
{
if (m_RendererDataList?.Length > m_DefaultRendererIndex && m_RendererDataList[m_DefaultRendererIndex] == null)
{
Debug.LogError("Default renderer is missing from the current Pipeline Asset.", this);
return null;
}
if (scriptableRendererData.isInvalidated || m_Renderers[m_DefaultRendererIndex] == null)
{
DestroyRenderer(ref m_Renderers[m_DefaultRendererIndex]);
m_Renderers[m_DefaultRendererIndex] = scriptableRendererData.InternalCreateRenderer();
// GPU Resident Drawer may need to be reinitialized if renderer data has become incompatible/compatible
if (gpuResidentDrawerMode != GPUResidentDrawerMode.Disabled)
{
IGPUResidentRenderPipeline.ReinitializeGPUResidentDrawer();
}
}
return m_Renderers[m_DefaultRendererIndex];
}
}
/// <summary>
/// Returns a renderer from the current pipeline asset
/// </summary>
/// <param name="index">Index to the renderer. If invalid index is passed, the default renderer is returned instead.</param>
/// <returns></returns>
public ScriptableRenderer GetRenderer(int index)
{
if (index == -1)
index = m_DefaultRendererIndex;
if (index >= m_RendererDataList.Length || index < 0 || m_RendererDataList[index] == null)
{
Debug.LogWarning(
$"Renderer at index {index.ToString()} is missing, falling back to Default Renderer {m_RendererDataList[m_DefaultRendererIndex].name}",
this);
index = m_DefaultRendererIndex;
}
// RendererData list differs from RendererList. Create RendererList.
if (m_Renderers == null || m_Renderers.Length < m_RendererDataList.Length)
{
DestroyRenderers();
CreateRenderers();
}
// This renderer data is outdated or invalid, we recreate the renderer
// so we construct all render passes with the updated data
if (m_RendererDataList[index].isInvalidated || m_Renderers[index] == null)
{
DestroyRenderer(ref m_Renderers[index]);
m_Renderers[index] = m_RendererDataList[index].InternalCreateRenderer();
// GPU Resident Drawer may need to be reinitialized if renderer data has become incompatible/compatible
if (gpuResidentDrawerMode != GPUResidentDrawerMode.Disabled)
{
IGPUResidentRenderPipeline.ReinitializeGPUResidentDrawer();
}
}
return m_Renderers[index];
}
internal ScriptableRendererData scriptableRendererData
{
get
{
if (m_RendererDataList[m_DefaultRendererIndex] == null)
CreatePipeline();
return m_RendererDataList[m_DefaultRendererIndex];
}
}
#if UNITY_EDITOR
internal GUIContent[] rendererDisplayList
{
get
{
GUIContent[] list = new GUIContent[m_RendererDataList.Length + 1];
list[0] = new GUIContent($"Default Renderer ({RendererDataDisplayName(m_RendererDataList[m_DefaultRendererIndex])})");
for (var i = 1; i < list.Length; i++)
{
list[i] = new GUIContent($"{(i - 1).ToString()}: {RendererDataDisplayName(m_RendererDataList[i - 1])}");
}
return list;
}
}
string RendererDataDisplayName(ScriptableRendererData data)
{
if (data != null)
return data.name;
return "NULL (Missing RendererData)";
}
#endif
private static GraphicsFormat[][] s_LightCookieFormatList = new GraphicsFormat[][]
{
/* Grayscale Low */ new GraphicsFormat[] {GraphicsFormat.R8_UNorm},
/* Grayscale High*/ new GraphicsFormat[] {GraphicsFormat.R16_UNorm},
/* Color Low */ new GraphicsFormat[] {GraphicsFormat.R5G6B5_UNormPack16, GraphicsFormat.B5G6R5_UNormPack16, GraphicsFormat.R5G5B5A1_UNormPack16, GraphicsFormat.B5G5R5A1_UNormPack16},
/* Color High */ new GraphicsFormat[] {GraphicsFormat.A2B10G10R10_UNormPack32, GraphicsFormat.R8G8B8A8_SRGB, GraphicsFormat.B8G8R8A8_SRGB},
/* Color HDR */ new GraphicsFormat[] {GraphicsFormat.B10G11R11_UFloatPack32},
};