I’m trying to do a basic blit using a material in Scriptable Render Feature,
Could someone please help me understand why it’s not working?
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class PleaseBlit : ScriptableRendererFeature
{
class CustomRenderPass : ScriptableRenderPass
{
private Material material;
private RTHandle tempTexture;
public CustomRenderPass(Material material) : base()
{
this.material = material;
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
// RTHandle allocation
// v1
var descriptor = renderingData.cameraData.cameraTargetDescriptor;
tempTexture = RTHandles.Alloc(descriptor, FilterMode.Bilinear, TextureWrapMode.Clamp, name: "_TexName");
//RenderingUtils.ReAllocateIfNeeded(ref tempTexture, descriptor, FilterMode.Bilinear, TextureWrapMode.Clamp, name: "_TexName");
//RenderTextureDescriptor cameraTextureDesc = renderingData.cameraData.cameraTargetDescriptor;
//cameraTextureDesc.depthBufferBits = 0;
//cmd.GetTemporaryRT(tempTexture.id, cameraTextureDesc, FilterMode.Bilinear);
var source = renderingData.cameraData.renderer.cameraColorTargetHandle;
var cmd = CommandBufferPool.Get();
// BLit
// v1
Blit(cmd, source, tempTexture, material, 0);
Blit(cmd, tempTexture, source);
//Blit(cmd, source, source);
//Blitter.BlitTexture(cmd, source, Vector2.one, material, 0);
// v2
//Blitter.BlitCameraTexture(cmd, source, source);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
//if (tempTexture != null)
//{
// RTHandles.Release(tempTexture);
// //tempTexture?.Release();
// tempTexture = null;
//}
RTHandles.Release(tempTexture);
}
}
public Material material;
private CustomRenderPass pass;
public override void Create()
{
pass = new CustomRenderPass(material);
pass.renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (renderingData.cameraData.cameraType == CameraType.Game)
{
renderer.EnqueuePass(pass);
}
}
}