Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question issue with commandBuffer.blit() to screen

Discussion in 'General Graphics' started by AdBen_U, Dec 2, 2023.

?

issue with commandBuffer.blit() to screen

  1. Render Texture Configuration

    0 vote(s)
    0.0%
  2. CommandBuffer Execution Order

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. AdBen_U

    AdBen_U

    Joined:
    Jan 22, 2021
    Posts:
    1
    hello everyone, i want to write a simple scriptabale render pipeline ; and i want to do some post processing before render the final image , so what i did is write this code to render first into a rendertexture and then blit the texture to screen ; this is my code


    protected override void Render(ScriptableRenderContext _ctx, Camera[] _cams)
    {
    foreach (var c in _cams)
    {
    FunTest(_ctx, c);
    }

    _ctx.Submit();
    }

    void FunTest(ScriptableRenderContext _ctx, Camera _c)
    {
    var cmd = new CommandBuffer();

    rt = new RenderTexture(_c.pixelWidth, _c.pixelHeight, 0, RenderTextureFormat.Default);
    rt.Create();

    cmd.SetRenderTarget(rt);
    cmd.ClearRenderTarget(true, true, Color.red);

    DrawRenderers(_ctx, _c);
    _ctx.ExecuteCommandBuffer(cmd);
    cmd.Release();


    cmd = new CommandBuffer();
    cmd.Blit(rt, BuiltinRenderTextureType.CameraTarget);


    _ctx.ExecuteCommandBuffer(cmd);
    cmd.Release();
    rt.Release();
    }




    void DrawRenderers(ScriptableRenderContext _ctx, Camera _c)
    {
    _c.TryGetCullingParameters(out var _cluPar);
    var culRes = _ctx.Cull(ref _cluPar);
    _ctx.SetupCameraProperties(_c);


    var sh = new ShaderTagId("MyTag");
    var renderSet = new DrawingSettings(sh, new SortingSettings(c));
    var filter = new FilteringSettings(RenderQueueRange.opaque) { layerMask = c.cullingMask };
    _ctx.DrawRenderers(culRes, ref renderSet, ref filter);

    }


    when i render directly to screen code work perfect , the problem happen when i want use an render texture

    it seems to me that the texture have the red color only and not my renderers

    what is the problem ?
     
  2. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79
    You may need 32bit depth option for the RenderTexture if those DrawRenderer needs depth test.