#Custom Render Pipeline Importing backbuffer?

1 messages · Page 1 of 1 (latest)

frigid tapir
#

Hello, i am trying to learn a bit more about rendering by creating a basic custom render pipeline.
I am using Unity 6.3. I created a basic rendergraph pass for clearing the render target but i always get erros about the size. i think the backbuffer is always 1x1 instead of the camera size.

    internal void RenderCamera(RenderGraph renderGraph, ScriptableRenderContext context, Camera camera)
    {
        context.SetupCameraProperties(camera);
        var cmd = CommandBufferPool.Get($"{camera} command buffer");
        var parameters = new RenderGraphParameters
        {
            commandBuffer = cmd,
            scriptableRenderContext = context,
            currentFrameIndex = Time.frameCount,
        };
        try
        {
            renderGraph.BeginRecording(parameters);

            // backbuffer
            RenderTargetIdentifier renderTarget = camera.targetTexture != null ? new RenderTargetIdentifier(camera.targetTexture) : new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);
            TextureHandle cameraTargetTexture = renderGraph.ImportBackbuffer(renderTarget);

            using (var builder = renderGraph.AddRasterRenderPass("pass", out PassData passData))
            {
                builder.SetRenderAttachment(cameraTargetTexture, 0, AccessFlags.WriteAll);
                builder.AllowPassCulling(false);

                builder.SetRenderFunc(static (PassData passData, RasterGraphContext context) =>
                {
                    context.cmd.ClearRenderTarget(true, true, Color.green);
                });
            }

            renderGraph.EndRecordingAndExecute();
        }
        catch (Exception e)
        {
            if (renderGraph.ResetGraphAndLogException(e))
                throw;
        }

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

Error:

pass: The dimensions or sample count of attachment 0 do not match RenderPass specifications (978 x 498 1AA) vs (1 x 1 1AA).
UnityEngine.Rendering.ScriptableRenderContext:Submit ()

I think my render target for some reason is 1x1 but idk how to ensure it has the size of the camera?

#

I am unsure what is wrong, i would like to draw something like the skybox in every camera, just something simple like that but these errors i am unsure how to correctly do it.

meager vault
# frigid tapir Hello, i am trying to learn a bit more about rendering by creating a basic custo...

You probably need to use this method overload instead of the one you're using, since it seems to be obsolete.

public TextureHandle ImportBackbuffer(RenderTargetIdentifier rt, RenderTargetInfo info, ImportResourceParams importParams = default)

You need to create and pass in the info struct. The docs mention that the render graph can't infer the rt properties on it's own:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.core%4017.6/api/UnityEngine.Rendering.RenderGraphModule.RenderGraph.html#sidetoggle

#

Also this note:

Import the final backbuffer to render graph. This function can only be used when nativeRenderPassesEnabled is false.
frigid tapir
# meager vault You probably need to use this method overload instead of the one you're using, s...

I have tried doing this but the one i am creating always gives me an error saying it is invalid.

Render Graph Execution error
Exception: Invalid imported texture. A RTHandle wrapping an RenderTargetIdentifier was imported without providing valid RenderTargetInfo.
RenderTargetIdentifier renderTarget = camera.targetTexture != null ? new RenderTargetIdentifier(camera.targetTexture) : new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);
RenderTargetInfo renderTargetInfo = new RenderTargetInfo();
renderTargetInfo.width = camera.pixelWidth;
renderTargetInfo.height = camera.pixelHeight;
TextureHandle cameraTargetTexture = renderGraph.ImportBackbuffer(renderTarget, renderTargetInfo);
meager vault
#

Well it basically tells you what the problem - render target info was not initialized properly. Perhaps you need to use a constructor, or there are other properties that must be initialized as well.

frigid tapir
#

it doesn't seem to really provide a constructor. i can only create new tag and then set the properties individually

#

RenderTargetInfo renderTargetInfo = new RenderTargetInfo();
renderTargetInfo.width = camera.pixelWidth;
renderTargetInfo.height = camera.pixelHeight;
renderTargetInfo.format = GraphicsFormat.R32G32B32A32_SFloat;

I tried adding a graphics format, i will try adding every property it has

#

Apparently the code below is a valid way to make it work. i got no errors now, only something else that's weird happens. In the scene view the clearing becomes pink and game view green, not sure what's going on there but i guess i am a step further

                // backbuffer
                RenderTargetIdentifier renderTarget;
                RenderTargetInfo renderTargetInfo = new RenderTargetInfo();

                if (camera.targetTexture != null)
                {
                    var rt = camera.targetTexture;

                    renderTarget = new RenderTargetIdentifier(rt);

                    renderTargetInfo.width = rt.width;
                    renderTargetInfo.height = rt.height;
                    renderTargetInfo.format = rt.graphicsFormat;
                    renderTargetInfo.volumeDepth = rt.volumeDepth;
                    renderTargetInfo.msaaSamples = 1;
                    renderTargetInfo.bindMS = rt.bindTextureMS;
                }
                else
                {
                    renderTarget = BuiltinRenderTextureType.CameraTarget;

                    renderTargetInfo.width = camera.pixelWidth;
                    renderTargetInfo.height = camera.pixelHeight;
                    renderTargetInfo.format = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm; // safe default
                    renderTargetInfo.volumeDepth = 1;
                    renderTargetInfo.msaaSamples = 1;
                    renderTargetInfo.bindMS = false;
                }

                TextureHandle cameraTargetTexture = renderGraph.ImportBackbuffer(renderTarget, renderTargetInfo);