-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathUniversalRenderPipelineCore.cs
2010 lines (1677 loc) · 98.3 KB
/
UniversalRenderPipelineCore.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;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Assertions;
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.Experimental.Rendering;
using Lightmapping = UnityEngine.Experimental.GlobalIllumination.Lightmapping;
namespace UnityEngine.Rendering.Universal
{
static class NativeArrayExtensions
{
/// <summary>
/// IMPORTANT: Make sure you do not write to the value! There are no checks for this!
/// </summary>
public static unsafe ref T UnsafeElementAt<T>(this NativeArray<T> array, int index) where T : struct
{
return ref UnsafeUtility.ArrayElementAsRef<T>(array.GetUnsafeReadOnlyPtr(), index);
}
public static unsafe ref T UnsafeElementAtMutable<T>(this NativeArray<T> array, int index) where T : struct
{
return ref UnsafeUtility.ArrayElementAsRef<T>(array.GetUnsafePtr(), index);
}
}
/// <summary>
/// Options for mixed lighting setup.
/// </summary>
public enum MixedLightingSetup
{
/// <summary>
/// Use this to disable mixed lighting.
/// </summary>
None,
/// <summary>
/// Use this to select shadow mask.
/// </summary>
ShadowMask,
/// <summary>
/// Use this to select subtractive.
/// </summary>
Subtractive,
};
/// <summary>
/// Enumeration that indicates what kind of image scaling is occurring if any
/// </summary>
internal enum ImageScalingMode
{
/// No scaling
None,
/// Upscaling to a larger image
Upscaling,
/// Downscaling to a smaller image
Downscaling
}
/// <summary>
/// Enumeration that indicates what kind of upscaling filter is being used
/// </summary>
internal enum ImageUpscalingFilter
{
/// Bilinear filtering
Linear,
/// Nearest-Neighbor filtering
Point,
/// FidelityFX Super Resolution
FSR,
/// Snapdragon Game Super Resolution
SGSR,
/// Spatial-Temporal Post-Processing
STP
}
/// <summary>
/// Struct that flattens several rendering settings used to render a camera stack.
/// URP builds the <c>RenderingData</c> settings from several places, including the pipeline asset, camera and light settings.
/// The settings also might vary on different platforms and depending on if Adaptive Performance is used.
/// </summary>
public struct RenderingData
{
internal ContextContainer frameData;
internal RenderingData(ContextContainer frameData)
{
this.frameData = frameData;
cameraData = new CameraData(frameData);
lightData = new LightData(frameData);
shadowData = new ShadowData(frameData);
postProcessingData = new PostProcessingData(frameData);
}
internal UniversalRenderingData universalRenderingData => frameData.Get<UniversalRenderingData>();
// Non-rendergraph path only. Do NOT use with rendergraph!
internal ref CommandBuffer commandBuffer
{
get
{
ref var cmd = ref frameData.Get<UniversalRenderingData>().m_CommandBuffer;
if (cmd == null)
Debug.LogError("RenderingData.commandBuffer is null. RenderGraph does not support this property. Please use the command buffer provided by the RenderGraphContext.");
return ref cmd;
}
}
/// <summary>
/// Returns culling results that exposes handles to visible objects, lights and probes.
/// You can use this to draw objects with <c>ScriptableRenderContext.DrawRenderers</c>
/// <see cref="CullingResults"/>
/// <seealso cref="ScriptableRenderContext"/>
/// </summary>
public ref CullingResults cullResults => ref frameData.Get<UniversalRenderingData>().cullResults;
/// <summary>
/// Holds several rendering settings related to camera.
/// <see cref="CameraData"/>
/// </summary>
public CameraData cameraData;
/// <summary>
/// Holds several rendering settings related to lights.
/// <see cref="LightData"/>
/// </summary>
public LightData lightData;
/// <summary>
/// Holds several rendering settings related to shadows.
/// <see cref="ShadowData"/>
/// </summary>
public ShadowData shadowData;
/// <summary>
/// Holds several rendering settings and resources related to the integrated post-processing stack.
/// <see cref="PostProcessData"/>
/// </summary>
public PostProcessingData postProcessingData;
/// <summary>
/// True if the pipeline supports dynamic batching.
/// This settings doesn't apply when drawing shadow casters. Dynamic batching is always disabled when drawing shadow casters.
/// </summary>
public ref bool supportsDynamicBatching => ref frameData.Get<UniversalRenderingData>().supportsDynamicBatching;
/// <summary>
/// Holds per-object data that are requested when drawing
/// <see cref="PerObjectData"/>
/// </summary>
public ref PerObjectData perObjectData => ref frameData.Get<UniversalRenderingData>().perObjectData;
/// <summary>
/// True if post-processing effect is enabled while rendering the camera stack.
/// </summary>
public ref bool postProcessingEnabled => ref frameData.Get<UniversalPostProcessingData>().isEnabled;
}
/// <summary>
/// Struct that holds settings related to lights.
/// </summary>
public struct LightData
{
ContextContainer frameData;
internal LightData(ContextContainer frameData)
{
this.frameData = frameData;
}
internal UniversalLightData universalLightData => frameData.Get<UniversalLightData>();
/// <summary>
/// Holds the main light index from the <c>VisibleLight</c> list returned by culling. If there's no main light in the scene, <c>mainLightIndex</c> is set to -1.
/// The main light is the directional light assigned as Sun source in light settings or the brightest directional light.
/// <seealso cref="CullingResults"/>
/// </summary>
public ref int mainLightIndex => ref frameData.Get<UniversalLightData>().mainLightIndex;
/// <summary>
/// The number of additional lights visible by the camera.
/// </summary>
public ref int additionalLightsCount => ref frameData.Get<UniversalLightData>().additionalLightsCount;
/// <summary>
/// Maximum amount of lights that can be shaded per-object. This value only affects forward rendering.
/// </summary>
public ref int maxPerObjectAdditionalLightsCount => ref frameData.Get<UniversalLightData>().maxPerObjectAdditionalLightsCount;
/// <summary>
/// List of visible lights returned by culling.
/// </summary>
public ref NativeArray<VisibleLight> visibleLights => ref frameData.Get<UniversalLightData>().visibleLights;
/// <summary>
/// True if additional lights should be shaded in vertex shader, otherwise additional lights will be shaded per pixel.
/// </summary>
public ref bool shadeAdditionalLightsPerVertex => ref frameData.Get<UniversalLightData>().shadeAdditionalLightsPerVertex;
/// <summary>
/// True if mixed lighting is supported.
/// </summary>
public ref bool supportsMixedLighting => ref frameData.Get<UniversalLightData>().supportsMixedLighting;
/// <summary>
/// True if box projection is enabled for reflection probes.
/// </summary>
public ref bool reflectionProbeBoxProjection => ref frameData.Get<UniversalLightData>().reflectionProbeBoxProjection;
/// <summary>
/// True if blending is enabled for reflection probes.
/// </summary>
public ref bool reflectionProbeBlending => ref frameData.Get<UniversalLightData>().reflectionProbeBlending;
/// <summary>
/// True if light layers are enabled.
/// </summary>
public ref bool supportsLightLayers => ref frameData.Get<UniversalLightData>().supportsLightLayers;
/// <summary>
/// True if additional lights enabled.
/// </summary>
public ref bool supportsAdditionalLights => ref frameData.Get<UniversalLightData>().supportsAdditionalLights;
}
/// <summary>
/// Struct that holds settings related to camera.
/// </summary>
public struct CameraData
{
ContextContainer frameData;
internal CameraData(ContextContainer frameData)
{
this.frameData = frameData;
}
internal UniversalCameraData universalCameraData => frameData.Get<UniversalCameraData>();
internal void SetViewAndProjectionMatrix(Matrix4x4 viewMatrix, Matrix4x4 projectionMatrix)
{
frameData.Get<UniversalCameraData>().SetViewAndProjectionMatrix(viewMatrix, projectionMatrix);
}
internal void SetViewProjectionAndJitterMatrix(Matrix4x4 viewMatrix, Matrix4x4 projectionMatrix, Matrix4x4 jitterMatrix)
{
frameData.Get<UniversalCameraData>().SetViewProjectionAndJitterMatrix(viewMatrix, projectionMatrix, jitterMatrix);
}
// Helper function to populate builtin stereo matricies as well as URP stereo matricies
internal void PushBuiltinShaderConstantsXR(RasterCommandBuffer cmd, bool renderIntoTexture)
{
frameData.Get<UniversalCameraData>().PushBuiltinShaderConstantsXR(cmd, renderIntoTexture);
}
/// <summary>
/// Returns the camera view matrix.
/// </summary>
/// <param name="viewIndex"> View index in case of stereo rendering. By default <c>viewIndex</c> is set to 0. </param>
/// <returns> The camera view matrix. </returns>
public Matrix4x4 GetViewMatrix(int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetViewMatrix(viewIndex);
}
/// <summary>
/// Returns the camera projection matrix. Might be jittered for temporal features.
/// </summary>
/// <param name="viewIndex"> View index in case of stereo rendering. By default <c>viewIndex</c> is set to 0. </param>
/// <returns> The camera projection matrix. </returns>
public Matrix4x4 GetProjectionMatrix(int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetProjectionMatrix(viewIndex);
}
internal Matrix4x4 GetProjectionMatrixNoJitter(int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetProjectionMatrixNoJitter(viewIndex);
}
/// <summary>
/// Returns the camera GPU projection matrix. This contains platform specific changes to handle y-flip and reverse z. Includes camera jitter if required by active features.
/// Similar to <c>GL.GetGPUProjectionMatrix</c> but queries URP internal state to know if the pipeline is rendering to render texture.
/// For more info on platform differences regarding camera projection check: https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
/// </summary>
/// <param name="viewIndex"> View index in case of stereo rendering. By default <c>viewIndex</c> is set to 0. </param>
/// <seealso cref="GL.GetGPUProjectionMatrix(Matrix4x4, bool)"/>
/// <returns></returns>
public Matrix4x4 GetGPUProjectionMatrix(int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetGPUProjectionMatrix(viewIndex);
}
/// <summary>
/// Returns the camera GPU projection matrix. This contains platform specific changes to handle y-flip and reverse z. Does not include any camera jitter.
/// Similar to <c>GL.GetGPUProjectionMatrix</c> but queries URP internal state to know if the pipeline is rendering to render texture.
/// For more info on platform differences regarding camera projection check: https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
/// </summary>
/// <param name="viewIndex"> View index in case of stereo rendering. By default <c>viewIndex</c> is set to 0. </param>
/// <seealso cref="GL.GetGPUProjectionMatrix(Matrix4x4, bool)"/>
/// <returns></returns>
public Matrix4x4 GetGPUProjectionMatrixNoJitter(int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetGPUProjectionMatrixNoJitter(viewIndex);
}
internal Matrix4x4 GetGPUProjectionMatrix(bool renderIntoTexture, int viewIndex = 0)
{
return frameData.Get<UniversalCameraData>().GetGPUProjectionMatrix(renderIntoTexture, viewIndex);
}
/// <summary>
/// The camera component.
/// </summary>
public ref Camera camera => ref frameData.Get<UniversalCameraData>().camera;
/// <summary>
/// The camera history texture manager. Used to access camera history from a ScriptableRenderPass.
/// </summary>
/// <seealso cref="ScriptableRenderPass"/>
public ref UniversalCameraHistory historyManager => ref frameData.Get<UniversalCameraData>().m_HistoryManager;
/// <summary>
/// The camera render type used for camera stacking.
/// <see cref="CameraRenderType"/>
/// </summary>
public ref CameraRenderType renderType => ref frameData.Get<UniversalCameraData>().renderType;
/// <summary>
/// Controls the final target texture for a camera. If null camera will resolve rendering to screen.
/// </summary>
public ref RenderTexture targetTexture => ref frameData.Get<UniversalCameraData>().targetTexture;
/// <summary>
/// Render texture settings used to create intermediate camera textures for rendering.
/// </summary>
public ref RenderTextureDescriptor cameraTargetDescriptor => ref frameData.Get<UniversalCameraData>().cameraTargetDescriptor;
internal ref Rect pixelRect => ref frameData.Get<UniversalCameraData>().pixelRect;
internal ref bool useScreenCoordOverride => ref frameData.Get<UniversalCameraData>().useScreenCoordOverride;
internal ref Vector4 screenSizeOverride => ref frameData.Get<UniversalCameraData>().screenSizeOverride;
internal ref Vector4 screenCoordScaleBias => ref frameData.Get<UniversalCameraData>().screenCoordScaleBias;
internal ref int pixelWidth => ref frameData.Get<UniversalCameraData>().pixelWidth;
internal ref int pixelHeight => ref frameData.Get<UniversalCameraData>().pixelHeight;
internal ref float aspectRatio => ref frameData.Get<UniversalCameraData>().aspectRatio;
/// <summary>
/// Render scale to apply when creating camera textures. Scaled extents are rounded down to integers.
/// </summary>
public ref float renderScale => ref frameData.Get<UniversalCameraData>().renderScale;
internal ref ImageScalingMode imageScalingMode => ref frameData.Get<UniversalCameraData>().imageScalingMode;
internal ref ImageUpscalingFilter upscalingFilter => ref frameData.Get<UniversalCameraData>().upscalingFilter;
internal ref bool fsrOverrideSharpness => ref frameData.Get<UniversalCameraData>().fsrOverrideSharpness;
internal ref float fsrSharpness => ref frameData.Get<UniversalCameraData>().fsrSharpness;
internal ref HDRColorBufferPrecision hdrColorBufferPrecision => ref frameData.Get<UniversalCameraData>().hdrColorBufferPrecision;
/// <summary>
/// True if this camera should clear depth buffer. This setting only applies to cameras of type <c>CameraRenderType.Overlay</c>
/// <seealso cref="CameraRenderType"/>
/// </summary>
public ref bool clearDepth => ref frameData.Get<UniversalCameraData>().clearDepth;
/// <summary>
/// The camera type.
/// <seealso cref="UnityEngine.CameraType"/>
/// </summary>
public ref CameraType cameraType => ref frameData.Get<UniversalCameraData>().cameraType;
/// <summary>
/// True if this camera is drawing to a viewport that maps to the entire screen.
/// </summary>
public ref bool isDefaultViewport => ref frameData.Get<UniversalCameraData>().isDefaultViewport;
/// <summary>
/// True if this camera should render to high dynamic range color targets.
/// </summary>
public ref bool isHdrEnabled => ref frameData.Get<UniversalCameraData>().isHdrEnabled;
/// <summary>
/// True if this camera allow color conversion and encoding for high dynamic range displays.
/// </summary>
public ref bool allowHDROutput => ref frameData.Get<UniversalCameraData>().allowHDROutput;
/// <summary>
/// True if this camera writes the alpha channel. Requires to color target to have an alpha channel.
/// </summary>
public ref bool isAlphaOutputEnabled => ref frameData.Get<UniversalCameraData>().isAlphaOutputEnabled;
/// <summary>
/// True if this camera requires to write _CameraDepthTexture.
/// </summary>
public ref bool requiresDepthTexture => ref frameData.Get<UniversalCameraData>().requiresDepthTexture;
/// <summary>
/// True if this camera requires to copy camera color texture to _CameraOpaqueTexture.
/// </summary>
public ref bool requiresOpaqueTexture => ref frameData.Get<UniversalCameraData>().requiresOpaqueTexture;
/// <summary>
/// Returns true if post processing passes require depth texture.
/// </summary>
public ref bool postProcessingRequiresDepthTexture => ref frameData.Get<UniversalCameraData>().postProcessingRequiresDepthTexture;
/// <summary>
/// Returns true if XR rendering is enabled.
/// </summary>
public ref bool xrRendering => ref frameData.Get<UniversalCameraData>().xrRendering;
internal bool requireSrgbConversion => frameData.Get<UniversalCameraData>().requireSrgbConversion;
/// <summary>
/// True if the camera rendering is for the scene window in the editor.
/// </summary>
public bool isSceneViewCamera => frameData.Get<UniversalCameraData>().isSceneViewCamera;
/// <summary>
/// True if the camera rendering is for the preview window in the editor.
/// </summary>
public bool isPreviewCamera => frameData.Get<UniversalCameraData>().isPreviewCamera;
internal bool isRenderPassSupportedCamera => frameData.Get<UniversalCameraData>().isRenderPassSupportedCamera;
internal bool resolveToScreen => frameData.Get<UniversalCameraData>().resolveToScreen;
/// <summary>
/// True if the Camera should output to an HDR display.
/// </summary>
public bool isHDROutputActive => frameData.Get<UniversalCameraData>().isHDROutputActive;
/// <summary>
/// HDR Display information about the current display this camera is rendering to.
/// </summary>
public HDROutputUtils.HDRDisplayInformation hdrDisplayInformation => frameData.Get<UniversalCameraData>().hdrDisplayInformation;
/// <summary>
/// HDR Display Color Gamut
/// </summary>
public ColorGamut hdrDisplayColorGamut => frameData.Get<UniversalCameraData>().hdrDisplayColorGamut;
/// <summary>
/// True if the Camera should render overlay UI.
/// </summary>
public bool rendersOverlayUI => frameData.Get<UniversalCameraData>().rendersOverlayUI;
/// <summary>
/// True is the handle has its content flipped on the y axis.
/// This happens only with certain rendering APIs.
/// On those platforms, any handle will have its content flipped unless rendering to a backbuffer, however,
/// the scene view will always be flipped.
/// When transitioning from a flipped space to a non-flipped space - or vice-versa - the content must be flipped
/// in the shader:
/// shouldPerformYFlip = IsHandleYFlipped(source) != IsHandleYFlipped(target)
/// </summary>
/// <param name="handle">Handle to check the flipped status on.</param>
/// <returns>True is the content is flipped in y.</returns>
public bool IsHandleYFlipped(RTHandle handle)
{
return frameData.Get<UniversalCameraData>().IsHandleYFlipped(handle);
}
/// <summary>
/// True if the camera device projection matrix is flipped. This happens when the pipeline is rendering
/// to a render texture in non OpenGL platforms. If you are doing a custom Blit pass to copy camera textures
/// (_CameraColorTexture, _CameraDepthAttachment) you need to check this flag to know if you should flip the
/// matrix when rendering with for cmd.Draw* and reading from camera textures.
/// </summary>
/// <returns> True if the camera device projection matrix is flipped. </returns>
[Obsolete(DeprecationMessage.CompatibilityScriptingAPIObsolete, false)]
public bool IsCameraProjectionMatrixFlipped()
{
return frameData.Get<UniversalCameraData>().IsCameraProjectionMatrixFlipped();
}
/// <summary>
/// True if the render target's projection matrix is flipped. This happens when the pipeline is rendering
/// to a render texture in non OpenGL platforms. If you are doing a custom Blit pass to copy camera textures
/// (_CameraColorTexture, _CameraDepthAttachment) you need to check this flag to know if you should flip the
/// matrix when rendering with for cmd.Draw* and reading from camera textures.
/// </summary>
/// <param name="color">Color render target to check whether the matrix is flipped.</param>
/// <param name="depth">Depth render target which is used if color is null. By default <c>depth</c> is set to null.</param>
/// <returns> True if the render target's projection matrix is flipped. </returns>
public bool IsRenderTargetProjectionMatrixFlipped(RTHandle color, RTHandle depth = null)
{
return frameData.Get<UniversalCameraData>().IsRenderTargetProjectionMatrixFlipped(color, depth);
}
internal bool IsTemporalAAEnabled()
{
return frameData.Get<UniversalCameraData>().IsTemporalAAEnabled();
}
/// <summary>
/// The sorting criteria used when drawing opaque objects by the internal URP render passes.
/// When a GPU supports hidden surface removal, URP will rely on that information to avoid sorting opaque objects front to back and
/// benefit for more optimal static batching.
/// </summary>
/// <seealso cref="SortingCriteria"/>
public ref SortingCriteria defaultOpaqueSortFlags => ref frameData.Get<UniversalCameraData>().defaultOpaqueSortFlags;
/// <summary>
/// XRPass holds the render target information and a list of XRView.
/// XRView contains the parameters required to render (projection and view matrices, viewport, etc)
/// </summary>
public XRPass xr
{
get => frameData.Get<UniversalCameraData>().xr;
internal set => frameData.Get<UniversalCameraData>().xr = value;
}
internal XRPassUniversal xrUniversal => frameData.Get<UniversalCameraData>().xrUniversal;
/// <summary>
/// Maximum shadow distance visible to the camera. When set to zero shadows will be disable for that camera.
/// </summary>
public ref float maxShadowDistance => ref frameData.Get<UniversalCameraData>().maxShadowDistance;
/// <summary>
/// True if post-processing is enabled for this camera.
/// </summary>
public ref bool postProcessEnabled => ref frameData.Get<UniversalCameraData>().postProcessEnabled;
/// <summary>
/// Provides set actions to the renderer to be triggered at the end of the render loop for camera capture.
/// </summary>
public ref IEnumerator<Action<RenderTargetIdentifier, CommandBuffer>> captureActions => ref frameData.Get<UniversalCameraData>().captureActions;
/// <summary>
/// The camera volume layer mask.
/// </summary>
public ref LayerMask volumeLayerMask => ref frameData.Get<UniversalCameraData>().volumeLayerMask;
/// <summary>
/// The camera volume trigger.
/// </summary>
public ref Transform volumeTrigger => ref frameData.Get<UniversalCameraData>().volumeTrigger;
/// <summary>
/// If set to true, the integrated post-processing stack will replace any NaNs generated by render passes prior to post-processing with black/zero.
/// Enabling this option will cause a noticeable performance impact. It should be used while in development mode to identify NaN issues.
/// </summary>
public ref bool isStopNaNEnabled => ref frameData.Get<UniversalCameraData>().isStopNaNEnabled;
/// <summary>
/// If set to true a final post-processing pass will be applied to apply dithering.
/// This can be combined with post-processing antialiasing.
/// <seealso cref="antialiasing"/>
/// </summary>
public ref bool isDitheringEnabled => ref frameData.Get<UniversalCameraData>().isDitheringEnabled;
/// <summary>
/// Controls the anti-alising mode used by the integrated post-processing stack.
/// When any other value other than <c>AntialiasingMode.None</c> is chosen, a final post-processing pass will be applied to apply anti-aliasing.
/// This pass can be combined with dithering.
/// <see cref="AntialiasingMode"/>
/// <seealso cref="isDitheringEnabled"/>
/// </summary>
public ref AntialiasingMode antialiasing => ref frameData.Get<UniversalCameraData>().antialiasing;
/// <summary>
/// Controls the anti-alising quality of the anti-aliasing mode.
/// <see cref="antialiasingQuality"/>
/// <seealso cref="AntialiasingMode"/>
/// </summary>
public ref AntialiasingQuality antialiasingQuality => ref frameData.Get<UniversalCameraData>().antialiasingQuality;
/// <summary>
/// Returns the current renderer used by this camera.
/// <see cref="ScriptableRenderer"/>
/// </summary>
public ref ScriptableRenderer renderer => ref frameData.Get<UniversalCameraData>().renderer;
/// <summary>
/// True if this camera is resolving rendering to the final camera render target.
/// When rendering a stack of cameras only the last camera in the stack will resolve to camera target.
/// </summary>
public ref bool resolveFinalTarget => ref frameData.Get<UniversalCameraData>().resolveFinalTarget;
/// <summary>
/// Camera position in world space.
/// </summary>
public ref Vector3 worldSpaceCameraPos => ref frameData.Get<UniversalCameraData>().worldSpaceCameraPos;
/// <summary>
/// Final background color in the active color space.
/// </summary>
public ref Color backgroundColor => ref frameData.Get<UniversalCameraData>().backgroundColor;
/// <summary>
/// Persistent TAA data, primarily for the accumulation texture.
/// </summary>
internal ref TaaHistory taaHistory => ref frameData.Get<UniversalCameraData>().taaHistory;
// TAA settings.
internal ref TemporalAA.Settings taaSettings => ref frameData.Get<UniversalCameraData>().taaSettings;
// Post-process history reset has been triggered for this camera.
internal bool resetHistory => frameData.Get<UniversalCameraData>().resetHistory;
/// <summary>
/// Camera at the top of the overlay camera stack
/// </summary>
public ref Camera baseCamera => ref frameData.Get<UniversalCameraData>().baseCamera;
}
/// <summary>
/// Container struct for various data used for shadows in URP.
/// </summary>
public struct ShadowData
{
ContextContainer frameData;
internal ShadowData(ContextContainer frameData)
{
this.frameData = frameData;
}
internal UniversalShadowData universalShadowData => frameData.Get<UniversalShadowData>();
/// <summary>
/// True if main light shadows are enabled.
/// </summary>
public ref bool supportsMainLightShadows => ref frameData.Get<UniversalShadowData>().supportsMainLightShadows;
/// <summary>
/// True if additional lights shadows are enabled in the URP Asset
/// </summary>
internal ref bool mainLightShadowsEnabled => ref frameData.Get<UniversalShadowData>().mainLightShadowsEnabled;
/// <summary>
/// The width of the main light shadow map.
/// </summary>
public ref int mainLightShadowmapWidth => ref frameData.Get<UniversalShadowData>().mainLightShadowmapWidth;
/// <summary>
/// The height of the main light shadow map.
/// </summary>
public ref int mainLightShadowmapHeight => ref frameData.Get<UniversalShadowData>().mainLightShadowmapHeight;
/// <summary>
/// The number of shadow cascades.
/// </summary>
public ref int mainLightShadowCascadesCount => ref frameData.Get<UniversalShadowData>().mainLightShadowCascadesCount;
/// <summary>
/// The split between cascades.
/// </summary>
public ref Vector3 mainLightShadowCascadesSplit => ref frameData.Get<UniversalShadowData>().mainLightShadowCascadesSplit;
/// <summary>
/// Main light last cascade shadow fade border.
/// Value represents the width of shadow fade that ranges from 0 to 1.
/// Where value 0 is used for no shadow fade.
/// </summary>
public ref float mainLightShadowCascadeBorder => ref frameData.Get<UniversalShadowData>().mainLightShadowCascadeBorder;
/// <summary>
/// True if additional lights shadows are enabled.
/// </summary>
public ref bool supportsAdditionalLightShadows => ref frameData.Get<UniversalShadowData>().supportsAdditionalLightShadows;
/// <summary>
/// True if additional lights shadows are enabled in the URP Asset
/// </summary>
internal ref bool additionalLightShadowsEnabled => ref frameData.Get<UniversalShadowData>().additionalLightShadowsEnabled;
/// <summary>
/// The width of the additional light shadow map.
/// </summary>
public ref int additionalLightsShadowmapWidth => ref frameData.Get<UniversalShadowData>().additionalLightsShadowmapWidth;
/// <summary>
/// The height of the additional light shadow map.
/// </summary>
public ref int additionalLightsShadowmapHeight => ref frameData.Get<UniversalShadowData>().additionalLightsShadowmapHeight;
/// <summary>
/// True if soft shadows are enabled.
/// </summary>
public ref bool supportsSoftShadows => ref frameData.Get<UniversalShadowData>().supportsSoftShadows;
/// <summary>
/// The number of bits used.
/// </summary>
public ref int shadowmapDepthBufferBits => ref frameData.Get<UniversalShadowData>().shadowmapDepthBufferBits;
/// <summary>
/// A list of shadow bias.
/// </summary>
public ref List<Vector4> bias => ref frameData.Get<UniversalShadowData>().bias;
/// <summary>
/// A list of resolution for the shadow maps.
/// </summary>
public ref List<int> resolution => ref frameData.Get<UniversalShadowData>().resolution;
internal ref bool isKeywordAdditionalLightShadowsEnabled => ref frameData.Get<UniversalShadowData>().isKeywordAdditionalLightShadowsEnabled;
internal ref bool isKeywordSoftShadowsEnabled => ref frameData.Get<UniversalShadowData>().isKeywordSoftShadowsEnabled;
internal ref int mainLightShadowResolution => ref frameData.Get<UniversalShadowData>().mainLightShadowResolution;
internal ref int mainLightRenderTargetWidth => ref frameData.Get<UniversalShadowData>().mainLightRenderTargetWidth;
internal ref int mainLightRenderTargetHeight => ref frameData.Get<UniversalShadowData>().mainLightRenderTargetHeight;
internal ref NativeArray<URPLightShadowCullingInfos> visibleLightsShadowCullingInfos => ref frameData.Get<UniversalShadowData>().visibleLightsShadowCullingInfos;
internal ref AdditionalLightsShadowAtlasLayout shadowAtlasLayout => ref frameData.Get<UniversalShadowData>().shadowAtlasLayout;
}
/// <summary>
/// Precomputed tile data.
/// Tile left, right, bottom and top plane equations in view space.
/// Normals are pointing out.
/// </summary>
public struct PreTile
{
/// <summary>
/// The left plane.
/// </summary>
public Unity.Mathematics.float4 planeLeft;
/// <summary>
/// The right plane.
/// </summary>
public Unity.Mathematics.float4 planeRight;
/// <summary>
/// The bottom plane.
/// </summary>
public Unity.Mathematics.float4 planeBottom;
/// <summary>
/// The top plane.
/// </summary>
public Unity.Mathematics.float4 planeTop;
}
/// <summary>
/// The tile data passed to the deferred shaders.
/// </summary>
public struct TileData
{
/// <summary>
/// The tile ID.
/// </summary>
public uint tileID; // 2x 16 bits
/// <summary>
/// The list bit mask.
/// </summary>
public uint listBitMask; // 32 bits
/// <summary>
/// The relative light offset.
/// </summary>
public uint relLightOffset; // 16 bits is enough
/// <summary>
/// Unused variable.
/// </summary>
public uint unused;
}
/// <summary>
/// The point/spot light data passed to the deferred shaders.
/// </summary>
public struct PunctualLightData
{
/// <summary>
/// The world position.
/// </summary>
public Vector3 wsPos;
/// <summary>
/// The radius of the light.
/// </summary>
public float radius; // TODO remove? included in attenuation
/// <summary>
/// The color of the light.
/// </summary>
public Vector4 color;
/// <summary>
/// The attenuation of the light.
/// </summary>
public Vector4 attenuation; // .xy are used by DistanceAttenuation - .zw are used by AngleAttenuation (for SpotLights)
/// <summary>
/// The direction for spot lights.
/// </summary>
public Vector3 spotDirection; // for spotLights
/// <summary>
/// The flags used.
/// </summary>
public int flags;
/// <summary>
/// The occlusion probe info.
/// </summary>
public Vector4 occlusionProbeInfo;
/// <summary>
/// The layer mask used.
/// </summary>
public uint layerMask;
}
internal static class ShaderPropertyId
{
public static readonly int glossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
public static readonly int subtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");
public static readonly int glossyEnvironmentCubeMap = Shader.PropertyToID("_GlossyEnvironmentCubeMap");
public static readonly int glossyEnvironmentCubeMapHDR = Shader.PropertyToID("_GlossyEnvironmentCubeMap_HDR");
public static readonly int ambientSkyColor = Shader.PropertyToID("unity_AmbientSky");
public static readonly int ambientEquatorColor = Shader.PropertyToID("unity_AmbientEquator");
public static readonly int ambientGroundColor = Shader.PropertyToID("unity_AmbientGround");
public static readonly int time = Shader.PropertyToID("_Time");
public static readonly int sinTime = Shader.PropertyToID("_SinTime");
public static readonly int cosTime = Shader.PropertyToID("_CosTime");
public static readonly int deltaTime = Shader.PropertyToID("unity_DeltaTime");
public static readonly int timeParameters = Shader.PropertyToID("_TimeParameters");
public static readonly int lastTimeParameters = Shader.PropertyToID("_LastTimeParameters");
public static readonly int scaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");
public static readonly int worldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos");
public static readonly int screenParams = Shader.PropertyToID("_ScreenParams");
public static readonly int alphaToMaskAvailable = Shader.PropertyToID("_AlphaToMaskAvailable");
public static readonly int projectionParams = Shader.PropertyToID("_ProjectionParams");
public static readonly int zBufferParams = Shader.PropertyToID("_ZBufferParams");
public static readonly int orthoParams = Shader.PropertyToID("unity_OrthoParams");
public static readonly int globalMipBias = Shader.PropertyToID("_GlobalMipBias");
public static readonly int screenSize = Shader.PropertyToID("_ScreenSize");
public static readonly int screenCoordScaleBias = Shader.PropertyToID("_ScreenCoordScaleBias");
public static readonly int screenSizeOverride = Shader.PropertyToID("_ScreenSizeOverride");
public static readonly int viewMatrix = Shader.PropertyToID("unity_MatrixV");
public static readonly int projectionMatrix = Shader.PropertyToID("glstate_matrix_projection");
public static readonly int viewAndProjectionMatrix = Shader.PropertyToID("unity_MatrixVP");
public static readonly int inverseViewMatrix = Shader.PropertyToID("unity_MatrixInvV");
public static readonly int inverseProjectionMatrix = Shader.PropertyToID("unity_MatrixInvP");
public static readonly int inverseViewAndProjectionMatrix = Shader.PropertyToID("unity_MatrixInvVP");
public static readonly int cameraProjectionMatrix = Shader.PropertyToID("unity_CameraProjection");
public static readonly int inverseCameraProjectionMatrix = Shader.PropertyToID("unity_CameraInvProjection");
public static readonly int worldToCameraMatrix = Shader.PropertyToID("unity_WorldToCamera");
public static readonly int cameraToWorldMatrix = Shader.PropertyToID("unity_CameraToWorld");
public static readonly int shadowBias = Shader.PropertyToID("_ShadowBias");
public static readonly int lightDirection = Shader.PropertyToID("_LightDirection");
public static readonly int lightPosition = Shader.PropertyToID("_LightPosition");
public static readonly int cameraWorldClipPlanes = Shader.PropertyToID("unity_CameraWorldClipPlanes");
public static readonly int billboardNormal = Shader.PropertyToID("unity_BillboardNormal");
public static readonly int billboardTangent = Shader.PropertyToID("unity_BillboardTangent");
public static readonly int billboardCameraParams = Shader.PropertyToID("unity_BillboardCameraParams");
public static readonly int previousViewProjectionNoJitter = Shader.PropertyToID("_PrevViewProjMatrix");
public static readonly int viewProjectionNoJitter = Shader.PropertyToID("_NonJitteredViewProjMatrix");
#if ENABLE_VR && ENABLE_XR_MODULE
public static readonly int previousViewProjectionNoJitterStereo = Shader.PropertyToID("_PrevViewProjMatrixStereo");
public static readonly int viewProjectionNoJitterStereo = Shader.PropertyToID("_NonJitteredViewProjMatrixStereo");
#endif
public static readonly int blitTexture = Shader.PropertyToID("_BlitTexture");
public static readonly int blitScaleBias = Shader.PropertyToID("_BlitScaleBias");
public static readonly int sourceTex = Shader.PropertyToID("_SourceTex");
public static readonly int scaleBias = Shader.PropertyToID("_ScaleBias");
public static readonly int scaleBiasRt = Shader.PropertyToID("_ScaleBiasRt");
// This uniform is specific to the RTHandle system
public static readonly int rtHandleScale = Shader.PropertyToID("_RTHandleScale");
// Required for 2D Unlit Shadergraph master node as it doesn't currently support hidden properties.
public static readonly int rendererColor = Shader.PropertyToID("_RendererColor");
public static readonly int ditheringTexture = Shader.PropertyToID("_DitheringTexture");
public static readonly int ditheringTextureInvSize = Shader.PropertyToID("_DitheringTextureInvSize");
public static readonly int renderingLayerMaxInt = Shader.PropertyToID("_RenderingLayerMaxInt");
public static readonly int renderingLayerRcpMaxInt = Shader.PropertyToID("_RenderingLayerRcpMaxInt");
public static readonly int overlayUITexture = Shader.PropertyToID("_OverlayUITexture");
public static readonly int hdrOutputLuminanceParams = Shader.PropertyToID("_HDROutputLuminanceParams");
public static readonly int hdrOutputGradingParams = Shader.PropertyToID("_HDROutputGradingParams");
}
/// <summary>
/// Settings used for Post Processing.
/// </summary>
public struct PostProcessingData
{
ContextContainer frameData;
internal PostProcessingData(ContextContainer frameData)
{
this.frameData = frameData;
}
internal UniversalPostProcessingData universalPostProcessingData => frameData.Get<UniversalPostProcessingData>();
/// <summary>
/// The <c>ColorGradingMode</c> to use.
/// </summary>
/// <seealso cref="ColorGradingMode"/>
public ref ColorGradingMode gradingMode => ref frameData.Get<UniversalPostProcessingData>().gradingMode;
/// <summary>
/// The size of the Look Up Table (LUT)
/// </summary>
public ref int lutSize => ref frameData.Get<UniversalPostProcessingData>().lutSize;
/// <summary>
/// True if fast approximation functions are used when converting between the sRGB and Linear color spaces, false otherwise.
/// </summary>
public ref bool useFastSRGBLinearConversion => ref frameData.Get<UniversalPostProcessingData>().useFastSRGBLinearConversion;
/// <summary>
/// Returns true if Screen Space Lens Flare are supported by this asset, false otherwise.
/// </summary>
public ref bool supportScreenSpaceLensFlare => ref frameData.Get<UniversalPostProcessingData>().supportScreenSpaceLensFlare;
/// <summary>
/// Returns true if Data Driven Lens Flare are supported by this asset, false otherwise.
/// </summary>
public ref bool supportDataDrivenLensFlare => ref frameData.Get<UniversalPostProcessingData>().supportDataDrivenLensFlare;
}
internal static class ShaderGlobalKeywords
{
public static GlobalKeyword MainLightShadows;
public static GlobalKeyword MainLightShadowCascades;
public static GlobalKeyword MainLightShadowScreen;
public static GlobalKeyword CastingPunctualLightShadow;
public static GlobalKeyword AdditionalLightsVertex;
public static GlobalKeyword AdditionalLightsPixel;
public static GlobalKeyword ForwardPlus;
public static GlobalKeyword AdditionalLightShadows;
public static GlobalKeyword ReflectionProbeBoxProjection;
public static GlobalKeyword ReflectionProbeBlending;
public static GlobalKeyword SoftShadows;
public static GlobalKeyword SoftShadowsLow;
public static GlobalKeyword SoftShadowsMedium;
public static GlobalKeyword SoftShadowsHigh;
public static GlobalKeyword MixedLightingSubtractive; // Backward compatibility
public static GlobalKeyword LightmapShadowMixing;
public static GlobalKeyword ShadowsShadowMask;
public static GlobalKeyword LightLayers;
public static GlobalKeyword RenderPassEnabled;
public static GlobalKeyword BillboardFaceCameraPos;
public static GlobalKeyword LightCookies;
public static GlobalKeyword DepthNoMsaa;
public static GlobalKeyword DepthMsaa2;
public static GlobalKeyword DepthMsaa4;
public static GlobalKeyword DepthMsaa8;
public static GlobalKeyword DBufferMRT1;
public static GlobalKeyword DBufferMRT2;
public static GlobalKeyword DBufferMRT3;
public static GlobalKeyword DecalNormalBlendLow;
public static GlobalKeyword DecalNormalBlendMedium;
public static GlobalKeyword DecalNormalBlendHigh;
public static GlobalKeyword DecalLayers;
public static GlobalKeyword WriteRenderingLayers;
public static GlobalKeyword ScreenSpaceOcclusion;
public static GlobalKeyword _SPOT;
public static GlobalKeyword _DIRECTIONAL;
public static GlobalKeyword _POINT;
public static GlobalKeyword _DEFERRED_STENCIL;
public static GlobalKeyword _DEFERRED_FIRST_LIGHT;
public static GlobalKeyword _DEFERRED_MAIN_LIGHT;
public static GlobalKeyword _GBUFFER_NORMALS_OCT;
public static GlobalKeyword _DEFERRED_MIXED_LIGHTING;
public static GlobalKeyword LIGHTMAP_ON;
public static GlobalKeyword DYNAMICLIGHTMAP_ON;
public static GlobalKeyword _ALPHATEST_ON;
public static GlobalKeyword DIRLIGHTMAP_COMBINED;
public static GlobalKeyword _DETAIL_MULX2;
public static GlobalKeyword _DETAIL_SCALED;
public static GlobalKeyword _CLEARCOAT;
public static GlobalKeyword _CLEARCOATMAP;
public static GlobalKeyword DEBUG_DISPLAY;
public static GlobalKeyword LOD_FADE_CROSSFADE;
public static GlobalKeyword USE_UNITY_CROSSFADE;
public static GlobalKeyword _EMISSION;
public static GlobalKeyword _RECEIVE_SHADOWS_OFF;
public static GlobalKeyword _SURFACE_TYPE_TRANSPARENT;
public static GlobalKeyword _ALPHAPREMULTIPLY_ON;
public static GlobalKeyword _ALPHAMODULATE_ON;