Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'General Graphics' started by ZoopTEK, Jun 17, 2020.

  1. ZoopTEK

    ZoopTEK

    Joined:
    Feb 14, 2012
    Posts:
    22
    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."

    Code (CSharp):
    1. RenderTexture.active = renderTexture;
    2. destination.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
    3. 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.
     
  2. ZoopTEK

    ZoopTEK

    Joined:
    Feb 14, 2012
    Posts:
    22
    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!
     
    BrandyStarbrite likes this.