Use shadows as a blend factor?

Hi everyone!

I’m trying to create a shader in the style of Wolf Among Us. For most objects in the game, they have a fairly standard toon shader with an unlit line shader layered over the top (with a contrast filter and maybe a blur set to distance from camera? still a little hazy on that one).

The specific shader I’m interested in synthesizing is the one used on the floor in this image:

As you can see from the image, the line layer I was talking about before is inverted within the boundaries of the shadow. The non-line areas become unlit black and the line areas become transparent, allowing you to see the paint layer beneath.

I’m new to material construction in blender, but my first thought for this would be to ramp the shadows and use them as a factor to blend between two other shaders, but I haven’t been able to figure out how to access shadow levels.

Is this possible? If not, is there some other way to replicate this effect? I thought possibly using OSL, but I don’t see a way to access light levels from within OSL either. I could use the relative normal vector to a specific light, but this wouldn’t create self-shadowing.

Any help would be appreciated!

Thanks!

The true answer is yes. But you need to encode all the lightning into the shader; which, on the other hand, makes mantainance and modifications very difficult (it’s almost as making a new render engine inside the render engine you’re using). Therefore it’s unadvisable to do it, and should be considered as hacking and bad use, not to mention the difficulty of doing it.

The OSL shading paradigm is such that shaders are supposed to be lighting independent. This is so to make them look good in any light condition (and specifically for PBR).
Since your objective is NPBR, you’ll be better making those effects as a composite effect (making different layers with the information you may need, like Shadows, ObjIDs, etc).

GLSL can also be used to create this kind of results, if needed in a realtime enviroment. But the logic to draw with OpenGL is quite different from the shading definitions from OSL, and you’ll require even more programming skills than the ones needed for OSL scripting.

Drat, I was worried that would be the answer. Thank you Secrop, I’ll look into using compositing to get this effect.

It’s unfortunate that one needs to duplicate objects to use different materials on separate render layers. I expect I’ll have to use scenes, which could be a little messy. Le sigh. Nobody ever said this was easy. :slight_smile:

Check the manual for ‘render layers’, ‘render passes’, and the layers’ material overwrite. Those options are quite usefull for later composition. Also, when using scenes, you can have most of the datablocks linked instead of copied… this will make changes propagate to all scenes where the linked datablocks are used.

Thanks again Secrop!