Search Unity

Problem setting RenderTarget on a Camera using SetTargetBuffers vs targetTexture

Discussion in 'Image Effects' started by jules_fpvr, Aug 23, 2017.

  1. jules_fpvr

    jules_fpvr

    Joined:
    Jan 8, 2016
    Posts:
    35
    If cam is the Camera component of a camera GameObject and rt is a RenderTexture created with:

    Code (CSharp):
    1. RenderTexture rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32);
    Then, are these three lines all exactly equivalent?

    Code (CSharp):
    1. cam.targetTexture = rt;
    2. cam.SetTargetBuffers(rt.colorBuffer, rt.depthBuffer);
    3. cam.SetTargetBuffers(new RenderBuffer[] { rt.colorBuffer }, rt.depthBuffer);
    If not, what is the difference?

    My code works fine, but when I try to to change the first of these to use SetTargetBuffers my code stops working.

    I'm just refactoring code that will shortly be needing MRT (multiple render targets) and I thought I'd test that it still works with one color buffer.

    Any suggestions as to why this would be?

    Thanks

    Jules
     
  2. laralex

    laralex

    Joined:
    Feb 16, 2018
    Posts:
    3
    I face the same issue in Unity 2022.3.19f1,
    cam.targetTexture = rt

    works, while
    cam.SetTargetBuffers(rt.colorBuffer, rt.depthBuffer);
    results in a black screen. I also use temporary RenderTextures. Calling `Create()` on the texture before setting the target buffers doesn't work either