Search Unity

Blitting onto single rendertexture in Tex2DArray

Discussion in 'General Graphics' started by CosmoM, May 31, 2021.

  1. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    I have a setup where I blit into a rendertexture using a material (
    Graphics.Blit(source,dest,matA)
    ). The rendertexture is associated with another material, matB, and everything works. I'd however like this to be instanced, so I can use the same material, matB, on multiple objects but only blit onto the texture of one of them at a time. Everything apart from the blit works, by making my rendertextures Tex2DArrays, setting an instanced slice index and using UNITY_SAMPLE_TEX2DARRAY and the like in matB to sample the right slice for each object.

    What I can't figure out is how to now do the blitting on only a single RenderTexture in the Tex2DArray, to only affect a single slice. Graphics.Blit has a
    destDepthSlice
    , which seems like what I need, except that I cannot use that as the same time as a source, dest and material it seems.

    So what is the right (GPU-side/efficient) approach? Use copytexture somehow? Set up a different pass in matB for each slice? Or something else entirely? Thanks for your help.
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    Never mind; turns out that unlike what the Graphics.Blit documentation claims, you can actually do
    Code (CSharp):
    1. Graphics.Blit(source,destArray,mat,-1,index);
    to blit from a normal rendertexture (
    source
    ) to a specific slice index of a Tex2DArray (
    destArray
    ) using a material, as long as you also set a source slice (here -1, since the source is not an array).