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

Applying image effects to just one camera in a multi-camera setup?

Discussion in 'Image Effects' started by m0nkeybl1tz, Dec 19, 2019.

  1. m0nkeybl1tz

    m0nkeybl1tz

    Joined:
    Feb 10, 2013
    Posts:
    35
    Hey all,

    I'm working on an AR project that's compositing 2 cameras: one that's the external camera feed of the real world, the other is for the virtual objects that are being added on top of it.

    It's a fairly simple setup:

    Real Camera is assigned to depth 0

    Virtual Camera is assigned to depth 1 with no clear flags, so it renders on top of the Real Camera, like so:






    So far I've just been using trying to apply the default Unity image effect shader, which inverts colors. I created a material with that shader, and applied it using:

    Code (CSharp):
    1.     void OnRenderImage(RenderTexture source, RenderTexture destination)
    2.     {
    3.         Graphics.Blit(source, destination, postprocessMaterial);
    4.     }
    My problem is I only want the effect to apply to the Virtual Camera, like so:



    However, even though I only put the script on the Virtual Camera it applies the effect to both the Virtual and Real Cameras, like so:



    Is there a way to apply an image effect to only one camera?

    I've seen suggestions about using a stencil buffer, but I'm not sure how it'd apply here. If possible, I'd prefer not to use custom materials/shaders for the objects in the scene, only for the image effect on the camera. Any help would be greatly appreciated!
     
  2. m0nkeybl1tz

    m0nkeybl1tz

    Joined:
    Feb 10, 2013
    Posts:
    35
    Randexy likes this.