# Boolean on cycles rays, not on mesh

Given a scene with objects and light sources, I want to add a box somewhere in the scene that surrounds some objects and collisions with some others. A camera looks at the box from outside.

Now I would like that Cycles only shows stuff inside the box. The result is that the box will act like a slicing volume, not at the mesh level but at the ray level.

Is it possible to do this kind of boolean operation on the light ray with materials ?

• Are you meaning like if you put the camera inside your "slicing box", maybe on one face center vertex? If the box is completely closed, and the camera inside, cycles will render only what is inside the box... Oct 13 '15 at 10:01
• The problem is that my camera is outside of the box and yes the box would be completely closed in order to "cut" anything beyond it. Oct 13 '15 at 10:59
• If the camera has to be outside the box, and the box is completely closed, I guess cycles can't see what is going on inside from that camera..? Maybe I still don't understand... Oct 13 '15 at 11:20
• You can make the box transparent of course, but then I wish that everything outside the (transparent) box is cut. Oct 13 '15 at 11:24
• ...unless you would like to experiment something like this blendernation.com/2015/08/06/render-through-the-objects but with the camera outside Oct 13 '15 at 11:28

## Mask with "Coordinates from object"

You can make a pass-trough node that is able to mask with a transparent shader all the geometry outside box object.

Basically you pick up the box coordinates, take the part outside the (-1,1) range (which actually depends on the box scale factors) of each components, sum all the contributes and assign to that a full-trasparent shader. The pass-trough masking node must be assigned to every material of the scene.

Notice that you can even scale the cube in different axis and it will still work as expected (never apply scale to the cube, or you'll lose this property).

The only limitation is that the proces is based on math, not geometry. The cube only help to better see the cutting boundaries, but there is not a true dependency (it would work even with an empty, what really matter are the object's coordinates and scale).

In this case the math behind the clamping is quite simple: it will consider only the object's bounding box. With some effort you should probably be able to build fror example a sphere/ellipsoid mask, a torus mask,... and even more complex shapes (you can sum the contributes of several individual masking objects).

If you would like to smooth out to the boundaries of the selection, just substitute the "Greather than" math node with a color ramp for each channel.

Almost infinite implementations could follow, as far as your math knowledge can support you

Here's another example with a spherical falloff:

• This is amazing !! This is exactly what I needed. Thank you ! I'll try this now and validate the answer soon. Oct 13 '15 at 13:04
• Is it possible to cap the surfaces that are cut away by showing the cube where it intersects with the monkeys in this case ? Oct 16 '15 at 8:00
• Cap the surface would mean create new geometry where before there was not. Suzanne's head is empty, all the object in blender are made of surfaces only. It's not a easy task to do only in the rendering phase. My first thought would be to use volumetrics as already suggested by @Jerryno (but it will increase your rendertime considerabily)... Oct 16 '15 at 8:08
• @Kristo you can use the color ramp to control the masking instead of a greather than node, which gives you an harsh transition. I've added an image of the nodetree in the answer. Feb 22 '18 at 23:38
• I've added that @Kristo. Feb 27 '18 at 22:22

What you want is a box with black (= no) material - this blocks/culls rays. Anything that is outside (lamps etc) of this box cannot influence what is inside.

But you want it completely transparent for camera, because we don't want to cull rays coming into camera - we would see nothing from inside of the box:

And that's it. You just need to boolean all the scene's geometry with the box also, because we don't want to render anything outside the box.

• My title explicitly mentions "boolean [...] not mesh". I have scenes filled with thousands of complicated objects and boolean operations consume way too much resources (including time) to even consider this. Oct 13 '15 at 13:02
• @nantille if you need to do this with shaders, you will have to use volumetric materials, otherwise you will see inside the objects when culling them. You can cull them based on object space coords of the box - as Carlo already did. Oct 13 '15 at 14:52
• Thanks for the additional explanation. With a very high density, a volume absorption shader works quite well. Oct 19 '15 at 9:11