-
-
Save forestrf/d277729bbb2c34699a87cb58db549464 to your computer and use it in GitHub Desktop.
Dump RenderTexture to PNG in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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