URP Blit Material Renderer Feature - Breaks the Inspector Asset Preview Window

Hi there!

I’ve been working on a game with my team and after adding some Custom Renderer Features to the URP rendering pipeline our asset preview windows are behaving strangely.

We recently upgraded our Unity/URP versions, however this glitch occured before the upgrade as well as after the upgrade. For reference before we were using Unity 2020.1.6f1 and URP 8.2.0. Now we are using Unity 2020.3.19f1, and URP 10.6.0.

Essentially, the preview window that should be showing the selected model/material/animation/etc from the project window is instead showing a glitchy duplicate of the scene view. I’ve attached an image of the error. The preview should be showing the selected model (TamikaTestUV1).

I’ve isolated the error to the Blit Material Feature. If I toggle the feature on and off the problem does go away. I’ve tested the feature with multiple different materials and it persists as long as it is active and has a material in the slot.

Would love to resolve this, so to not have to constantly turn the blit feature off to preview assets. Any help would be greatly appreciated!

Zed

Image upload didn’t work. Here it is.

Hi Zed,

Sorry to hear you are facing issues. If this happens in empty projects, this might indicate a possible bug in the URP pipeline. The regular steps are to submit a bug report with the steps to reproduce the issue. Our QA team will then try reproducing the bug and if it is found, a fix will be deployed. I understand this takes time but we appreciate if you can send us the report. Steps to follow are found in the following guide:

You should receive a bug case that will be followed up directly by our colleagues in the QA team.

Apologies if this is not the answer you were expecting. Our devs are constantly monitoring forum threads and might comment more on this. Reporting the bug will also work to get the devs to look at the issue and further advise on this.

1 Like

Thank you for the reply.

I forgot to add my Blit script to this, I now assume the problem may be with the script actually. I’ve attached it here in case anyone can help.

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class BlitMaterialFeature : ScriptableRendererFeature {
    class RenderPass : ScriptableRenderPass {

        private string profilingName;
        private Material material;
        private int materialPassIndex;
        private RenderTargetIdentifier sourceID;
        private RenderTargetHandle tempTextureHandle;

        public RenderPass(string name, Material material, int passIndex) : base() {
            this.profilingName = name;
            this.material = material;
            this.materialPassIndex = passIndex;
            tempTextureHandle.Init("_TempBlitMaterialTexture");
        }

        public void SetSource(RenderTargetIdentifier source) {
            this.sourceID = source;
        }

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) {
            CommandBuffer cmd = CommandBufferPool.Get(profilingName);

            RenderTextureDescriptor cameraTextureDesc = renderingData.cameraData.cameraTargetDescriptor;
            cameraTextureDesc.depthBufferBits = 0;

            cmd.GetTemporaryRT(tempTextureHandle.id, cameraTextureDesc, FilterMode.Bilinear);
            Blit(cmd, sourceID, tempTextureHandle.Identifier(), material, materialPassIndex);
            Blit(cmd, tempTextureHandle.Identifier(), sourceID);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }

        public override void FrameCleanup(CommandBuffer cmd) {
            cmd.ReleaseTemporaryRT(tempTextureHandle.id);
        }
    }

    [System.Serializable]
    public class Settings {
        public string name;
        public Material material;
        public int materialPassIndex = -1; // -1 means render all passes
        public RenderPassEvent renderEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    [SerializeField]
    private Settings settings = new Settings();

    private RenderPass renderPass;

    public Material Material {
        get => settings.material;
    }

    public override void Create() {
        this.renderPass = new RenderPass(settings.name, settings.material, settings.materialPassIndex);
        renderPass.renderPassEvent = settings.renderEvent;
    }

    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) {
        renderPass.SetSource(renderer.cameraColorTarget);
        renderer.EnqueuePass(renderPass);
    }
}

7594825–942082–BlitMaterialFeature.cs (2.52 KB)

1 Like

Hello,

We’re facing the very same issue, our code are similar in setup/execute/Clean…

Did you found a solution to the texture being shown in preview?

Thanks.