So I followed this:
tutorial on adding a custom post-processing effect which was made using a custom render pass feature that is applied to a forward renderer and applies a material to the whole screen. In my case, I created a simple shader in the URP shader graph which basically just changes the colour of each pixel based on its value.
That might not’ve made much sense but it works fine in the editor, visually its doing exactly what I hoped for but when I go to build it the game is just a black screen. I read a couple of other posts on custom render passes but they didn’t help. Ive also checked the player log and there’s no issue.
This is my first time doing anything like this and I’m really not sure whats wrong.
That was the code for my custom render pass feature…
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class CustomRenderPassFeature : ScriptableRendererFeature
{
class CustomRenderPass : ScriptableRenderPass
{
public RenderTargetIdentifier source;
Material mat;
RenderTargetHandle tempRenderTarget;
public CustomRenderPass(Material material)
{
mat = material;
tempRenderTarget.Init("_temp");
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer commandBuffer = CommandBufferPool.Get();
commandBuffer.GetTemporaryRT(tempRenderTarget.id, renderingData.cameraData.cameraTargetDescriptor);
Blit(commandBuffer, source, tempRenderTarget.Identifier(), mat);
Blit(commandBuffer, tempRenderTarget.Identifier(), source);
context.ExecuteCommandBuffer(commandBuffer);
CommandBufferPool.Release(commandBuffer);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
}
}
[System.Serializable]
public class Settings
{
public Material material = null;
}
public Settings settings = new Settings();
CustomRenderPass m_ScriptablePass;
/// <inheritdoc/>
public override void Create()
{
m_ScriptablePass = new CustomRenderPass(settings.material)
{
renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing
};
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
m_ScriptablePass.source = renderer.cameraColorTarget;
renderer.EnqueuePass(m_ScriptablePass);
}
}
It might also be worth noting that it works completely fine when the render feature is removed.
UI Also works fine in the build - although it is unaffected by the render feature.