Skip to content

Instantly share code, notes, and snippets.

@forestrf
Forked from AlexanderDzhoganov/DebugUtil.cs
Created March 26, 2021 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forestrf/d277729bbb2c34699a87cb58db549464 to your computer and use it in GitHub Desktop.
Save forestrf/d277729bbb2c34699a87cb58db549464 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