- Home /
Save image from camera with post processing.
Since formatting in Unity Answers is awful, here is the StackOverflow post with pretty formatting: https://stackoverflow.com/questions/61167603/save-image-from-unity-camera-with-post-processing-effects
I have a separate camera from my main camera, whose purpose is to take screenshots at different angles. Hierarchy as such:
Screenshot Camera
Main Camera
GUI Camera
Canvas
Image
The main camera captures the 3D scene just like a normal main camera would, including post-processing components.
The GUI camera captures just the UI layer.
The canvas and image are simply a watermark, rendered by the GUI camera.
I point both the main camera and GUI camera to the same target render texture. The result of the render texture appears to be correct.
Then I convert to a normal Texture2D so it can be saved:
RenderTexture.active = renderTexture;
destination.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
destination.Apply();
However, during that conversion, the dark areas turn transparent, and light areas remain correct. It's very strange.
The above screenshot is placed on top of black to make it easier to see. (It's not exactly the same as the render texture picture because I took them at different times, but close enough to make the comparison.)
I have found if I disable post-processing, everything works as intended, no changes required.
I have tinkered with color linearity, removing the UI camera, and changing texture color formats. What is stranger yet, is I use almost the same solution elsewhere in the same project, and that one works.
Your answer
Follow this Question
Related Questions
Why Camera clear color alpha channel is ignored? 2 Answers
Rendertexture to texture2d in Unity5 0 Answers
Copy non-rectangle part of one texture to another 2 Answers
Texture2D GetPixel returns the same value everywhere 2 Answers
Best way to convert particles and sprites in a single sprite at runTime 1 Answer