How to capture image from camera with post effects? Mysteriously only getting emission(?) pass...

I am still in Unity 2018.4.6f1.

I have a separate camera from my main camera, whose purpose is to take screenshots, or render a "live feed" of the action, at different angles. Hierarchy as such:

  • The game object labeled as "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 have removed this and it has no bearing on the issue at hand.

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 in the inspector.

One way or another, it appears that I can only get access to the "bloom," and nothing else:

(On black so it's easier to see.)

If I assign the render texture onto a Raw Image canvas element, it only shows the "emission."

If I try to convert the render texture to a regular texture, it also only shows the "emission."

RenderTexture.active = renderTexture;
destination.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
destination.Apply();

(I have also tried AsyncGPUReadback. Its resulting texture looks like a flat gray without variance in the inspector.)

I have found if I disable post-processing, everything works as intended, no changes required. Of course, I am missing the post processing, which I want!

Somehow, somewhere, it seems Unity is getting data external of the texture itself, depending on context:

  • Using Unity's ReadPixels method only picks up the "bloom."
  • Using Unity's EncodeToPNG method only picks up the "bloom."
  • Putting the RenderTexture on a Raw Image only picks up the "bloom."
  • If I use a separate PNG encoder using the same Color32 data, I get the final correct image.
  • The inspector successfully renders the final correct image.

I have actually run into this issue multiple times, and have found numerous posts about it, but never found a proper solution, and definitely never a real-time solution, which I now desperately need.

To answer my own question: On the PostProcessLayer component, there is a "Keep Alpha" checkbox that needs to be checked to avoid the transparency issues.

When reading the description of that check box, I got the impression that when enabled, it would essentially "enable alpha," which is why I kept it unchecked until now. It appears to have the opposite effect, checking the "Keep Alpha" checkbox seems to make the result opaque, which is exactly what I wanted! Hooray!

1 Like