Search Unity

camera looks slightly gamma brightened after using renderTexture

Discussion in 'General Graphics' started by s_guy, Apr 30, 2019.

  1. s_guy

    s_guy

    Joined:
    Feb 27, 2013
    Posts:
    102
    Running the following code one time appears to permanently make everything slightly whiter (except overlays), as if a gamma correction of about 2.2 were in play. The intent is to capture a Texture2D via renderTexture and then dispose of all other resources and set things back to normal. Any ideas why?

    Code (CSharp):
    1.        
    2.     static Texture2D TakeScreenshot(int width, int height)
    3.     {
    4.         RenderTexture renderTexture = new RenderTexture(width, height, 24);
    5.         Camera.main.targetTexture = renderTexture;
    6.         Camera.main.Render();
    7.         RenderTexture.active = renderTexture;
    8.         Texture2D screenShot = new Texture2D(width, height, TextureFormat.RGB24, false);
    9.         screenShot.ReadPixels(new Rect(0, 0, width, height), 0, 0);
    10.         screenShot.Apply(false);
    11.         Destroy(renderTexture);
    12.         RenderTexture.active = null;
    13.         Camera.main.targetTexture = null;
    14.  
    15.         return screenShot;
    16.     }
    17.  
    (I know about UnityEngine.ScreenCapture, but I'm in Unity 5.6)