Search Unity

Post-Processing different per camera

Discussion in 'General Graphics' started by Shaggy22, Feb 12, 2018.

  1. Shaggy22

    Shaggy22

    Joined:
    Jan 25, 2018
    Posts:
    4
    Hi, I am looking for a demo/example/documentation of how I would setup different cameras with different post-processing effects. I have done quite a bit of searching, and one of the more common methods I have seen is to render the cameras to different textures (with culling on the layers I want each camera to affect), and then blit (composite) them to a final texture. Am I understanding that right? I have tried messing around with this but I have not had any success.

    For my sample project, I want to apply a large amount of bloom to the main game window. For the UI camera I want to apply a minor amount of bloom. But I guess I am just not understanding the process.

    Any examples of how to accomplish this would be really helpful. Thanks.
     
  2. nygren

    nygren

    Joined:
    Feb 13, 2014
    Posts:
    33
    Maybe I'm not understanding what you're trying to do. If you're using Unity's standard Post Processing Behaviour effect, then you'll have that component on each Camera. The Post Processing Behaviour has a reference to what Post Processing Profile to use, so you could have two different profiles - one for each camera, with different bloom amount set.
     
  3. Shaggy22

    Shaggy22

    Joined:
    Jan 25, 2018
    Posts:
    4
    Yes I am doing that, where the UI camera is rendered 2nd with its own post processing profile. Problem is, the bloom from the ui camera is further blooming the other (game) camera. I want the effects to be independent of each other. Does that make sense?

    Thanks
     
  4. nygren

    nygren

    Joined:
    Feb 13, 2014
    Posts:
    33
    Yes, it makes sense.
    Your RenderTexture approach seems correct in principle. Disclaimer: I am not good at these things, so all I write is probably inefficient and too complex!

    This might work:
    1. A UI camera that is setup to render to a RenderTexture and renders before the main camera renders (and with its own post processing profile).
    2. UI camera's Clear Flags should be a fully transparent Solid color.
    3. A main camera that renders as normal with its own post processing profile.
    4. Create a custom post processing script that will compose the RenderTexture from the UI camera on top of the screen or destination RenderTexture given to its OnRenderImage method.
    5. On the main camera add your custom post processing script below Unity's Post Processing in the Inspector.

    What might be causing problems is that I think when you enable Post Processing on your UI Camera, your RenderTexture will no longer have alpha as transparency because the Post Processing uses it for effects. So your UI would not be able to be transparent without some modifications to the approach.

    I guess you could try to save the alpha channel before the Post Processing script runs and then restore it. However, if the post processing causes extra pixels to be filled - for example because the bloom causes a glow outside your UI, then that wouldn't be visible unless you handled that as well. For this latter problem, perhaps for each pixel that now has an alpha and previously didn't you can check it's color against the camera's clear color, but now it's getting really messy and error-prone :)

    Another solution to the alpha is to use version 2 of the Post Processing stack which I believe fixes this alpha problem. https://github.com/Unity-Technologies/PostProcessing
     
  5. Shaggy22

    Shaggy22

    Joined:
    Jan 25, 2018
    Posts:
    4
    Thanks for the help nygren. I'll have to play around more with this info, with version 2 of the stack. I didn't know there was one.
     
  6. enigmagame

    enigmagame

    Joined:
    Feb 16, 2014
    Posts:
    13
    Hi Shaggy22,
    have you found a solution? Have you found a way in order to have different effects on different cameras?
    Thanks.
     
  7. Pimpace

    Pimpace

    Joined:
    Sep 21, 2017
    Posts:
    41
    I have the same issue... I couldn't get any solution. :( I'm using HDRP, but I can't separate the postprocess effects.