Light Path Node for area in Shadow Pass?

So, I have been playing around with the shadow pass lately. And for various reasons (mainly NPR) I would find it useful to create a shader that targets specifically the area that shows up as black in the shadow pass. (Say, I would like to apply some color or texture exactly to the shadow areas and later on mask these areas using the shadow pass in the compositor.)

At first, I thought that should be pretty easy using the “Light Path” node (specifically, “Is Shadow Ray” or “Ray Depth”), alas, no luck so far.

Can anybody offer any ideas? Is this possible at all?

What are you trying to achieve?

You want to color the shadows in realtime in the viewport or as a post in compositor?

If you want to colour the shadows in realtime, you could use the Shader to RGB node and do some manipulations in the shader itself.

For example, you can seperate HSV from the Shader to RGB node and use math node to filter out values less than or equal to 0 in the saturation and value channel and use it as a mask to color black areas in the viewport. Or if you just want to target dark areas, you can directly use a colour ramp.

Basically, yes, I would like to colorize or texture the shadow areas. And I did already think about using the Shader to RGB node and/or using a Color Ramp. However, this does not allow me to exactly (!) target those areas that the Shadow Pass contains.

Basically, I would like to create a workflow, where the final image is composited using render passes, such as a pure Color Pass (without any shadows), a Shadow Pass, an AO Pass, a Freestyle Pass and so on. These passes should be rather simple and straightforward and no special effects will be applied during compositing. I would simply like to save the passes as separate files to bring them into another software.

What makes this difficult, is that I would like to, say, apply some color (or texture) to the shadow area in the Shadow Pass, but using a material (!) so that the composite result can be previewed in the viewport.

My first idea consisted of using an Emission Shader and multiplying it with whatever is supposed to end up in the shadow area using the Light Path node, but this does not seem to work.

Actually, now that I think of it… I do not even insist on using the Shadow Pass. I would simply like to find a way to somehow separate the image into the same light and shadow areas during shading and compositing.

For eevee and no compositing you’re pretty much stuck with what you can derive from shader to RGB node. All the other lightpath nodes work on baked lighting only and are pretty useless.

Thanks, unfortunately that confirms what I was seeing in my tests.

But I’m willing to switch to Cycles, if that solves the problem. However, so far, it looks as if even Cycles doesn’t allow me to target specifically those areas that will later appear in the Shadow Pass. Or am I overlooking something?

I don’t know Cycles well enough to say anything definitive, but I haven’t found a easy way to do it. There’s way more flexibility with it though and you have OSL on top of it - if you’re willing to take the rendering performance hit from CPU only rendering.

Hi, did you find some solution for your goal? searching for method to create separate shadow and line layers too