Search Unity

Post Processing Stack V2 - Camera Event Control (Controlling when the stack should render)

Discussion in 'Image Effects' started by Brechtos, Jan 24, 2020.

  1. Brechtos

    Brechtos

    Joined:
    Sep 18, 2014
    Posts:
    18
    Hi all,

    The issue
    I recently encountered a rather annoying issue while using the Post Processing Stack V2 in the built-in renderpipeline.
    More specifically the inability to control when the post processing stack will be rendered to the command buffers.
    This is specifically an issue when also dealing with legacy post-processing effects that can't easily be "upgraded" to the new stack.
    By default the stack is being handled by setting the command buffer to CameraEvent.BeforeImagesEffects in PostProcessLayer.cs.
    The downside of this is that all legacy post processing effects will be rendered on top/after all of the PPSv2 effects and there is no real way to work around that.

    The Cause
    Given the type of effects that are part of the stack (for example AA) it would in some cases (and in my case all of them) be more interesting to have the PPSv2 main stack camera event set to CameraEvent.AfterImageEffects. That way the legacy Image effect setup that based on the order of the components on the camera will be handled and rendered before the PPSv2 instead of after.

    The Patch
    The only solution I could come up with was to make adjustments to the PostProcessLayer.cs by making the event an exposed property. That way the control over this timing is handed to the developer via the inspector, giving more freedom in the type of setups possible.
    Downside with this approach is that you need to embed the package into the project itself.
    Especially if you are working with source control and want an easy way to have this change available for the rest of your team.

    Should you run into the same issue. I have attached the altered files to this thread.
    Just replace the PostprocessLayer.cs and PostprocessLayerEditor.cs files and you should be able to control the timing of the stack.

    Info on how to easily embed a package from the package manager can be found here:
    https://docs.unity3d.com/Manual/upm-api.html

    Hopefully this will help some of you who run into this same issue in case Unity doesn't expose this control option themselves (pretty please.add this options so we can just use the package as is :D:()
     

    Attached Files:

    Meceka likes this.
  2. Brechtos

    Brechtos

    Joined:
    Sep 18, 2014
    Posts:
    18
    A little update:
    The fix seems to work rather well when running the game and when testing the effects in scene view. Yet for some reason, when viewing a preplaced camera in the game view while in editor mode, you end up with a full white image... .

    I'm guessing that this is because the current camera render result isn't being passed allong correctly.
    Still trying to pinpoint what is causing this. But looking at the Frame Debugger the first CopyStd seems to be the one filled with just the UnityWhite texture.

    If anyone has any idea on where I could fix this issue it would be greatly appreciated :)