← All ideas
  • Published 7 Dec 2017

Mask Shader

It would be great if we could have a shader for both cycles and #eevee that mask whatever object has it and or is IN it.

it differs from the holdout shader because the holdout shader kills everything behind it, its similar to the transparent shader but the problem with the transparent shader is that is poly asignment based.

So more specifically what the mask shader would do is what the "mask" option in the render layers does now, but more powerful because you could have a factor and have it make gradually dissapear all the objects that are contained by a box (kind of like with transparency but each object would still have their own shaders), without affecting objects that are in the background. It would be the same as having a mask in the compositor but that is in 3D space, with the power of cycles, and sooner than not eevee this would solve a lot of things that are needed to be done with complex compositing and layering techniques to one shader.

I'll probably try to implement a few mockups but I think it's clear enough to get the idea out.

92.3%

Development Status: Open

Upvote 12 Downvote 1
luciano
7 Dec 2017

10 Comments

ChameleonScales

actually I think creating such a shader is impossible without fundamentally messing with the Cycles shader system. Here's why :

What shaders do is simply tell light rays what to do when they hit an object possessing that shader. For a 100% transparent surface shader, it tells the ray to go forward unaltered. For a holdout, it tells the ray to stop and leave a value of 0 for all RGBA channels.

But once the light ray has passed that object and goes to the next one, it can only follow the new instructions given by that next object. A shader cannot give instructions for future bounces of the light ray. In other words it can't tell a light ray : "go forward but also don't pay attention to the instructions of the next 3 objects". And developping a shader that would allow such behavior would probably require rewriting the code from the ground up.

However, the effect you're looking for is doable with the current Cycles features. See, light rays do carry information about the previous surfaces they hit, and that information can be used in the shader of an object you'd like to mask. For example, if the foreground object has a transparency shader and the next 2 objects have this node setup : they will reveal the objects behind them only when the first one gets in front. Just like this :

Here is the wireframe :

As for masking only parts of an object that are contained inside the volume of the "mask" object, it just takes 3 more nodes :

and there you go :

Here's the solid view :

8
luciano Author

@Caetano Veyssières: great stuff my friend, though i dont understand iun the last example hy you dont get to see the interior of the cilinder in the other hand what you say might be true, it might be messy but im just thinking of easy functions that could improve how you can approach the creation of motion graphics and such things that blender could be great at and that hasn't been solved. And hey if nobody has done it we might be on to something good.

ChameleonScales

"i dont understand iun the last example hy you dont get to see the interior of the cilinder"

You mean like if the cylinder had a difference boolean with the torus ?

luciano Author

@Caetano Veyssières: yes.

ChameleonScales

Ok, so I found a setup that can do it, as this result shows :

boolean material gif result

As you can see the dropped shadow on the ground doesn't take the "boolean effect" into account. Maybe there's a way to make it so it does but I haven't figured it out yet.

for the cube I used the same material as the blue cylinder in the previous setup and for the torus I used this material :

boolean material node setup

1
kotulsky

It's just saved my day! Thanks a lot! But how to deal with glass shader and volume?

luciano Author

hey thanks for the answer, is it possible to make it work on eevee ?

ChameleonScales

Since Eevee isn't a raytracer and therefore can't use the LightPath node, I don't see how you could retrieve information about previous hit surfaces, so, not to my knowledge.

mradamearle

what about objects masking objects and being able to invert that mask. I'm not sure that is even possible.

ChameleonScales

That seems insanely useful but has it ever been done in any other 3D software ?