-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrabpassRendererFeature.cs
58 lines (49 loc) · 1.91 KB
/
GrabpassRendererFeature.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
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GrabpassRendererFeature : ScriptableRendererFeature
{
class GrabpassRenderPass : ScriptableRenderPass
{
const string textureName = "_Grabpass";
Material material;
RTHandle tempTexture;
RTHandle sourceTexture;
public GrabpassRenderPass(Material material, RenderPassEvent renderPassEvent) : base()
{
this.material = material;
this.renderPassEvent = renderPassEvent;
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
sourceTexture = renderingData.cameraData.renderer.cameraColorTargetHandle;
tempTexture = RTHandles.Alloc(new RenderTargetIdentifier(textureName), textureName);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer commandBuffer = CommandBufferPool.Get("FullScreenRenderFeature");
RenderTextureDescriptor targetDescriptor = renderingData.cameraData.cameraTargetDescriptor;
targetDescriptor.depthBufferBits = 0;
commandBuffer.GetTemporaryRT(Shader.PropertyToID(tempTexture.name), targetDescriptor, FilterMode.Point);
Blit(commandBuffer, sourceTexture, tempTexture, material);
Blit(commandBuffer, tempTexture, sourceTexture);
context.ExecuteCommandBuffer(commandBuffer);
CommandBufferPool.Release(commandBuffer);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
tempTexture.Release();
}
}
[SerializeField] Material material;
[SerializeField] RenderPassEvent renderPassEvent;
GrabpassRenderPass grabpassRenderPass;
public override void Create()
{
grabpassRenderPass = new GrabpassRenderPass(material, renderPassEvent);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(grabpassRenderPass);
}
}