7
$\begingroup$

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 ?

$\endgroup$
8
  • $\begingroup$ 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... $\endgroup$
    – m.ardito
    Oct 13, 2015 at 10:01
  • $\begingroup$ 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. $\endgroup$
    – nantille
    Oct 13, 2015 at 10:59
  • $\begingroup$ 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... $\endgroup$
    – m.ardito
    Oct 13, 2015 at 11:20
  • $\begingroup$ You can make the box transparent of course, but then I wish that everything outside the (transparent) box is cut. $\endgroup$
    – nantille
    Oct 13, 2015 at 11:24
  • $\begingroup$ ...unless you would like to experiment something like this blendernation.com/2015/08/06/render-through-the-objects but with the camera outside $\endgroup$
    – m.ardito
    Oct 13, 2015 at 11:28

2 Answers 2

16
$\begingroup$

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.

enter image description here

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.

enter image description here

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).

enter image description here

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.

enter image description here

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

Here's another example with a spherical falloff:

enter image description here

$\endgroup$
8
  • $\begingroup$ This is amazing !! This is exactly what I needed. Thank you ! I'll try this now and validate the answer soon. $\endgroup$
    – nantille
    Oct 13, 2015 at 13:04
  • $\begingroup$ Is it possible to cap the surfaces that are cut away by showing the cube where it intersects with the monkeys in this case ? $\endgroup$
    – nantille
    Oct 16, 2015 at 8:00
  • $\begingroup$ 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)... $\endgroup$
    – Carlo
    Oct 16, 2015 at 8:08
  • 1
    $\begingroup$ @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. $\endgroup$
    – Carlo
    Feb 22, 2018 at 23:38
  • 1
    $\begingroup$ I've added that @Kristo. $\endgroup$
    – Carlo
    Feb 27, 2018 at 22:22
2
$\begingroup$

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:

enter image description here

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – nantille
    Oct 13, 2015 at 13:02
  • $\begingroup$ @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. $\endgroup$ Oct 13, 2015 at 14:52
  • $\begingroup$ Thanks for the additional explanation. With a very high density, a volume absorption shader works quite well. $\endgroup$
    – nantille
    Oct 19, 2015 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .