-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathUniversalRendererRenderGraph.cs
1912 lines (1588 loc) · 103 KB
/
UniversalRendererRenderGraph.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.Runtime.CompilerServices;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering.RenderGraphModule;
using UnityEngine.Rendering.Universal.Internal;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Enumerates the identifiers to use with the FrameResource manager to get/set URP frame resources.
/// </summary>
public enum UniversalResource
{
/// <summary>
/// The backbuffer color used to render directly to screen. All passes can write to it depending on frame setup.
/// </summary>
BackBufferColor,
/// <summary>
/// The backbuffer depth used to render directly to screen. All passes can write to it depending on frame setup.
/// </summary>
BackBufferDepth,
// intermediate camera targets
/// <summary>
/// Main offscreen camera color target. All passes can write to it depending on frame setup.
/// Can hold multiple samples if MSAA is enabled.
/// </summary>
CameraColor,
/// <summary>
/// Main offscreen camera depth target. All passes can write to it depending on frame setup.
/// Can hold multiple samples if MSAA is enabled.
/// </summary>
CameraDepth,
// shadows
/// <summary>
/// Main shadow map.
/// </summary>
MainShadowsTexture,
/// <summary>
/// Additional shadow map.
/// </summary>
AdditionalShadowsTexture,
// gbuffer targets
/// <summary>
/// GBuffer0. Written to by the GBuffer pass.
/// </summary>
GBuffer0,
/// <summary>
/// GBuffer1. Written to by the GBuffer pass.
/// </summary>
GBuffer1,
/// <summary>
/// GBuffer2. Written to by the GBuffer pass.
/// </summary>
GBuffer2,
/// <summary>
/// GBuffer3. Written to by the GBuffer pass.
/// </summary>
GBuffer3,
/// <summary>
/// GBuffer4. Written to by the GBuffer pass.
/// </summary>
GBuffer4,
/// <summary>
/// GBuffer5. Written to by the GBuffer pass.
/// </summary>
GBuffer5,
/// <summary>
/// GBuffer6. Written to by the GBuffer pass.
/// </summary>
GBuffer6,
// camera opaque/depth/normal
/// <summary>
/// Camera opaque texture. Contains a copy of CameraColor if the CopyColor pass is executed.
/// </summary>
CameraOpaqueTexture,
/// <summary>
/// Camera depth texture. Contains the scene depth if the CopyDepth or Depth Prepass passes are executed.
/// </summary>
CameraDepthTexture,
/// <summary>
/// Camera normals texture. Contains the scene depth if the DepthNormals Prepass pass is executed.
/// </summary>
CameraNormalsTexture,
// motion vector
/// <summary>
/// Motion Vector Color. Written to by the Motion Vector passes.
/// </summary>
MotionVectorColor,
/// <summary>
/// Motion Vector Depth. Written to by the Motion Vector passes.
/// </summary>
MotionVectorDepth,
// postFx
/// <summary>
/// Internal Color LUT. Written to by the InternalLUT pass.
/// </summary>
InternalColorLut,
/// <summary>
/// Color output of post-process passes (uberPost and finalPost) when HDR debug views are enabled. It replaces
/// the backbuffer color as standard output because the later cannot be sampled back (or may not be in HDR format).
/// If used, DebugHandler will perform the blit from DebugScreenTexture to BackBufferColor.
/// </summary>
DebugScreenColor,
/// <summary>
/// Depth output of post-process passes (uberPost and finalPost) when HDR debug views are enabled. It replaces
/// the backbuffer depth as standard output because the later cannot be sampled back.
/// </summary>
DebugScreenDepth,
/// <summary>
/// After Post Process Color. Stores the contents of the main color target after the post processing passes.
/// </summary>
AfterPostProcessColor,
/// <summary>
/// Overlay UI Texture. The DrawScreenSpaceUI pass writes to this texture when rendering off-screen.
/// </summary>
OverlayUITexture,
// rendering layers
/// <summary>
/// Rendering Layers Texture. Can be written to by the DrawOpaques pass or DepthNormals prepass based on settings.
/// </summary>
RenderingLayersTexture,
// decals
/// <summary>
/// DBuffer0. Written to by the Decals pass.
/// </summary>
DBuffer0,
/// <summary>
/// DBuffer1. Written to by the Decals pass.
/// </summary>
DBuffer1,
/// <summary>
/// DBuffer2. Written to by the Decals pass.
/// </summary>
DBuffer2,
/// <summary>
/// DBufferDepth. Written to by the Decals pass.
/// </summary>
DBufferDepth,
/// <summary>
/// Screen Space Ambient Occlusion texture. Written to by the SSAO pass.
/// </summary>
SSAOTexture
}
public sealed partial class UniversalRenderer
{
// TODO RENDERGRAPH: Once all cameras will run in a single RenderGraph we should remove all RTHandles and use per frame RG textures.
// We use 2 camera color handles so we can handle the edge case when a pass might want to read and write the same target.
// This is not allowed so we just swap the current target, this keeps camera stacking working and avoids an extra blit pass.
private static RTHandle[] m_RenderGraphCameraColorHandles = new RTHandle[]
{
null, null
};
private static RTHandle[] m_RenderGraphUpscaledCameraColorHandles = new RTHandle[]
{
null, null
};
private static RTHandle m_RenderGraphCameraDepthHandle;
private static int m_CurrentColorHandle = 0;
private static bool m_UseUpscaledColorHandle = false;
private static RTHandle m_RenderGraphDebugTextureHandle;
private RTHandle currentRenderGraphCameraColorHandle
{
get
{
// Select between the pre-upscale and post-upscale color handle sets based on the current upscaling state
return m_UseUpscaledColorHandle ? m_RenderGraphUpscaledCameraColorHandles[m_CurrentColorHandle]
: m_RenderGraphCameraColorHandles[m_CurrentColorHandle];
}
}
// get the next m_RenderGraphCameraColorHandles and make it the new current for future accesses
private RTHandle nextRenderGraphCameraColorHandle
{
get
{
m_CurrentColorHandle = (m_CurrentColorHandle + 1) % 2;
return currentRenderGraphCameraColorHandle;
}
}
// rendering layers
private bool m_RequiresRenderingLayer;
private RenderingLayerUtils.Event m_RenderingLayersEvent;
private RenderingLayerUtils.MaskSize m_RenderingLayersMaskSize;
private bool m_RenderingLayerProvidesRenderObjectPass;
private bool m_RenderingLayerProvidesByDepthNormalPass;
private string m_RenderingLayersTextureName;
private void CleanupRenderGraphResources()
{
m_RenderGraphCameraColorHandles[0]?.Release();
m_RenderGraphCameraColorHandles[1]?.Release();
m_RenderGraphUpscaledCameraColorHandles[0]?.Release();
m_RenderGraphUpscaledCameraColorHandles[1]?.Release();
m_RenderGraphCameraDepthHandle?.Release();
m_RenderGraphDebugTextureHandle?.Release();
}
/// <summary>
/// Utility method to convert RenderTextureDescriptor to TextureHandle and create a RenderGraph texture
/// </summary>
/// <param name="renderGraph"></param>
/// <param name="desc"></param>
/// <param name="name"></param>
/// <param name="clear"></param>
/// <param name="filterMode"></param>
/// <param name="wrapMode"></param>
/// <returns></returns>
public static TextureHandle CreateRenderGraphTexture(RenderGraph renderGraph, RenderTextureDescriptor desc, string name, bool clear,
FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Clamp)
{
TextureDesc rgDesc = new TextureDesc(desc.width, desc.height);
rgDesc.dimension = desc.dimension;
rgDesc.clearBuffer = clear;
rgDesc.bindTextureMS = desc.bindMS;
rgDesc.format = (desc.depthStencilFormat != GraphicsFormat.None) ? desc.depthStencilFormat : desc.graphicsFormat;
rgDesc.slices = desc.volumeDepth;
rgDesc.msaaSamples = (MSAASamples)desc.msaaSamples;
rgDesc.name = name;
rgDesc.enableRandomWrite = desc.enableRandomWrite;
rgDesc.filterMode = filterMode;
rgDesc.wrapMode = wrapMode;
rgDesc.isShadowMap = desc.shadowSamplingMode != ShadowSamplingMode.None && desc.depthStencilFormat != GraphicsFormat.None;
rgDesc.vrUsage = desc.vrUsage;
rgDesc.useDynamicScale = desc.useDynamicScale;
rgDesc.useDynamicScaleExplicit = desc.useDynamicScaleExplicit;
return renderGraph.CreateTexture(rgDesc);
}
internal static TextureHandle CreateRenderGraphTexture(RenderGraph renderGraph, RenderTextureDescriptor desc, string name, bool clear, Color color,
FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Clamp)
{
TextureDesc rgDesc = new TextureDesc(desc.width, desc.height);
rgDesc.dimension = desc.dimension;
rgDesc.clearBuffer = clear;
rgDesc.clearColor = color;
rgDesc.bindTextureMS = desc.bindMS;
rgDesc.format = (desc.depthStencilFormat != GraphicsFormat.None) ? desc.depthStencilFormat : desc.graphicsFormat;
rgDesc.slices = desc.volumeDepth;
rgDesc.msaaSamples = (MSAASamples)desc.msaaSamples;
rgDesc.name = name;
rgDesc.enableRandomWrite = desc.enableRandomWrite;
rgDesc.filterMode = filterMode;
rgDesc.wrapMode = wrapMode;
rgDesc.useDynamicScale = desc.useDynamicScale;
rgDesc.useDynamicScaleExplicit = desc.useDynamicScaleExplicit;
return renderGraph.CreateTexture(rgDesc);
}
bool ShouldApplyPostProcessing(bool postProcessEnabled)
{
return postProcessEnabled && m_PostProcessPasses.isCreated;
}
bool CameraHasPostProcessingWithDepth(UniversalCameraData cameraData)
{
return ShouldApplyPostProcessing(cameraData.postProcessEnabled) && cameraData.postProcessingRequiresDepthTexture;
}
bool RequiresIntermediateAttachments(UniversalCameraData cameraData, ref RenderPassInputSummary renderPassInputs)
{
bool requiresDepthPrepass = RequireDepthPrepass(cameraData, ref renderPassInputs);
var requireColorTexture = HasActiveRenderFeatures() && m_IntermediateTextureMode == IntermediateTextureMode.Always;
requireColorTexture |= HasPassesRequiringIntermediateTexture();
requireColorTexture |= Application.isEditor && m_Clustering;
requireColorTexture |= RequiresIntermediateColorTexture(cameraData, ref renderPassInputs);
var requireDepthTexture = RequireDepthTexture(cameraData, requiresDepthPrepass, ref renderPassInputs);
useDepthPriming = IsDepthPrimingEnabled(cameraData);
// Intermediate texture has different yflip state than backbuffer. In case we use intermediate texture, we must use both color and depth together.
return (requireColorTexture || requireDepthTexture);
}
// Gather history render requests and manage camera history texture life-time.
private void UpdateCameraHistory(UniversalCameraData cameraData)
{
// NOTE: Can be null for non-game cameras.
// Technically each camera has AdditionalCameraData which owns the historyManager.
if (cameraData != null && cameraData.historyManager != null)
{
// XR multipass renders the frame twice, avoid updating camera history twice.
bool xrMultipassEnabled = false;
int multipassId = 0;
#if ENABLE_VR && ENABLE_XR_MODULE
xrMultipassEnabled = cameraData.xr.enabled && !cameraData.xr.singlePassEnabled;
multipassId = cameraData.xr.multipassId;
#endif
bool isNewFrame = !xrMultipassEnabled || (multipassId == 0);
if (isNewFrame)
{
var history = cameraData.historyManager;
// Gather all external user requests by callback.
history.GatherHistoryRequests();
// Typically we would also gather all the internal requests here before checking for unused textures.
// However the requests are versioned in the history manager, so we can defer the clean up for couple frames.
// Garbage collect all the unused persistent data instances. Free GPU resources if any.
// This will start a new "history frame".
history.ReleaseUnusedHistory();
// Swap and cycle camera history RTHandles. Update the reference size for the camera history RTHandles.
history.SwapAndSetReferenceSize(cameraData.cameraTargetDescriptor.width, cameraData.cameraTargetDescriptor.height);
}
}
}
const string _CameraTargetAttachmentAName = "_CameraTargetAttachmentA";
const string _CameraTargetAttachmentBName = "_CameraTargetAttachmentB";
const string _CameraUpscaledTargetAttachmentAName = "_CameraUpscaledTargetAttachmentA";
const string _CameraUpscaledTargetAttachmentBName = "_CameraUpscaledTargetAttachmentB";
void CreateRenderGraphCameraRenderTargets(RenderGraph renderGraph, bool isCameraTargetOffscreenDepth)
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
UniversalPostProcessingData postProcessingData = frameData.Get<UniversalPostProcessingData>();
bool lastCameraInTheStack = cameraData.resolveFinalTarget;
bool isBuiltInTexture = (cameraData.targetTexture == null);
RenderTargetIdentifier targetColorId = cameraData.targetTexture != null ? new RenderTargetIdentifier(cameraData.targetTexture) : BuiltinRenderTextureType.CameraTarget;
RenderTargetIdentifier targetDepthId = cameraData.targetTexture != null ? new RenderTargetIdentifier(cameraData.targetTexture) : BuiltinRenderTextureType.Depth;
bool clearColor = cameraData.renderType == CameraRenderType.Base;
bool clearDepth = cameraData.renderType == CameraRenderType.Base || cameraData.clearDepth;
// if the camera background type is "uninitialized" clear using a yellow color, so users can clearly understand the underlying behaviour
// only exception being if we are rendering to an external texture
Color cameraBackgroundColor = (cameraData.camera.clearFlags == CameraClearFlags.Nothing && cameraData.targetTexture == null) ? Color.yellow : cameraData.backgroundColor;
// If scene filtering is enabled (prefab edit mode), the filtering is implemented compositing some builtin ImageEffect passes.
// For the composition to work, we need to clear the color buffer alpha to 0
// How filtering works:
// - SRP frame is fully rendered as background
// - builtin ImageEffect pass grey-out of the full scene previously rendered
// - SRP frame rendering only the objects belonging to the prefab being edited (with clearColor.a = 0)
// - builtin ImageEffect pass compositing the two previous passes
// TODO: We should implement filtering fully in SRP to remove builtin dependencies
if (IsSceneFilteringEnabled(cameraData.camera))
{
cameraBackgroundColor.a = 0;
clearDepth = false;
}
// Certain debug modes (e.g. wireframe/overdraw modes) require that we override clear flags and clear everything.
var debugHandler = cameraData.renderer.DebugHandler;
if (debugHandler != null && debugHandler.IsActiveForCamera(cameraData.isPreviewCamera) && debugHandler.IsScreenClearNeeded)
{
clearColor = true;
clearDepth = true;
if ((DebugHandler != null) && DebugHandler.IsActiveForCamera(cameraData.isPreviewCamera))
{
DebugHandler.TryGetScreenClearColor(ref cameraBackgroundColor);
}
}
ImportResourceParams importColorParams = new ImportResourceParams();
importColorParams.clearOnFirstUse = clearColor; // && cameraData.camera.clearFlags != CameraClearFlags.Nothing;
importColorParams.clearColor = cameraBackgroundColor;
importColorParams.discardOnLastUse = false;
ImportResourceParams importDepthParams = new ImportResourceParams();
importDepthParams.clearOnFirstUse = clearDepth;
importDepthParams.clearColor = cameraBackgroundColor;
importDepthParams.discardOnLastUse = false;
#if ENABLE_VR && ENABLE_XR_MODULE
if (cameraData.xr.enabled)
{
targetColorId = cameraData.xr.renderTarget;
targetDepthId = cameraData.xr.renderTarget;
isBuiltInTexture = false;
}
#endif
if (m_TargetColorHandle == null)
{
m_TargetColorHandle = RTHandles.Alloc(targetColorId, "Backbuffer color");
}
else if(m_TargetColorHandle.nameID != targetColorId)
{
RTHandleStaticHelpers.SetRTHandleUserManagedWrapper(ref m_TargetColorHandle, targetColorId);
}
if (m_TargetDepthHandle == null)
{
m_TargetDepthHandle = RTHandles.Alloc(targetDepthId, "Backbuffer depth");
}
else if (m_TargetDepthHandle.nameID != targetDepthId)
{
RTHandleStaticHelpers.SetRTHandleUserManagedWrapper(ref m_TargetDepthHandle, targetDepthId);
}
// Gather render pass history requests and update history textures.
UpdateCameraHistory(cameraData);
RenderPassInputSummary renderPassInputs = GetRenderPassInputs(cameraData.IsTemporalAAEnabled(), postProcessingData.isEnabled, cameraData.isSceneViewCamera);
// Enable depth normal prepass if it's needed by rendering layers
if (m_RenderingLayerProvidesByDepthNormalPass)
renderPassInputs.requiresNormalsTexture = true;
// We configure this for the first camera of the stack and overlay camera will reuse create color/depth var
// to pick the correct target, as if there is an intermediate texture, overlay cam should use them
if (cameraData.renderType == CameraRenderType.Base)
m_RequiresIntermediateAttachments = RequiresIntermediateAttachments(cameraData, ref renderPassInputs);
// The final output back buffer should be cleared by the graph on first use only if we have no final blit pass.
// If there is a final blit, that blit will write the buffers so on first sight an extra clear should not be problem,
// blit will simply blit over the cleared values. BUT! the final blit may not write the whole buffer in case of a camera
// with a Viewport Rect smaller than the full screen. So the existing backbuffer contents need to be preserved in this case.
// Finally for non-base cameras the backbuffer should never be cleared. (Note that there might still be two base cameras
// rendering to the same screen. See e.g. test foundation 014 that renders a minimap)
bool clearBackbufferOnFirstUse = (cameraData.renderType == CameraRenderType.Base) && !m_RequiresIntermediateAttachments;
// force the clear if we are rendering to an offscreen depth texture
clearBackbufferOnFirstUse |= isCameraTargetOffscreenDepth;
// UI Overlay is rendered by native engine if not done within SRP
// To check if the engine does it natively post-URP, we look at SupportedRenderingFeatures
// and restrict it to cases where we resolve to screen and render UI overlay, i.e mostly final camera for game view
// We cannot use directly !cameraData.rendersOverlayUI but this is similar logic
bool isNativeUIOverlayRenderingAfterURP = !SupportedRenderingFeatures.active.rendersUIOverlay && cameraData.resolveToScreen;
bool isNativeRenderingAfterURP = UnityEngine.Rendering.Watermark.IsVisible() || isNativeUIOverlayRenderingAfterURP;
// If MSAA > 1, no extra native rendering after SRP and we target the BB directly (!m_RequiresIntermediateAttachments)
// then we can discard MSAA buffers and only resolve, otherwise we must store and resolve
bool noStoreOnlyResolveBBColor = !m_RequiresIntermediateAttachments && !isNativeRenderingAfterURP && (cameraData.cameraTargetDescriptor.msaaSamples > 1);
ImportResourceParams importBackbufferColorParams = new ImportResourceParams();
importBackbufferColorParams.clearOnFirstUse = clearBackbufferOnFirstUse;
importBackbufferColorParams.clearColor = cameraBackgroundColor;
importBackbufferColorParams.discardOnLastUse = noStoreOnlyResolveBBColor;
ImportResourceParams importBackbufferDepthParams = new ImportResourceParams();
importBackbufferDepthParams.clearOnFirstUse = clearBackbufferOnFirstUse;
importBackbufferDepthParams.clearColor = cameraBackgroundColor;
importBackbufferDepthParams.discardOnLastUse = !isCameraTargetOffscreenDepth;
#if UNITY_EDITOR
// on TBDR GPUs like Apple M1/M2, we need to preserve the backbuffer depth for overlay cameras in Editor for Gizmos
if (cameraData.isSceneViewCamera)
importBackbufferDepthParams.discardOnLastUse = false;
#endif
#if ENABLE_VR && ENABLE_XR_MODULE
// some XR devices require depth data to composite the final image. In such case, we need to preserve the eyetexture(backbuffer) depth.
if (cameraData.xr.enabled && cameraData.xr.copyDepth)
{
importBackbufferDepthParams.discardOnLastUse = false;
}
#endif
// For BuiltinRenderTextureType wrapping RTHandles RenderGraph can't know what they are so we have to pass it in.
RenderTargetInfo importInfo = new RenderTargetInfo();
RenderTargetInfo importInfoDepth = new RenderTargetInfo();
// So the render target we pass into render graph is
// RTHandles(RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget))
// or
// RTHandles(RenderTargetIdentifier(RenderTexture(cameraData.targetTexture)))
//
// Because of the RenderTargetIdentifier in the "wrapper chain" the graph can't know
// the size of the passed in textures so we need to provide it for the graph.
// The amount of texture handle wrappers and their subtleties is probably something to be investigated.
if (isBuiltInTexture)
{
// Backbuffer is the final render target, we obtain its number of MSAA samples through Screen API
// in some cases we disable multisampling for optimization purpose
int numSamples = AdjustAndGetScreenMSAASamples(renderGraph, m_RequiresIntermediateAttachments);
//BuiltinRenderTextureType.CameraTarget so this is either system render target or camera.targetTexture if non null
//NOTE: Careful what you use here as many of the properties bake-in the camera rect so for example
//cameraData.cameraTargetDescriptor.width is the width of the rectangle but not the actual render target
//same with cameraData.camera.pixelWidth
importInfo.width = Screen.width;
importInfo.height = Screen.height;
importInfo.volumeDepth = 1;
importInfo.msaaSamples = numSamples;
importInfo.format = cameraData.cameraTargetDescriptor.graphicsFormat;
importInfoDepth = importInfo;
importInfoDepth.format = cameraData.cameraTargetDescriptor.depthStencilFormat;
}
else
{
#if ENABLE_VR && ENABLE_XR_MODULE
if (cameraData.xr.enabled)
{
importInfo.width = cameraData.xr.renderTargetDesc.width;
importInfo.height = cameraData.xr.renderTargetDesc.height;
importInfo.volumeDepth = cameraData.xr.renderTargetDesc.volumeDepth;
importInfo.msaaSamples = cameraData.xr.renderTargetDesc.msaaSamples;
importInfo.format = cameraData.xr.renderTargetDesc.graphicsFormat;
importInfoDepth = importInfo;
importInfoDepth.format = cameraData.xr.renderTargetDesc.depthStencilFormat;
}
else
#endif
{
importInfo.width = cameraData.targetTexture.width;
importInfo.height = cameraData.targetTexture.height;
importInfo.volumeDepth = cameraData.targetTexture.volumeDepth;
importInfo.msaaSamples = cameraData.targetTexture.antiAliasing;
importInfo.format = cameraData.targetTexture.graphicsFormat;
importInfoDepth = importInfo;
importInfoDepth.format = cameraData.targetTexture.depthStencilFormat;
}
// We let users know that a depth format is required for correct usage, but we fallback to the old default depth format behaviour to avoid regressions
if (importInfoDepth.format == GraphicsFormat.None)
{
importInfoDepth.format = SystemInfo.GetGraphicsFormat(DefaultFormat.DepthStencil);
Debug.LogWarning("In the render graph API, the output Render Texture must have a depth buffer. When you select a Render Texture in any camera's Output Texture property, the Depth Stencil Format property of the texture must be set to a value other than None.");
}
}
// TODO: Don't think the backbuffer color and depth should be imported at all if !isBuiltinTexture, double check
if (!isCameraTargetOffscreenDepth)
resourceData.backBufferColor = renderGraph.ImportTexture(m_TargetColorHandle, importInfo, importBackbufferColorParams);
resourceData.backBufferDepth = renderGraph.ImportTexture(m_TargetDepthHandle, importInfoDepth, importBackbufferDepthParams);
#region Intermediate Camera Target
if (m_RequiresIntermediateAttachments && !isCameraTargetOffscreenDepth)
{
var cameraTargetDescriptor = cameraData.cameraTargetDescriptor;
cameraTargetDescriptor.useMipMap = false;
cameraTargetDescriptor.autoGenerateMips = false;
cameraTargetDescriptor.depthStencilFormat = GraphicsFormat.None;
RenderingUtils.ReAllocateHandleIfNeeded(ref m_RenderGraphCameraColorHandles[0], cameraTargetDescriptor, FilterMode.Bilinear, TextureWrapMode.Clamp, name: _CameraTargetAttachmentAName);
RenderingUtils.ReAllocateHandleIfNeeded(ref m_RenderGraphCameraColorHandles[1], cameraTargetDescriptor, FilterMode.Bilinear, TextureWrapMode.Clamp, name: _CameraTargetAttachmentBName);
// Make sure that the base camera always starts rendering to the ColorAttachmentA for deterministic frame results.
// Not doing so makes the targets look different every frame, causing the frame debugger to flash, and making debugging harder.
if (cameraData.renderType == CameraRenderType.Base)
{
m_CurrentColorHandle = 0;
// Base camera rendering always starts with a pre-upscale size color target
// If upscaling happens during the frame, we'll switch to the post-upscale color target size and any overlay camera that renders on top should inherit the upscaled size
m_UseUpscaledColorHandle = false;
}
importColorParams.discardOnLastUse = lastCameraInTheStack;
resourceData.cameraColor = renderGraph.ImportTexture(currentRenderGraphCameraColorHandle, importColorParams);
resourceData.activeColorID = UniversalResourceData.ActiveID.Camera;
// If STP is enabled, we'll be upscaling the rendered frame during the post processing logic.
// Once upscaling occurs, we must use different set of color handles that reflect the upscaled size.
if (cameraData.IsSTPEnabled())
{
var upscaledTargetDesc = cameraTargetDescriptor;
upscaledTargetDesc.width = cameraData.pixelWidth;
upscaledTargetDesc.height = cameraData.pixelHeight;
RenderingUtils.ReAllocateHandleIfNeeded(ref m_RenderGraphUpscaledCameraColorHandles[0], upscaledTargetDesc, FilterMode.Point, TextureWrapMode.Clamp, name: _CameraUpscaledTargetAttachmentAName);
RenderingUtils.ReAllocateHandleIfNeeded(ref m_RenderGraphUpscaledCameraColorHandles[1], upscaledTargetDesc, FilterMode.Point, TextureWrapMode.Clamp, name: _CameraUpscaledTargetAttachmentBName);
}
}
else
{
resourceData.activeColorID = UniversalResourceData.ActiveID.BackBuffer;
}
bool depthTextureIsDepthFormat = RequireDepthPrepass(cameraData, ref renderPassInputs) && (renderingModeActual != RenderingMode.Deferred);
if (m_RequiresIntermediateAttachments)
{
var depthDescriptor = cameraData.cameraTargetDescriptor;
depthDescriptor.useMipMap = false;
depthDescriptor.autoGenerateMips = false;
bool hasMSAA = depthDescriptor.msaaSamples > 1;
bool resolveDepth = RenderingUtils.MultisampleDepthResolveSupported() && renderGraph.nativeRenderPassesEnabled;
// If we aren't using hardware depth resolves and we have MSAA, we need to resolve depth manually by binding as an MSAA texture.
depthDescriptor.bindMS = !resolveDepth && hasMSAA;
// binding MS surfaces is not supported by the GLES backend, and it won't be fixed after investigating
// the high performance impact of potential fixes, which would make it more expensive than depth prepass (fogbugz 1339401 for more info)
if (IsGLESDevice())
depthDescriptor.bindMS = false;
depthDescriptor.graphicsFormat = GraphicsFormat.None;
depthDescriptor.depthStencilFormat = cameraDepthAttachmentFormat;
RenderingUtils.ReAllocateHandleIfNeeded(ref m_RenderGraphCameraDepthHandle, depthDescriptor, FilterMode.Point, TextureWrapMode.Clamp, name: "_CameraDepthAttachment");
importDepthParams.discardOnLastUse = lastCameraInTheStack;
#if UNITY_EDITOR
// scene filtering will reuse "camera" depth from the normal pass for the "filter highlight" effect
if (cameraData.isSceneViewCamera && CoreUtils.IsSceneFilteringEnabled())
importDepthParams.discardOnLastUse = false;
#endif
resourceData.cameraDepth = renderGraph.ImportTexture(m_RenderGraphCameraDepthHandle, importDepthParams);
resourceData.activeDepthID = UniversalResourceData.ActiveID.Camera;
// Configure the copy depth pass based on the allocated depth texture
m_CopyDepthPass.MssaSamples = depthDescriptor.msaaSamples;
m_CopyDepthPass.CopyToDepth = depthTextureIsDepthFormat;
m_CopyDepthPass.m_CopyResolvedDepth = !depthDescriptor.bindMS;
}
else
{
resourceData.activeDepthID = UniversalResourceData.ActiveID.BackBuffer;
}
#endregion
CreateCameraDepthCopyTexture(renderGraph, cameraData.cameraTargetDescriptor, depthTextureIsDepthFormat);
CreateCameraNormalsTexture(renderGraph, cameraData.cameraTargetDescriptor);
CreateMotionVectorTextures(renderGraph, cameraData.cameraTargetDescriptor);
CreateRenderingLayersTexture(renderGraph, cameraData.cameraTargetDescriptor);
if (!isCameraTargetOffscreenDepth)
CreateAfterPostProcessTexture(renderGraph, cameraData.cameraTargetDescriptor);
}
void SetupRenderingLayers(int msaaSamples)
{
// Gather render pass require rendering layers event and mask size
m_RequiresRenderingLayer = RenderingLayerUtils.RequireRenderingLayers(this, rendererFeatures, msaaSamples,
out m_RenderingLayersEvent, out m_RenderingLayersMaskSize);
m_RenderingLayerProvidesRenderObjectPass = m_RequiresRenderingLayer && m_RenderingLayersEvent == RenderingLayerUtils.Event.Opaque;
m_RenderingLayerProvidesByDepthNormalPass = m_RequiresRenderingLayer && m_RenderingLayersEvent == RenderingLayerUtils.Event.DepthNormalPrePass;
if (m_DeferredLights != null)
{
m_DeferredLights.RenderingLayerMaskSize = m_RenderingLayersMaskSize;
m_DeferredLights.UseDecalLayers = m_RequiresRenderingLayer;
}
}
internal void SetupRenderGraphLights(RenderGraph renderGraph, UniversalRenderingData renderingData, UniversalCameraData cameraData, UniversalLightData lightData)
{
m_ForwardLights.SetupRenderGraphLights(renderGraph, renderingData, cameraData, lightData);
if (this.renderingModeActual == RenderingMode.Deferred)
{
m_DeferredLights.UseFramebufferFetch = renderGraph.nativeRenderPassesEnabled;
m_DeferredLights.SetupRenderGraphLights(renderGraph, cameraData, lightData);
}
}
// "Raw render" color/depth history.
// Should include opaque and transparent geometry before TAA or any post-processing effects. No UI overlays etc.
private void RenderRawColorDepthHistory(RenderGraph renderGraph, UniversalCameraData cameraData, UniversalResourceData resourceData)
{
if (cameraData != null && cameraData.historyManager != null && resourceData != null)
{
UniversalCameraHistory history = cameraData.historyManager;
bool xrMultipassEnabled = false;
int multipassId = 0;
#if ENABLE_VR && ENABLE_XR_MODULE
xrMultipassEnabled = cameraData.xr.enabled && !cameraData.xr.singlePassEnabled;
multipassId = cameraData.xr.multipassId;
#endif
if (history.IsAccessRequested<RawColorHistory>() && resourceData.cameraColor.IsValid())
{
var colorHistory = history.GetHistoryForWrite<RawColorHistory>();
if (colorHistory != null)
{
colorHistory.Update(ref cameraData.cameraTargetDescriptor, xrMultipassEnabled);
if (colorHistory.GetCurrentTexture(multipassId) != null)
{
var colorHistoryTarget = renderGraph.ImportTexture(colorHistory.GetCurrentTexture(multipassId));
// See pass create in UniversalRenderer() for execution order.
m_HistoryRawColorCopyPass.RenderToExistingTexture(renderGraph, frameData, colorHistoryTarget, resourceData.cameraColor, Downsampling.None);
}
}
}
if (history.IsAccessRequested<RawDepthHistory>() && resourceData.cameraDepth.IsValid())
{
var depthHistory = history.GetHistoryForWrite<RawDepthHistory>();
if (depthHistory != null)
{
if (m_HistoryRawDepthCopyPass.CopyToDepth == false)
{
// Fall back to R32_Float if depth copy is disabled.
var tempColorDepthDesc = cameraData.cameraTargetDescriptor;
tempColorDepthDesc.graphicsFormat = GraphicsFormat.R32_SFloat;
tempColorDepthDesc.depthStencilFormat = GraphicsFormat.None;
depthHistory.Update(ref tempColorDepthDesc, xrMultipassEnabled);
}
else
{
var tempColorDepthDesc = cameraData.cameraTargetDescriptor;
tempColorDepthDesc.graphicsFormat = GraphicsFormat.None;
depthHistory.Update(ref tempColorDepthDesc, xrMultipassEnabled);
}
if (depthHistory.GetCurrentTexture(multipassId) != null)
{
var depthHistoryTarget = renderGraph.ImportTexture(depthHistory.GetCurrentTexture(multipassId));
// See pass create in UniversalRenderer() for execution order.
m_HistoryRawDepthCopyPass.Render(renderGraph, frameData, depthHistoryTarget, resourceData.cameraDepth, false);
}
}
}
}
}
/// <summary>
/// Called before recording the render graph. Can be used to initialize resources.
/// </summary>
public override void OnBeginRenderGraphFrame()
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
resourceData.InitFrame();
}
internal override void OnRecordRenderGraph(RenderGraph renderGraph, ScriptableRenderContext context)
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalRenderingData renderingData = frameData.Get<UniversalRenderingData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
useRenderPassEnabled = renderGraph.nativeRenderPassesEnabled;
MotionVectorRenderPass.SetRenderGraphMotionVectorGlobalMatrices(renderGraph, cameraData);
SetupRenderGraphLights(renderGraph, renderingData, cameraData, lightData);
SetupRenderingLayers(cameraData.cameraTargetDescriptor.msaaSamples);
bool isCameraTargetOffscreenDepth = cameraData.camera.targetTexture != null && cameraData.camera.targetTexture.format == RenderTextureFormat.Depth;
CreateRenderGraphCameraRenderTargets(renderGraph, isCameraTargetOffscreenDepth);
if (DebugHandler != null)
DebugHandler.Setup(renderGraph, cameraData.isPreviewCamera);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.BeforeRendering);
SetupRenderGraphCameraProperties(renderGraph, resourceData.isActiveTargetBackBuffer);
#if VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER
ProcessVFXCameraCommand(renderGraph);
#endif
cameraData.renderer.useDepthPriming = useDepthPriming;
if (isCameraTargetOffscreenDepth)
{
OnOffscreenDepthTextureRendering(renderGraph, context, resourceData, cameraData);
return;
}
OnBeforeRendering(renderGraph);
BeginRenderGraphXRRendering(renderGraph);
OnMainRendering(renderGraph, context);
OnAfterRendering(renderGraph);
EndRenderGraphXRRendering(renderGraph);
}
/// <summary>
/// Called after recording the render graph. Can be used to clean up resources.
/// </summary>
public override void OnEndRenderGraphFrame()
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
resourceData.EndFrame();
}
internal override void OnFinishRenderGraphRendering(CommandBuffer cmd)
{
if (this.renderingModeActual == RenderingMode.Deferred)
m_DeferredPass.OnCameraCleanup(cmd);
m_CopyDepthPass.OnCameraCleanup(cmd);
m_DepthNormalPrepass.OnCameraCleanup(cmd);
}
private bool m_IssuedGPUOcclusionUnsupportedMsg = false;
/// <summary>
/// Used to determine if this renderer supports the use of GPU occlusion culling.
/// </summary>
public override bool supportsGPUOcclusion
{
get
{
// UUM-82677: GRD GPU Occlusion Culling on Vulkan breaks rendering on some mobile GPUs
//
// We currently disable gpu occlusion culling when running on Qualcomm GPUs due to suspected driver issues.
// Once the issue is resolved, this logic should be removed.
const int kQualcommVendorId = 0x5143;
bool isGpuSupported = SystemInfo.graphicsDeviceVendorID != kQualcommVendorId;
if (!isGpuSupported && !m_IssuedGPUOcclusionUnsupportedMsg)
{
Debug.LogWarning("The GPU Occlusion Culling feature is currently unavailable on this device due to suspected driver issues.");
m_IssuedGPUOcclusionUnsupportedMsg = true;
}
return (m_RenderingMode != RenderingMode.Deferred) && isGpuSupported;
}
}
private static bool m_RequiresIntermediateAttachments;
private void OnOffscreenDepthTextureRendering(RenderGraph renderGraph, ScriptableRenderContext context, UniversalResourceData resourceData, UniversalCameraData cameraData)
{
if (!renderGraph.nativeRenderPassesEnabled)
ClearTargetsPass.Render(renderGraph, resourceData.activeColorTexture, resourceData.backBufferDepth, RTClearFlags.Depth, cameraData.backgroundColor);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.BeforeRenderingShadows, RenderPassEvent.BeforeRenderingOpaques);
m_RenderOpaqueForwardPass.Render(renderGraph, frameData, TextureHandle.nullHandle, resourceData.backBufferDepth, TextureHandle.nullHandle, TextureHandle.nullHandle, uint.MaxValue);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.AfterRenderingOpaques, RenderPassEvent.BeforeRenderingTransparents);
#if ADAPTIVE_PERFORMANCE_2_1_0_OR_NEWER
if (needTransparencyPass)
#endif
m_RenderTransparentForwardPass.Render(renderGraph, frameData, TextureHandle.nullHandle, resourceData.backBufferDepth, TextureHandle.nullHandle, TextureHandle.nullHandle, uint.MaxValue);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.AfterRenderingTransparents, RenderPassEvent.AfterRendering);
}
private void OnBeforeRendering(RenderGraph renderGraph)
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalRenderingData renderingData = frameData.Get<UniversalRenderingData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
UniversalShadowData shadowData = frameData.Get<UniversalShadowData>();
m_ForwardLights.PreSetup(renderingData, cameraData, lightData);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.BeforeRenderingShadows);
bool renderShadows = false;
if (m_MainLightShadowCasterPass.Setup(renderingData, cameraData, lightData, shadowData))
{
renderShadows = true;
resourceData.mainShadowsTexture = m_MainLightShadowCasterPass.Render(renderGraph, frameData);
}
if (m_AdditionalLightsShadowCasterPass.Setup(renderingData, cameraData, lightData, shadowData))
{
renderShadows = true;
resourceData.additionalShadowsTexture = m_AdditionalLightsShadowCasterPass.Render(renderGraph, frameData);
}
// The camera need to be setup again after the shadows since those passes override some settings
// TODO RENDERGRAPH: move the setup code into the shadow passes
if (renderShadows)
SetupRenderGraphCameraProperties(renderGraph, resourceData.isActiveTargetBackBuffer);
RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.AfterRenderingShadows);
bool requiredColorGradingLutPass = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated;
if (requiredColorGradingLutPass)
{
TextureHandle internalColorLut;
m_PostProcessPasses.colorGradingLutPass.Render(renderGraph, frameData, out internalColorLut);
resourceData.internalColorLut = internalColorLut;
}
}
private void UpdateInstanceOccluders(RenderGraph renderGraph, UniversalCameraData cameraData, TextureHandle depthTexture)
{
int scaledWidth = (int)(cameraData.pixelWidth * cameraData.renderScale);
int scaledHeight = (int)(cameraData.pixelHeight * cameraData.renderScale);
bool isSinglePassXR = cameraData.xr.enabled && cameraData.xr.singlePassEnabled;
var occluderParams = new OccluderParameters(cameraData.camera.GetInstanceID())
{
subviewCount = isSinglePassXR ? 2 : 1,
depthTexture = depthTexture,
depthSize = new Vector2Int(scaledWidth, scaledHeight),
depthIsArray = isSinglePassXR,
};
Span<OccluderSubviewUpdate> occluderSubviewUpdates = stackalloc OccluderSubviewUpdate[occluderParams.subviewCount];
for (int subviewIndex = 0; subviewIndex < occluderParams.subviewCount; ++subviewIndex)
{
var viewMatrix = cameraData.GetViewMatrix(subviewIndex);
var projMatrix = cameraData.GetProjectionMatrix(subviewIndex);
occluderSubviewUpdates[subviewIndex] = new OccluderSubviewUpdate(subviewIndex)
{
depthSliceIndex = subviewIndex,
viewMatrix = viewMatrix,
invViewMatrix = viewMatrix.inverse,
gpuProjMatrix = GL.GetGPUProjectionMatrix(projMatrix, true),
viewOffsetWorldSpace = Vector3.zero,
};
}
GPUResidentDrawer.UpdateInstanceOccluders(renderGraph, occluderParams, occluderSubviewUpdates);
}
private void InstanceOcclusionTest(RenderGraph renderGraph, UniversalCameraData cameraData, OcclusionTest occlusionTest)
{
bool isSinglePassXR = cameraData.xr.enabled && cameraData.xr.singlePassEnabled;
int subviewCount = isSinglePassXR ? 2 : 1;
var settings = new OcclusionCullingSettings(cameraData.camera.GetInstanceID(), occlusionTest)
{
instanceMultiplier = (isSinglePassXR && !SystemInfo.supportsMultiview) ? 2 : 1,
};
Span<SubviewOcclusionTest> subviewOcclusionTests = stackalloc SubviewOcclusionTest[subviewCount];
for (int subviewIndex = 0; subviewIndex < subviewCount; ++subviewIndex)
{
subviewOcclusionTests[subviewIndex] = new SubviewOcclusionTest()
{
cullingSplitIndex = 0,
occluderSubviewIndex = subviewIndex,
};
}
GPUResidentDrawer.InstanceOcclusionTest(renderGraph, settings, subviewOcclusionTests);
}
// Records the depth copy pass along with the specified custom passes in a way that properly handles depth read dependencies
// This function will also trigger motion vector rendering if required by the current frame since its availability is intended to match depth's.
private void RecordCustomPassesWithDepthCopyAndMotion(RenderGraph renderGraph, UniversalResourceData resourceData, RenderPassEvent earliestDepthReadEvent, RenderPassEvent currentEvent, bool renderMotionVectors)
{
// Custom passes typically come before built-in passes but there's an exception for passes that require depth.
// In cases where custom passes passes may depend on depth, we split the event range and execute the depth copy as late as possible while still ensuring valid depth reads.
CalculateSplitEventRange(currentEvent, earliestDepthReadEvent, out var startEvent, out var splitEvent, out var endEvent);
RecordCustomRenderGraphPassesInEventRange(renderGraph, startEvent, splitEvent);
ExecuteScheduledDepthCopyWithMotion(renderGraph, resourceData, renderMotionVectors);
RecordCustomRenderGraphPassesInEventRange(renderGraph, splitEvent, endEvent);
}
// Returns true if the current render pass inputs allow us to perform a partial depth normals prepass
//
// During a partial prepass, we only render forward opaque objects that aren't rendered into the gbuffer.
// This produces a set of partial depth & normal buffers that must be completed by the gbuffer pass later in the frame.
// This allows us to produce complete depth & normals data before lighting takes place, but it isn't valid when custom
// passes require this data before the gbuffer pass finishes.
private bool AllowPartialDepthNormalsPrepass(bool isDeferred, RenderPassEvent requiresDepthNormalEvent)
{
return isDeferred && ((RenderPassEvent.AfterRenderingGbuffer <= requiresDepthNormalEvent) &&
(requiresDepthNormalEvent <= RenderPassEvent.BeforeRenderingOpaques));
}
// Enumeration of possible positions within the frame where the depth copy can occur
private enum DepthCopySchedule
{
// In some cases, we can render depth directly to the depth texture during the depth prepass
DuringPrepass,
AfterPrepass,
AfterGBuffer,
AfterOpaques,
AfterSkybox,
AfterTransparents,
// None is always the last value so we can easily check if the depth has already been copied in the current frame via comparison
None
}
// Enumeration of possible positions within the frame where the color copy pass can be scheduled
private enum ColorCopySchedule
{