I want to save a render texture into a grayscale 8 bit PNG image that only uses 1 color channel. I converted the render texture into a Texture2D and have experimented with TextureFormat.R8 and TextureFormat.Alpha8 but have had no success. The output images have every pixel painted black with Alpha8 and every pixel painted turquoise with R8. Is there any way to accomplish this without having to use custom shaders? Thank you!
Assume your RenderTexture is ARGB32 format, then
RenderTexture.active = YOUR_RT;
Texture2D tempTexture = new Texture2D(rtWidth, rtHeight, TextureFormat.ARGB32, false, true);
tempTexture.ReadPixels(new Rect(0, 0, rtWidth, rtHeight), 0, 0);
tempTexture.Apply();
RenderTexture.active = BACKUP_RT; // or just set it to null.
Then use another texture to save it:
Color[ ] colorSrc = tempTexture.GetPixels(0, 0, rtWidth, rtHeight);
outTexture = new Texture2D(rtWidth, rtHeight, format, false, true); // format can be Alpha8
outTexture.SetPixels(colorSrc);
outTexture.Apply(true, false);