Search Unity

Manually generate RenderTexture mips at runtime

Discussion in 'Image Effects' started by C-Gabriel, Sep 25, 2018.

  1. C-Gabriel

    C-Gabriel

    Joined:
    Jan 27, 2016
    Posts:
    119
    Is it possible to write in the mips of an RT manually? The RenderTexture class has both support for useMipMap and autoGenerateMips. Since I can enable useMipMap without automatically generating them, I assume there must be a way to manually write into them. Texture2D already supports that.

    I want to create a blur texture, and store the multiple blur levels in the RT's mips. It might not save memory or performance, but it's more ergonomic :)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,338
    It can be done using the command buffer version of Blit which takes a RenderTextureIdentifier which includes the mip level to blit to, or you can use CopyTexture, or a compute shader. Note: you cannot do a blit with the same render texture as the source and destination, so you have to create intermediate render targets and either blit or preferably CopyTexture into each mip after generating the blurred version. Compute gets around this by way of using a RWTexture.
     
  3. C-Gabriel

    C-Gabriel

    Joined:
    Jan 27, 2016
    Posts:
    119
    Thanks @bgolus. In the end, I've decided to use only one blur iteration, so I don't need the mips anymore, but I'll keep this in mind for some other project :)
     
  4. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    726
    just noting, RWTexture both reading and writing to itself only works on newer GPUs. feature level 11_0 doesn't seem to support this, even in compute shaders (learned the hard way)
     
    CruelByte likes this.