Skip to content

Instantly share code, notes, and snippets.

@wonkee-kim
Created August 11, 2020 00:33
Show Gist options
  • Save wonkee-kim/6ac812aaf8925b739fe1f5b7c9307e76 to your computer and use it in GitHub Desktop.
Save wonkee-kim/6ac812aaf8925b739fe1f5b7c9307e76 to your computer and use it in GitHub Desktop.
Simplified version of ScriptableRenderPass
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