Skip to content

[HDRP][Compositor] Fix issues with bloom, alpha and HDR layers in the compositor #2083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 8, 2020

Conversation

pmavridis
Copy link
Contributor

@pmavridis pmavridis commented Oct 2, 2020

Purpose of this PR

https://fogbugz.unity3d.com/f/cases/1272621/

This bug revealed a few issues in the compositor:

  • The alpha value was using to guide the application of bloom. However bloom should spread over the entire RT, even at regions with zero alpha. This is the case now.
  • The composition layers were created as UNORM resources, so HDR values were clamped. I have changed that to SFloat.

This PR also includes:

  • Some updates on the alpha output from @FrancescoC-unity (with a minor change to fix the alpha to 1 only when alpha testing is NOT performed, as discussed offline. The TAA fix was fine but we had to update the reference image)
  • An updated compositor test scene to test UI rendering and AOV stacking (+ updated reference image)

Testing status

After some minor modifications to the repro project in the bug ticket, applying bloom on the cubes now gives the same result:

image

The modifications to make this work are the following:

  • Dithering should be disabled in the background camera (because it clamps the values to [0,1] )
  • When using camera stacking, as with the repro project, bloom should only be applied on the last layer of the stack (here the foreground). For the background layer I have created a new volume with only an exposure override (set to the same exposure as foreground) but not bloom.

@Soaryn
Copy link

Soaryn commented Oct 3, 2020

Having looked over the report image, I noticed that it came from my report. I'm hoping I misunderstood something with the potential fix here, but I wanted to ensure a use case was achievable:

Having 3 layers,

  • A: Post Processed Background as a default back drop.
  • B: No post processing for external capture sources that renders over the backdrop.
  • C: Post Processed overlay with bloom that renders on top of all of the aforementioned sources.

The backdrop is purely there to be in case the capture source is not present, but can still render high end graphic such as a VFX animated wall. The Capture sources are coming in via a capture card and read into a Render Texture which can then be used anywhere in Layer B (currently as quads to allow reshaping) without color modifications such as tone mapping or emitting its own bloom values. The last layer is to allow a dynamic overlay with bloom and other post processes to overlay onto the capture. It is important to have bloom from layer C to show on Layer A or B, but I want to ensure that Layer B itself does not create a bloom.

I don't mind elaborating more, but I'd prefer to have a vocal conversation with someone regarding this. The compositor thus far seems to be a nice broadcasting production solution, but some things are slightly issued. I am currently using it in fact, but restricted by issues that have already been fixed such as the screen flickering internally, but not fixed publicly.

Note: One of the benefits to the compositor is allowing you to control which objects get what process, but if you bloom every thing based on the last layer, that defeats that purpose.

@pmavridis
Copy link
Contributor Author

pmavridis commented Oct 5, 2020

The last layer is to allow a dynamic overlay with bloom and other post processes to overlay onto the capture. It is important to have bloom from layer C to show on Layer A or B, but I want to ensure that Layer B itself does not create a bloom.

First of all, thanks for using the Graphics Compositor and for all the feedback. We really appreciate that.

Yes, you will be able to do what you want (after my last update). The alpha channel is used to control which areas of the image create bloom/glow. So on your last layer (Layer C in your example) make sure the "clear alpha" checkbox is selected.

Here is a screenshot on how this looks with the cubes:
image
In this example, only the foreground layer has bloom enabled.

  • On the left side, when the "clear alpha" option is not selected, the alpha channel includes the regions that were drawn from previous layers, so both cubes create glow because they are in the alpha channel.
  • On the right side, the alpha is cleared before the last layer is drawn, therefore only the last cube/layer is creating glow.

So I think this should cover your use case. If you have any other concerns, please let us know.

@sebastienlagarde sebastienlagarde merged commit c9030f5 into HDRP/staging Oct 8, 2020
@sebastienlagarde sebastienlagarde deleted the HDRP/case_1272621 branch October 8, 2020 10:16
@remi-chapelain
Copy link
Contributor

Check with a fresh project to understand what was happening ✔️

@Soaryn
Copy link

Soaryn commented Oct 22, 2020

The last layer is to allow a dynamic overlay with bloom and other post processes to overlay onto the capture. It is important to have bloom from layer C to show on Layer A or B, but I want to ensure that Layer B itself does not create a bloom.

First of all, thanks for using the Graphics Compositor and for all the feedback. We really appreciate that.

Yes, you will be able to do what you want (after my last update). The alpha channel is used to control which areas of the image create bloom/glow. So on your last layer (Layer C in your example) make sure the "clear alpha" checkbox is selected.

Here is a screenshot on how this looks with the cubes:
image
In this example, only the foreground layer has bloom enabled.

  • On the left side, when the "clear alpha" option is not selected, the alpha channel includes the regions that were drawn from previous layers, so both cubes create glow because they are in the alpha channel.
  • On the right side, the alpha is cleared before the last layer is drawn, therefore only the last cube/layer is creating glow.

So I think this should cover your use case. If you have any other concerns, please let us know.

So now that 10.1 is available via the package manager I was able to sit down and try it out. Back to the use case at hand how would I achieve what I asked earlier? Because if I wipe everything out by clearing the alpha on the last layer, the Background layer is not able to bloom. The use case is that both the Foreground AND the background would have the same post processing FX, but the capturable layer (the layer between) should not have fx. Because the layer is in between the 2 Post processed layers clearing the alpha of the previous layers seems like not the correct approach.

In my attempt this is what I was able to achieve and this is not quite what was desired:
image

As a note, by changing other post processing fx, I can achieve the same appearance such as by turning off exposure; however, the appearance should be the same between the 2 cubes on the left and right regardless of Volume settings as they are using the same volume.

@pmavridis
Copy link
Contributor Author

pmavridis commented Oct 24, 2020

So now that 10.1 is available via the package manager I was able to sit down and try it out. Back to the use case at hand how would I achieve what I asked earlier?

You have many options. Which one is better depends a lot on your content. In particular:

  • If the capturable layer has depth (ie you display the video on a quad or other surface with depth), you can just move it on the top of your render schedule. The stacking of the sub-layers is depth-aware (if clear-depth is not selected), so the order in the list is only important for transparency/translucency effects, otherwise the output will be the same even if you re-order the layers.
    In this case you have to clear the alpha on the background layer (which will be in the middle of the list) and then enable bloom on the Foreground layer (without alpha clear), which will be the last rendered.
    If your video has alpha/transparency (through chroma keying for example), and you expect to see the background behind your video, then with this approach you will be limited to alpha clipping. (You cannot render the video as transparent surface because the background will be rendered later)

  • If the order of layers is important (for transparency for example), then perhaps the best option is
    a) all layers keep (not clear) the alpha
    b) the sub-layer in-between with the capturable should output zero alpha for the pixels that it writes (even if they are opaque). You can do this for example by drawing an "invisible" quad on top of the video that writes alpha but not color (and/or using a custom pass).
    [edit: before my edit I suggested to use an "Alpha Mask" input filter for the video sub-layer (see the input filters section), were you can override the output alpha with a texture/mask that will be black on the regions that you draw the video and white otherwise. This is easy to setup but would work for rather static scenes]
    c) The Foreground layer is the only one that renders bloom

  • Of course another option is to enable bloom in both background and the foreground (all layers clear the alpha). This is my least favorite option, because you will pay the cost of bloom two times, and any objects in the capture/foreground layer will be drawn on top of the bloom from the background layer, so you will have discontinuities. Generally I would try to make the second option work.

  • Finally, the option that gives you the most flexibility (depending again on the content) might be to add three composition layers in the compositor (by adding two more Texture2D input properties in the composition graph - in this case the Compositor Window will automatically show the extra layers and you control the mixing with the Shader Graph). This way you have full control on the way the layers are mixed/blended together and you could even implement the blending modes that you know from PhotoShop, use a black-and-white version of a layer as alpha etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants