-
Notifications
You must be signed in to change notification settings - Fork 870
Expand file tree
/
Copy pathCustomPass.cs
More file actions
574 lines (502 loc) · 27.8 KB
/
CustomPass.cs
File metadata and controls
574 lines (502 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
using System.Collections.Generic;
using System;
using UnityEngine.Serialization;
using UnityEngine.Experimental.Rendering.RenderGraphModule;
namespace UnityEngine.Rendering.HighDefinition
{
/// <summary>
/// Class that holds data and logic for the pass to be executed
/// </summary>
[System.Serializable]
public abstract class CustomPass : IVersionable<DrawRenderersCustomPass.Version>
{
/// <summary>
/// Name of the custom pass
/// </summary>
public string name
{
get => m_Name;
set
{
m_Name = value;
m_ProfilingSampler = new ProfilingSampler(m_Name);
}
}
[SerializeField, FormerlySerializedAsAttribute("name")]
string m_Name = "Custom Pass";
internal ProfilingSampler profilingSampler
{
get
{
if (m_ProfilingSampler == null)
m_ProfilingSampler = new ProfilingSampler(m_Name ?? "Custom Pass");
return m_ProfilingSampler;
}
}
ProfilingSampler m_ProfilingSampler;
/// <summary>
/// Is the custom pass enabled or not
/// </summary>
public bool enabled = true;
/// <summary>
/// Target color buffer (Camera or Custom)
/// </summary>
public TargetBuffer targetColorBuffer;
/// <summary>
/// Target depth buffer (camera or custom)
/// </summary>
public TargetBuffer targetDepthBuffer;
// The actual depth buffer has to follow some constraints, and thus may not be the same result as the target
// depth buffer that the user has requested. Apply these constraints and return a result.
internal TargetBuffer getConstrainedDepthBuffer()
{
TargetBuffer depth = targetDepthBuffer;
if (depth == TargetBuffer.Camera &&
HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.enabled &&
currentHDCamera.allowDynamicResolution &&
injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
{
// This custom pass is injected after postprocessing, and Dynamic Resolution Scaling is enabled, which
// means an upscaler is active. In this case, the camera color buffer is the full display resolution,
// but the camera depth buffer is a lower, pre-upscale resolution. So we cannot do depth testing here.
depth = TargetBuffer.None;
}
return depth;
}
/// <summary>
/// What clear to apply when the color and depth buffer are bound
/// </summary>
public ClearFlag clearFlags;
[SerializeField]
bool passFoldout;
[System.NonSerialized]
bool isSetup = false;
bool isExecuting = false;
RenderTargets currentRenderTarget;
CustomPassVolume owner;
HDCamera currentHDCamera;
// TODO RENDERGRAPH: Remove this when we move things to render graph completely.
MaterialPropertyBlock m_MSAAResolveMPB = null;
void Awake()
{
if (m_MSAAResolveMPB == null)
m_MSAAResolveMPB = new MaterialPropertyBlock();
}
/// <summary>
/// Mirror of the value in the CustomPassVolume where this custom pass is listed
/// </summary>
/// <value>The blend value that should be applied to the custom pass effect</value>
protected float fadeValue => owner.fadeValue;
/// <summary>
/// Get the injection point in HDRP where this pass will be executed
/// </summary>
/// <value></value>
protected CustomPassInjectionPoint injectionPoint => owner.injectionPoint;
/// <summary>
/// True if you want your custom pass to be executed in the scene view. False for game cameras only.
/// </summary>
protected virtual bool executeInSceneView => true;
/// <summary>
/// Used to select the target buffer when executing the custom pass
/// </summary>
public enum TargetBuffer
{
/// <summary>The buffers for the currently rendering Camera.</summary>
Camera,
/// <summary>The custom rendering buffers that HDRP allocates.</summary>
Custom,
/// <summary>No target buffer.</summary>
None,
}
/// <summary>
/// Render Queue filters for the DrawRenderers custom pass
/// </summary>
public enum RenderQueueType
{
/// <summary>Opaque GameObjects without alpha test only.</summary>
OpaqueNoAlphaTest = 0,
/// <summary>Opaque GameObjects with alpha test only.</summary>
OpaqueAlphaTest = 1,
/// <summary>All opaque GameObjects.</summary>
AllOpaque = 2,
/// <summary>Opaque GameObjects that use the after post process render pass.</summary>
AfterPostProcessOpaque = 3,
/// <summary>Transparent GameObjects that use the the pre refraction render pass.</summary>
PreRefraction = 4,
/// <summary>Transparent GameObjects that use the default render pass.</summary>
Transparent = 5,
/// <summary>Transparent GameObjects that use the low resolution render pass.</summary>
LowTransparent = 6,
/// <summary>All Transparent GameObjects.</summary>
AllTransparent = 7,
/// <summary>Transparent GameObjects that use the Pre-refraction, Default, or Low resolution render pass.</summary>
AllTransparentWithLowRes = 8,
/// <summary>Transparent GameObjects that use after post process render pass.</summary>
AfterPostProcessTransparent = 9,
/// <summary>All GameObjects that use the overlay render pass.</summary>
Overlay = 11,
/// <summary>All GameObjects</summary>
All = 10,
}
internal struct RenderTargets
{
public Lazy<RTHandle> customColorBuffer;
public Lazy<RTHandle> customDepthBuffer;
public TextureHandle colorBufferRG;
public TextureHandle nonMSAAColorBufferRG;
public TextureHandle depthBufferRG;
public TextureHandle normalBufferRG;
public TextureHandle motionVectorBufferRG;
}
enum Version
{
Initial,
}
[SerializeField]
Version m_Version = MigrationDescription.LastVersion<Version>();
Version IVersionable<Version>.version
{
get => m_Version;
set => m_Version = value;
}
internal bool WillBeExecuted(HDCamera hdCamera)
{
if (!enabled)
return false;
if (hdCamera.camera.cameraType == CameraType.SceneView && !executeInSceneView)
return false;
return true;
}
class ExecutePassData
{
public CustomPass customPass;
public CullingResults cullingResult;
public CullingResults cameraCullingResult;
public HDCamera hdCamera;
}
RenderTargets ReadRenderTargets(in RenderGraphBuilder builder, in RenderTargets targets)
{
RenderTargets output = new RenderTargets();
// Copy over builtin textures.
output.customColorBuffer = targets.customColorBuffer;
output.customDepthBuffer = targets.customDepthBuffer;
// TODO RENDERGRAPH
// For now we assume that all "outside" textures are both read and written.
// We can change that once we properly integrate render graph into custom passes.
// Problem with that is that it will extend the lifetime of any of those textures to the last custom pass that is executed...
// Also, we test validity of all handles because depending on where the custom pass is executed, they may not always be.
if (targets.colorBufferRG.IsValid())
output.colorBufferRG = builder.ReadWriteTexture(targets.colorBufferRG);
if (targets.nonMSAAColorBufferRG.IsValid())
output.nonMSAAColorBufferRG = builder.ReadWriteTexture(targets.nonMSAAColorBufferRG);
if (targets.depthBufferRG.IsValid())
output.depthBufferRG = builder.ReadWriteTexture(targets.depthBufferRG);
if (targets.normalBufferRG.IsValid())
output.normalBufferRG = builder.ReadWriteTexture(targets.normalBufferRG);
if (targets.motionVectorBufferRG.IsValid())
output.motionVectorBufferRG = builder.ReadWriteTexture(targets.motionVectorBufferRG);
return output;
}
internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera, CullingResults cullingResult, CullingResults cameraCullingResult, in RenderTargets targets, CustomPassVolume owner)
{
this.owner = owner;
this.currentRenderTarget = targets;
this.currentHDCamera = hdCamera;
using (var builder = renderGraph.AddRenderPass<ExecutePassData>(name, out ExecutePassData passData, profilingSampler))
{
passData.customPass = this;
passData.cullingResult = cullingResult;
passData.cameraCullingResult = cameraCullingResult;
passData.hdCamera = hdCamera;
this.currentRenderTarget = ReadRenderTargets(builder, targets);
builder.SetRenderFunc(
(ExecutePassData data, RenderGraphContext ctx) =>
{
var customPass = data.customPass;
ctx.cmd.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)customPass.injectionPoint);
if (customPass.currentRenderTarget.colorBufferRG.IsValid() && customPass.injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
ctx.cmd.SetGlobalTexture(HDShaderIDs._AfterPostProcessColorBuffer, customPass.currentRenderTarget.colorBufferRG);
if (customPass.currentRenderTarget.motionVectorBufferRG.IsValid() && (customPass.injectionPoint != CustomPassInjectionPoint.BeforeRendering))
ctx.cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, customPass.currentRenderTarget.motionVectorBufferRG);
if (customPass.currentRenderTarget.normalBufferRG.IsValid() && customPass.injectionPoint != CustomPassInjectionPoint.AfterPostProcess)
ctx.cmd.SetGlobalTexture(HDShaderIDs._NormalBufferTexture, customPass.currentRenderTarget.normalBufferRG);
if (customPass.currentRenderTarget.customColorBuffer.IsValueCreated)
ctx.cmd.SetGlobalTexture(HDShaderIDs._CustomColorTexture, customPass.currentRenderTarget.customColorBuffer.Value);
if (customPass.currentRenderTarget.customDepthBuffer.IsValueCreated)
ctx.cmd.SetGlobalTexture(HDShaderIDs._CustomDepthTexture, customPass.currentRenderTarget.customDepthBuffer.Value);
if (!customPass.isSetup)
{
customPass.Setup(ctx.renderContext, ctx.cmd);
customPass.isSetup = true;
}
customPass.SetCustomPassTarget(ctx.cmd);
var outputColorBuffer = customPass.currentRenderTarget.colorBufferRG;
// Create the custom pass context:
CustomPassContext customPassCtx = new CustomPassContext(
ctx.renderContext, ctx.cmd, data.hdCamera,
data.cullingResult, data.cameraCullingResult,
outputColorBuffer,
customPass.currentRenderTarget.depthBufferRG,
customPass.currentRenderTarget.normalBufferRG,
customPass.currentRenderTarget.motionVectorBufferRG,
customPass.currentRenderTarget.customColorBuffer,
customPass.currentRenderTarget.customDepthBuffer,
ctx.renderGraphPool.GetTempMaterialPropertyBlock(),
customPass.injectionPoint
);
customPass.isExecuting = true;
customPass.Execute(customPassCtx);
customPass.isExecuting = false;
// Set back the camera color buffer if we were using a custom buffer as target
if (customPass.getConstrainedDepthBuffer() != TargetBuffer.Camera)
CoreUtils.SetRenderTarget(ctx.cmd, outputColorBuffer);
});
}
}
internal void InternalAggregateCullingParameters(ref ScriptableCullingParameters cullingParameters, HDCamera hdCamera) => AggregateCullingParameters(ref cullingParameters, hdCamera);
/// <summary>
/// Cleans up the custom pass when Unity destroys it unexpectedly. Currently, this happens every time you edit
/// the UI because of a bug with the SerializeReference attribute.
/// </summary>
~CustomPass() { CleanupPassInternal(); }
internal void CleanupPassInternal()
{
if (isSetup)
{
Cleanup();
isSetup = false;
}
}
bool IsMSAAEnabled(HDCamera hdCamera)
{
// if MSAA is enabled and the current injection point is before transparent.
bool msaa = hdCamera.msaaEnabled;
msaa &= injectionPoint == CustomPassInjectionPoint.BeforePreRefraction
|| injectionPoint == CustomPassInjectionPoint.BeforeTransparent
|| injectionPoint == CustomPassInjectionPoint.AfterOpaqueDepthAndNormal;
return msaa;
}
// This function must be only called from the ExecuteInternal method (requires current render target and current RT manager)
void SetCustomPassTarget(CommandBuffer cmd)
{
TargetBuffer depth = getConstrainedDepthBuffer();
// In case all the buffer are set to none, we can't bind anything
if (targetColorBuffer == TargetBuffer.None && depth == TargetBuffer.None)
return;
RTHandle colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? currentRenderTarget.customColorBuffer.Value : currentRenderTarget.colorBufferRG;
RTHandle depthBuffer = (depth == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG;
if (targetColorBuffer == TargetBuffer.None && depth != TargetBuffer.None)
CoreUtils.SetRenderTarget(cmd, depthBuffer, clearFlags);
else if (targetColorBuffer != TargetBuffer.None && depth == TargetBuffer.None)
CoreUtils.SetRenderTarget(cmd, colorBuffer, clearFlags);
else
{
if (colorBuffer.isMSAAEnabled != depthBuffer.isMSAAEnabled)
Debug.LogError("Color and Depth buffer MSAA flags doesn't match, no rendering will occur.");
CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, clearFlags);
}
}
/// <summary>
/// Use this method if you want to draw objects that are not visible in the camera.
/// For example if you disable a layer in the camera and add it in the culling parameters, then the culling result will contains your layer.
/// </summary>
/// <param name="cullingParameters">Aggregate the parameters in this property (use |= for masks fields, etc.)</param>
/// <param name="hdCamera">The camera where the culling is being done</param>
protected virtual void AggregateCullingParameters(ref ScriptableCullingParameters cullingParameters, HDCamera hdCamera) { }
/// <summary>
/// Called when your pass needs to be executed by a camera
/// </summary>
/// <param name="renderContext"></param>
/// <param name="cmd"></param>
/// <param name="hdCamera"></param>
/// <param name="cullingResult"></param>
[Obsolete("This Execute signature is obsolete and will be removed in the future. Please use Execute(CustomPassContext) instead")]
protected virtual void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult) { }
/// <summary>
/// Called when your pass needs to be executed by a camera
/// </summary>
/// <param name="ctx">The context of the custom pass. Contains command buffer, render context, buffer, etc.</param>
// TODO: move this function to abstract when we remove the method above
protected virtual void Execute(CustomPassContext ctx)
{
#pragma warning disable CS0618 // Member is obsolete
Execute(ctx.renderContext, ctx.cmd, ctx.hdCamera, ctx.cullingResults);
#pragma warning restore CS0618
}
/// <summary>
/// Called before the first execution of the pass occurs.
/// Allow you to allocate custom buffers.
/// </summary>
/// <param name="renderContext">The render context</param>
/// <param name="cmd">Current command buffer of the frame</param>
protected virtual void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { }
/// <summary>
/// Called when HDRP is destroyed.
/// Allow you to free custom buffers.
/// </summary>
protected virtual void Cleanup() { }
/// <summary>
/// Bind the camera color buffer as the current render target
/// </summary>
/// <param name="cmd"></param>
/// <param name="bindDepth">if true we bind the camera depth buffer in addition to the color</param>
/// <param name="clearFlags"></param>
[Obsolete("Use directly CoreUtils.SetRenderTarget with the render target of your choice.")]
protected void SetCameraRenderTarget(CommandBuffer cmd, bool bindDepth = true, ClearFlag clearFlags = ClearFlag.None)
{
if (!isExecuting)
throw new Exception("SetCameraRenderTarget can only be called inside the CustomPass.Execute function");
RTHandle colorBuffer = currentRenderTarget.colorBufferRG;
RTHandle depthBuffer = currentRenderTarget.depthBufferRG;
if (bindDepth)
CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, clearFlags);
else
CoreUtils.SetRenderTarget(cmd, colorBuffer, clearFlags);
}
/// <summary>
/// Bind the custom color buffer as the current render target
/// </summary>
/// <param name="cmd"></param>
/// <param name="bindDepth">if true we bind the custom depth buffer in addition to the color</param>
/// <param name="clearFlags"></param>
[Obsolete("Use directly CoreUtils.SetRenderTarget with the render target of your choice.")]
protected void SetCustomRenderTarget(CommandBuffer cmd, bool bindDepth = true, ClearFlag clearFlags = ClearFlag.None)
{
if (!isExecuting)
throw new Exception("SetCameraRenderTarget can only be called inside the CustomPass.Execute function");
if (bindDepth)
CoreUtils.SetRenderTarget(cmd, currentRenderTarget.customColorBuffer.Value, currentRenderTarget.customDepthBuffer.Value, clearFlags);
else
CoreUtils.SetRenderTarget(cmd, currentRenderTarget.customColorBuffer.Value, clearFlags);
}
/// <summary>
/// Bind the render targets according to the parameters of the UI (targetColorBuffer, targetDepthBuffer and clearFlags)
/// </summary>
/// <param name="cmd"></param>
protected void SetRenderTargetAuto(CommandBuffer cmd) => SetCustomPassTarget(cmd);
/// <summary>
/// Resolve the camera color buffer only if the MSAA is enabled and the pass is executed in before transparent.
/// </summary>
/// <param name="cmd"></param>
/// <param name="hdCamera"></param>
protected void ResolveMSAAColorBuffer(CommandBuffer cmd, HDCamera hdCamera)
{
if (!isExecuting)
throw new Exception("ResolveMSAAColorBuffer can only be called inside the CustomPass.Execute function");
// TODO RENDERGRAPH
// See how to implement this correctly...
// When running with render graph, the design was to have both msaa/non-msaa textures at the same time, which makes a lot of the code simpler.
// This pattern here breaks this.
// Also this should be reimplemented as a render graph pass completely instead of being nested like this (and reuse existing code).
if (IsMSAAEnabled(hdCamera))
{
CoreUtils.SetRenderTarget(cmd, currentRenderTarget.nonMSAAColorBufferRG);
m_MSAAResolveMPB.SetTexture(HDShaderIDs._ColorTextureMS, currentRenderTarget.colorBufferRG);
cmd.DrawProcedural(Matrix4x4.identity, HDRenderPipeline.currentPipeline.GetMSAAColorResolveMaterial(), HDRenderPipeline.SampleCountToPassIndex(hdCamera.msaaSamples), MeshTopology.Triangles, 3, 1, m_MSAAResolveMPB);
}
}
/// <summary>
/// Resolve the camera color buffer only if the MSAA is enabled and the pass is executed in before transparent.
/// </summary>
/// <param name="ctx">Custom Pass Context from the Execute() method</param>
protected void ResolveMSAAColorBuffer(CustomPassContext ctx) => ResolveMSAAColorBuffer(ctx.cmd, ctx.hdCamera);
/// <summary>
/// Get the current camera buffers (can be MSAA)
/// </summary>
/// <param name="colorBuffer">outputs the camera color buffer</param>
/// <param name="depthBuffer">outputs the camera depth buffer</param>
[Obsolete("GetCameraBuffers is obsolete and will be removed in the future. All camera buffers are now avaliable directly in the CustomPassContext in parameter of the Execute function")]
protected void GetCameraBuffers(out RTHandle colorBuffer, out RTHandle depthBuffer)
{
if (!isExecuting)
throw new Exception("GetCameraBuffers can only be called inside the CustomPass.Execute function");
colorBuffer = currentRenderTarget.colorBufferRG;
depthBuffer = currentRenderTarget.depthBufferRG;
}
/// <summary>
/// Get the current custom buffers
/// </summary>
/// <param name="colorBuffer">outputs the custom color buffer</param>
/// <param name="depthBuffer">outputs the custom depth buffer</param>
[Obsolete("GetCustomBuffers is obsolete and will be removed in the future. All custom buffers are now avaliable directly in the CustomPassContext in parameter of the Execute function")]
protected void GetCustomBuffers(out RTHandle colorBuffer, out RTHandle depthBuffer)
{
if (!isExecuting)
throw new Exception("GetCustomBuffers can only be called inside the CustomPass.Execute function");
colorBuffer = currentRenderTarget.customColorBuffer.Value;
depthBuffer = currentRenderTarget.customDepthBuffer.Value;
}
/// <summary>
/// Get the current normal buffer (can be MSAA)
/// </summary>
/// <returns></returns>
[Obsolete("GetNormalBuffer is obsolete and will be removed in the future. Normal buffer is now avaliable directly in the CustomPassContext in parameter of the Execute function")]
protected RTHandle GetNormalBuffer()
{
if (!isExecuting)
throw new Exception("GetNormalBuffer can only be called inside the CustomPass.Execute function");
return currentRenderTarget.normalBufferRG;
}
/// <summary>
/// List all the materials that need to be displayed at the bottom of the component.
/// All the materials gathered by this method will be used to create a Material Editor and then can be edited directly on the custom pass.
/// </summary>
/// <returns>An enumerable of materials to show in the inspector. These materials can be null, the list is cleaned afterwards</returns>
public virtual IEnumerable<Material> RegisterMaterialForInspector() { yield break; }
/// <summary>
/// Returns the render queue range associated with the custom render queue type
/// </summary>
/// <param name="type">The custom pass render queue type.</param>
/// <returns>Returns a render queue range compatible with a ScriptableRenderContext.DrawRenderers.</returns>
protected RenderQueueRange GetRenderQueueRange(CustomPass.RenderQueueType type)
=> CustomPassUtils.GetRenderQueueRangeFromRenderQueueType(type);
/// <summary>
/// Create a custom pass to execute a fullscreen pass
/// </summary>
/// <param name="fullScreenMaterial">The material to use for your fullscreen pass. It must have a shader based on the Custom Pass Fullscreen shader or equivalent</param>
/// <param name="targetColorBuffer"></param>
/// <param name="targetDepthBuffer"></param>
/// <returns></returns>
public static FullScreenCustomPass CreateFullScreenPass(Material fullScreenMaterial, TargetBuffer targetColorBuffer = TargetBuffer.Camera,
TargetBuffer targetDepthBuffer = TargetBuffer.Camera)
{
return new FullScreenCustomPass()
{
name = "FullScreen Pass",
targetColorBuffer = targetColorBuffer,
targetDepthBuffer = targetDepthBuffer,
fullscreenPassMaterial = fullScreenMaterial,
};
}
/// <summary>
/// Create a Custom Pass to render objects
/// </summary>
/// <param name="queue">The render queue filter to select which object will be rendered</param>
/// <param name="mask">The layer mask to select which layer(s) will be rendered</param>
/// <param name="overrideMaterial">The replacement material to use when renering objects</param>
/// <param name="overrideMaterialPassName">The pass name to use in the override material</param>
/// <param name="sorting">Sorting options when rendering objects</param>
/// <param name="clearFlags">Clear options when the target buffers are bound. Before executing the pass</param>
/// <param name="targetColorBuffer">Target Color buffer</param>
/// <param name="targetDepthBuffer">Target Depth buffer. Note: It's also the buffer which will do the Depth Test</param>
/// <returns></returns>
public static DrawRenderersCustomPass CreateDrawRenderersPass(RenderQueueType queue, LayerMask mask,
Material overrideMaterial, string overrideMaterialPassName = "Forward", SortingCriteria sorting = SortingCriteria.CommonOpaque,
ClearFlag clearFlags = ClearFlag.None, TargetBuffer targetColorBuffer = TargetBuffer.Camera,
TargetBuffer targetDepthBuffer = TargetBuffer.Camera)
{
return new DrawRenderersCustomPass()
{
name = "DrawRenderers Pass",
renderQueueType = queue,
layerMask = mask,
overrideMaterial = overrideMaterial,
overrideMaterialPassName = overrideMaterialPassName,
sortingCriteria = sorting,
clearFlags = clearFlags,
targetColorBuffer = targetColorBuffer,
targetDepthBuffer = targetDepthBuffer,
};
}
}
}