Skip to content

Instantly share code, notes, and snippets.

@AlexanderDzhoganov
Created March 14, 2015 14:08
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlexanderDzhoganov/d795b897005389071e2a to your computer and use it in GitHub Desktop.
Save AlexanderDzhoganov/d795b897005389071e2a to your computer and use it in GitHub Desktop.
Dump RenderTexture to PNG in Unity
public static class DebugUtil
{
public static void DumpRenderTexture(RenderTexture rt, string pngOutPath)
{
var oldRT = RenderTexture.active;
var tex = new Texture2D(rt.width, rt.height);
RenderTexture.active = rt;
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
tex.Apply();
File.WriteAllBytes(pngOutPath, tex.EncodeToPNG());
RenderTexture.active = oldRT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment