I am rather a newbee to Unity and recently wanted to experiment with the URP RendererFeatures and Blitting. I am using Unity 2022.3.17 with the default URP setup.
So I looked at the Unity documentation examples
- Example of a complete Scriptable Renderer Feature | Universal RP | 14.0.11 (This is a Blur in two passes)
- Perform a full screen blit in URP | Universal RP | 15.0.7 (This just filters the green component of scene and uses _CameraOpaqueTexture)
But there are problems. If I don’t press “Play” both RendererFeatures work well (screen blurred or screen greenish; switchable via the checkbox in the URP-HighFidelity-Renderer).
But after I press “Play”, switching on the BlurRendererFeature makes the cube disappear instead of blurred.
The screen is filled with a gray - which I am not sure where it comes from - I changed cube color and background color, but it seems unrelated.
Here are the Execute-Methods of both examples (the first one (blur) doesn’t work when “play” is pressed, the second one (green filter) works reliably (with and without pressing play)).
public override void Execute(ScriptableRenderContext context,
ref RenderingData renderingData)
{
//Get a CommandBuffer from pool.
CommandBuffer cmd = CommandBufferPool.Get();
RTHandle cameraTargetHandle =
renderingData.cameraData.renderer.cameraColorTargetHandle;
UpdateBlurSettings();
// Blit from the camera target to the temporary render texture,
// using the first shader pass.
Blit(cmd, cameraTargetHandle, blurTextureHandle, material, 0);
// Blit from the temporary render texture to the camera target,
// using the second shader pass.
Blit(cmd, blurTextureHandle, cameraTargetHandle, material, 1);
//Execute the command buffer and release it back to the pool.
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cameraData = renderingData.cameraData;
if (cameraData.camera.cameraType != CameraType.Game)
return;
if (m_Material == null)
return;
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, m_ProfilingSampler))
{
m_Material.SetFloat("_Intensity", m_Intensity);
Blitter.BlitCameraTexture(cmd, m_CameraColorTarget, m_CameraColorTarget, m_Material, 0);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
}