Fullscreen postprocessing using light layers

Hello, I am currently working on a game that takes place in a dark cartoonish environment. I need to make visuals to differenciate between two mode of vision simultaneously (let’s call them “normal” and “sonar”). I got this working in a material shader, by differentiating between two light layers (in the screenshot, red light is “normal” layer, white is “sonar” :

but now I need to add a postprocessing layer to add outlines, which I also got working:

But now the problem is, I need to make the outline different depending on the light layer affecting the material (and none at all outside light sources). I was intending on using camera textures for that, but camera culling masks won’t work because they apply to entire objects, and I can’t find a way to have a camera texture render only one light layer… Is it even possible?

And if anyone has a better take on how to implement this, I will take it :wink:

To make things more clear, here is the test setup with lights being the same color, bu on different rendering layers :

In the material shader, I have the information of the light’s rendering layer, that I can directly render :


Here, layers 1, 2 and 3 are rendered as Blue, Green and Red.

What I try to acheive is to somehow store the light layer information, to later use it as a mask on a post precessing effect (fullscreen shader) and I can’t find a way to do it.