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

Use rendertexture as texture

Discussion in 'General Graphics' started by augustinus, Feb 10, 2017.

  1. augustinus

    augustinus

    Joined:
    Feb 3, 2015
    Posts:
    25
    It's very slow to read pixels from Rendertexture and make it into texture2d.

    Code (CSharp):
    1. RenderTexture.active = myRenderTexture;
    2. myTexture2D.ReadPixels(new Rect(0, 0, myRenderTexture.width, myRenderTexture.height), 0, 0);
    3. myTexture2D.Apply();
    So, I tried to use rendertexture as my model's texture.

    Code (CSharp):
    1. modelMaterial.mainTexture = myRenderTexture;
    I test it in mobile device.
    It works. Not so slow.

    I know Rendertexture can be destroyed at some device events, etc.
    Link : https://docs.unity3d.com/ScriptReference/RenderTexture.html

    So, I tried to recreate the RenderTexture at some device event.

    Is there any other risk to use Rendertexture as model's texture ?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The risk is sometimes the material using the now-missing render texture shows the default white texture or garbled noise. As long as you recreate it and re-apply it's fine.