0
\$\begingroup\$

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:

enter image description here

  • The game object labeled as "main camera" captures the 3D scene just like a normal main camera would, including post-processing components. 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.

Render texture is correct

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

Bright colors opaque, dark colors transparent. (On black so it's easier to see.)

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

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

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, 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 never found a proper solution, and definitely never a real-time solution, which I now desperately need.

\$\endgroup\$
  • \$\begingroup\$ It looks to me like it's capturing your whole scene, but at the wrong exposure, so the bright parts are dimmer and the dark parts fade away entirely. You might be bypassing the HDR resolve pass. \$\endgroup\$ – DMGregory Jun 17 at 10:43
  • \$\begingroup\$ I'm not sure how I did that, or how to fix it. I simply used the same strategy used by everyone since Unity was a thing, grabbing the render texture from a camera. How do I avoid "bypassing" the HDR resolve pass? \$\endgroup\$ – Zoop Jun 17 at 13:54
0
\$\begingroup\$

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!

It does make me wonder if that "Keep Alpha" checkbox is reversed. If so, that does have a performance and visual impact, at least according to the description. Should I keep it enabled by default?

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.