Postprocessing effect only works with layer "Everything"

Unity 2019.1.4f1
Post Processing 2.1.6

I’ve set up two cameras:
cam 1: main camera, culling mask is everything but “fog of war”
cam 2: fog camera, culling mask is “fog of war”

Switching them on and off, I see the correct layers being rendered.

However, when I add post processing volume & layer to cam 2 and set them to “fog of war”, the depth of field effect does nothing.
If I switch the pp volume layer to “everything”, the effect is applied to everything, even stuff the cam isn’t supposed to see.

Main camera 1:

Fog of war cam 2 (a child of cam 1 since I need it to move when cam 1 moves, not sure if this matters)

With these settings, I see everything in the scene rendered, including objects from the main cam 1 as well as the objects on the fog of war layer, from cam 2.

If I switch cam 2’s layer to nothing, I still see everything else on cam 1, but I see no objects on the fog of war layer, as expected.

But, nothing is blurred or otherwise affected by the Depth of Field effect.

If I make just one change, and set the Layer in Post Process Layer to “Everything” - then Depth of Field is applied to everything, including objects on other layers.

Any ideas what’s going wrong here?

It appears that it’s not “Everything” but specifically the “Default” layer that’s causing this. If the Default layer is not included in cam 2’s Post Process Layer, nothing works. There are exactly zero game objects on the Default layer. Nothing - yet it affects everything if that layer is included.

I’m having the exact same problem and have been scratching my head for hours now, glad I’m not the only one tho, I’d be happy to know if you find a solution :slight_smile:

The post process volume’s layer is determined by the layer of the game object the volume component is on. In this case, it’s the default layer because that’s what the camera’s gameobject is set to. You can set you camera’s gameobject to your fog of war layer without a problem since the camera itself doesn’t care what layer it’s on.

3 Likes

Ohhhhhh now that I haven’t thought of.

I’ll test that @bgolus - thank you!

No, that didn’t do it either, @bgolus . Cam 2’s gameobject is now set to the fog of war layer - but effects still apply to everything including stuff on entirely different layers and rendered by a totally different camera.

@Jacksendary did you have better luck?

It feels like I’ve tried every possible combination of every possible UI switch or button on those cameras - there is no way to make this work as I’d expect.
Whatever I do, post processing either affects nothing, or affects everything - but I can’t restrict it to a single layer.

Ah, I understand what you’re trying to do now better.

Yes, that is how post processing effects work. They apply to everything on screen indiscriminately. Since you’re applying the fog of war using the second camera, it’s also rendering over the everything the first camera rendered since it’s on the screen.

The layers thing with the post processing stack is really confusing people since the most common use of layers is for culling what gets seen by camera, or what objects lights apply to, but this isn’t exactly how the Post Processing Stack is using them. Technically they can be used to control which cameras the post process volumes apply to, but not which objects.

So, options;
If you want to limit what objects get affected by a post process, you basically need to render out a mask of some kind to a render texture or using the stencil buffer and write a custom post process effect that is aware of that mask. Unity’s provided post processing stack effects have zero support for this. You can kind of hack it in using stencils if you have the post processing stack’s uber shader use a hard coded stencil ref comparison.

The other option is to not use post processing at all, but instead apply it as custom shaders on your objects. Not as easy to do if you’re using the deferred rendering path, and depends on the kinds of effects your looking to do, but it’s a powerful option for forward rendering.

1 Like

Okay thank you a ton for clarifying @bgolus - at least I don’t need to waste anymore time with this then :slight_smile:

Cheers!

Infact I did have some luck and I feel incredibly stupid as I should had known this, although the “layer” option is a little miss leading IMO.

Long story short, Post processing effects is camera dependent, basically it is image effects which happens AFTER every thing have been rendered, hinge the name “post”. The “layer” you can choose is where to look for “volumes” as you can use colliders to derimine an area which should be affected by the effect.

As others have said you can use render textures, but this is a bit of an expensive opperation IMO, you could also before LWRP use 2 cameras which rendered different layers, but sadly this does not seem to work any more.

My new approach, although some would call this stupid is to use emission maps to get the “glow” effect, a bit of color tweaking (espeacially if using particle effects) is needed, I then exclude some layers from my “main” directional light to get the effect I want, works well for me anyways.

1 Like