how to get postprocess material result to use it as mask in materials

Hello,
I’m trying something tricky.

I want to make a horror game with a special mechanic. The idea is that the enemy is invisible in shadow but visible in light.

To achieve this, you have to find out which pixel is in the shadow and which pixel is in the light. The problem is that unreal doesn’t provide this data.

So here’s how I did it:
Using the post process Scene texture and Diffuse color, I get the color of the pixels and then set them to black and white. After that, if a pixel is too black, I assume it’s in shadow.
And it works… on post process material…

The problem is that unreal calculates the light at the very end, so only post process material can access the pixel color with the light applied.
The question is how to get the result of the post process to use it in a material. I had an idea like a fake texture or something like that (I’ll be late by a frame, but it’s the best idea I’ve had).

Not 100% certain this approach would work, but might be worth looking at this tutorial:

He goes through a method of creating a PPM that takes advantage of the shadow information. Might not be quite the right way but…