Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bloom: ignoring specific colors.

Discussion in 'Image Effects' started by georgeq, Jan 14, 2020.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I need to do some green screen processing, but I also need to apply the bloom effect before that. I have my camera set up to render a solid color for the background (which will later be used for the green screen), but, as far as I understand, since bloom is a full screen effect, the background color is also consider it for the process, which creates various undesired side effects, for example, red objects have some yellowish inner glow.

    I think, I could solve these issues, if I could turn green pixels black after they are sampled and before the effect is applied. I peered inside the code, but I don't fully understand how it works. It seems, it samples the screen and then somehow it applies the effect, but I haven't been able to figure out how. I suppose the samples are stored in some kind of texture, but it is not clear to me how and where.

    Could anyone please explain how could I achieve this?
     
  2. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    If you're going fully custom, bloom typically has a "threshold" pass that it performs on the scene first.
    IE, a ultra simplified version of that would be:
    1. Sample color on pixel
    2. If color on pixel is less bright than BRIGHTNESS_THRESHOLD, discard (set to black) color
    If you added in your chroma key check after 2), and discarded any green, then your bloom texture would effectively do what you wanted it to. Check out shadertoy.com and search "chroma key" for some examples, and look at (typically older) bloom effects that have dedicated threshold passes.
     
  3. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    That's exactly what I'm trying to do. The problems is that I don't know where to plug that piece of code. It is clear to me that it is sampling the screen, but I don't understand where and how it updates the pixels.
     
  4. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    It will depend on the bloom effect, there is no set pass to put it as all blooms are different, even within blooms, it could differ (ie. for a mobile-optimization, I combine thresholding into the first downsampling pass at the start with my bloom, if that's not checked, it's a separate pass). I would know where to put it in the bloom that I write for PRISM, but can't speak to others. Your best bet is to play around with some simpler post-processing shaders to see how they work (shadertoy is a good place to start) and gradually build an understanding.
     
  5. JayJack

    JayJack

    Joined:
    Dec 29, 2020
    Posts:
    2
    Emission Maps might be able to work for this if the shaders are set up properly for them, though I have no experience with 3d so I'm not sure how well it would work there