Created
August 11, 2020 00:33
-
-
Save wonkee-kim/6ac812aaf8925b739fe1f5b7c9307e76 to your computer and use it in GitHub Desktop.
Simplified version of ScriptableRenderPass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.Rendering; | |
using UnityEngine.Rendering.Universal; | |
namespace UnityEngine.Experimental.Rendering.Universal { | |
public class MyRenderPass :ScriptableRenderPass { | |
string m_profilerTag; | |
Material m_blitMaterial; | |
private RenderTargetIdentifier source { get; set; } | |
private RenderTargetHandle destination { get; set; } | |
public MyRenderPass(string profilerTag, RenderPassEvent renderPassEvent, Material blitMaterial) { | |
m_profilerTag = profilerTag; | |
this.renderPassEvent = renderPassEvent; | |
m_blitMaterial = blitMaterial; | |
} | |
public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination) { | |
this.source = source; | |
this.destination = destination; | |
} | |
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) { | |
if(destination == RenderTargetHandle.CameraTarget) | |
cmd.GetTemporaryRT(destination.id, cameraTextureDescriptor); | |
} | |
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { | |
CommandBuffer cmd = CommandBufferPool.Get(m_profilerTag); | |
cmd.Clear(); | |
if(destination == RenderTargetHandle.CameraTarget) { | |
Blit(cmd, source, destination.Identifier(), m_blitMaterial, 0); | |
Blit(cmd, destination.Identifier(), source); | |
} else { | |
Blit(cmd, source, destination.Identifier(), m_blitMaterial, 0); | |
} | |
context.ExecuteCommandBuffer(cmd); | |
CommandBufferPool.Release(cmd); | |
} | |
public override void FrameCleanup(CommandBuffer cmd) { | |
if(destination == RenderTargetHandle.CameraTarget) | |
cmd.ReleaseTemporaryRT(destination.id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment