Search Unity

Issue with RenderTexture, GetTemporary and MipMap

Discussion in 'General Graphics' started by MaT227, May 11, 2016.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Hi there,

    I am using Unity 5.3.4f1 and trying to generate a RenderTexture with mips. For performance reasons, I am using RenderTexture.GetTemporary to generate my RenderTexture.

    I would like to generate mips for this RenderTexture that's why I am scaling it to have a power-of-two size. Unfortunately, I can't use renderTexture.useMipMap or renderTexture.generateMips without having those errors :
    The funny thing is that the mips are available but the errors flood the console.
    I don't want to use a predefined RenderTexture as GetTemporary gives better performances.

    It seems that this has been already reported but not really fixed : https://issuetracker.unity3d.com/is...-on-rendertexture-dot-gettemporary-in-5-dot-2

    Is there a way to generate mips for temporary RenderTexture without generating an error ?
    Thank you !
     
  2. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Anybody ?
     
  3. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Still nobody...
     
  4. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    You have to enable mipmaps before you call RenderTexture.Create() like this:

    Code (CSharp):
    1. rt = new RenderTexture(resolution.x, resolution.y, 0, format, RenderTextureReadWrite.Linear);
    2. rt.name = name;
    3. rt.useMipMap = true;
    4. rt.Create();
    Nathaniel
     
    chrismarch likes this.
  5. whoaadrian

    whoaadrian

    Joined:
    Aug 20, 2018
    Posts:
    2
    Still nothing on this? @eagle555 correct, but the error comes when using RenderTexture.GetTemporary. The texture is already created in an internal pool and re-setting the mipmaps is not allowed.
     
  6. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Then don't use the internal pool but create one yourself ;)
     
  7. maxhb30

    maxhb30

    Joined:
    Aug 16, 2020
    Posts:
    1
    if you want to use mipmaps, you need to make sure that the texture is not created in video memory, and if created, release, assign the use of mipmaps and create. When I do this, it doesn't seem to have a huge impact on performance in my experience.

    I use code like this:

    Code (CSharp):
    1. var texture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32);
    2. if (useMipMaps)
    3. {
    4.     if (texture.IsCreated())
    5.     {
    6.         texture.Release();
    7.     }
    8.     texture.useMipMap = true;
    9.     texture.filterMode = FilterMode.Trilinear;
    10.     texture.anisoLevel = 9;
    11. }
    12. if (!texture.IsCreated())
    13. {
    14.     texture.Create();
    15. }
    16.  
     
    bgolus likes this.
  8. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Cool didn't know that was possible. I was looking for manipulating the builtin Gbuffer textures with a ComputeShader and this makes that possible :)