-
Notifications
You must be signed in to change notification settings - Fork 2
/
BlitPass.cs
47 lines (39 loc) · 1.5 KB
/
BlitPass.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
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEditor; // TODO
/// <summary>
/// CustomPass responsible for blitting the pre-rendered colour and depth textures
/// to the main colour render target and depth render target.
/// </summary>
public class BlitPass : CustomPass
{
private Shader shader;
private Material material;
private Texture2D depthTexture = null;
private Texture2D backgroundTexture = null;
protected override bool executeInSceneView => false;
public void BlitTextures(Texture2D depthTex, Texture2D bkgTex)
{
depthTexture = depthTex;
backgroundTexture = bkgTex;
}
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
shader = Shader.Find("Custom/BlitPreRendered");
material = CoreUtils.CreateEngineMaterial(shader);
Debug.Assert(material != null, "Failed to create custom pass material");
}
protected override void Execute(CustomPassContext ctx)
{
ctx.propertyBlock.SetTexture("_DepthTexture", depthTexture);
ctx.propertyBlock.SetTexture("_BackgroundTexture", backgroundTexture);
CoreUtils.SetRenderTarget(ctx.cmd, ctx.cameraColorBuffer, ctx.cameraDepthBuffer, ClearFlag.None);
CoreUtils.DrawFullScreen(ctx.cmd, material, ctx.propertyBlock, shaderPassId: 0);
}
protected override void Cleanup()
{
CoreUtils.Destroy(material);
}
}