Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SetRenderTarget with MRT, Depth Slices and Mips?

Discussion in 'General Graphics' started by Chimera3D, Mar 24, 2020.

  1. Chimera3D

    Chimera3D

    Joined:
    Jan 27, 2012
    Posts:
    73
    I am attempting to render to MRTs that are 2D texture arrays with 2 mipmaps with something like the following:
    Code (CSharp):
    1.    public void Example ()
    2.     {
    3.         int mipCount = 2;
    4.         RenderTexture[] tex = new RenderTexture[3];
    5.         RenderBuffer[] colorBuffers = new RenderBuffer[tex.Length];
    6.         for (int i = 0; i < tex.Length; i++)
    7.         {
    8.             tex[i] = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB32, mipCount);
    9.             tex[i].dimension = TextureDimension.Tex2DArray;
    10.             tex[i].volumeDepth = 4;
    11.             tex[i].useMipMap = true;
    12.             tex[i].autoGenerateMips = false;
    13.             tex[i].Create();
    14.             colorBuffers[i] = tex[i].colorBuffer;
    15.         }
    16.  
    17.         int targetMip = 1;
    18.         RenderTargetSetup setup = new RenderTargetSetup(colorBuffers, tex[0].depthBuffer, targetMip);
    19.         setup.depthSlice = 2;
    20.  
    21.         Graphics.SetRenderTarget(setup);
    22.     }
    As long as the targetMip is 0, rendering afterwards works fine, but setting it to 1 (with no other changes) does not render anything. Is this configuration with MRTs, depth slices and mip levels supported? I know that specifying the mipcount for a RenderTexture is a fairly recent feature so is that the issue?

    EDIT: Not sure what I changed but it works now.
     
    Last edited: Mar 24, 2020
  2. andeliseev

    andeliseev

    Joined:
    Mar 30, 2013
    Posts:
    7
    maybe you know what you changed? because i always have black (or simply no render) in mip > 0
     
  3. georgerh

    georgerh

    Joined:
    Feb 28, 2020
    Posts:
    72
    Isn't tex[0].depthBuffer null because you are creating the RenderTexture without a depth buffer (3rd parameter of the ctr)?

    Wouldn't be surprised if the depth buffer was random (whatever was bound before) which may or may not reject some pixels depending on the contents.

    Actually, this code wouldn't work anyways because for the second mip, you'd need a depth buffer that is 128 >> 1 (64 x 64 pixels) in size.
     
    Last edited: Dec 19, 2022