3
$\begingroup$

This image sums up my problem, which is a spherical cut instead of cubical I would like a boolean effect to allow me to show the inside of a machine. The cube shown on the left uses a boolean modifier, with a cube as the cutter. The right shows my current state, which is undesirable because of the spherical cut. I can get all sorts of transparency shapes except one that behaves like a cube. Note: I am not trying to get the true effect of a boolean which adds geometry to fill the hole - like the faces shown in red.

Blend file: https://drive.google.com/file/d/1ZvMw58LljFR22X2Ykv8q7NeWsFLgC2uT/view?usp=sharing

$\endgroup$

3 Answers 3

3
$\begingroup$

Of course you cannot use a Spherical gradient when you do not want a spherical cutout.

I would not use a Gradient Texture at all. What you need is the distance of the empty to the cube, but the problem is, a simple Vector Math node set to Distance will also result in a spherical cutout, because the location of the empty is just a point in space. So you have to get the distances on each axis separately.

Here I am using some Math nodes set to Compare after a Separate XYZ node to compare the distance to the center of the empty.

I do this by checking if the X, Y or Z value is 0 and the Epsilon value is the distance from the center which I want to be cut out from the cube. Multiplying the results of the comparisons give True (or 1 or white) for everything within the given distance from the empty on all axis. Everything further away will be False (or 0 or black).

Since I am checking all distances 1-dimensional on the axes separately, I do not get a spherical result.

setup

I plugged a Value node into all Epsilon inputs to be able to control them all at once. This makes the empty cut out a cubic shape. You can of course control all axis individually if you want one side longer or shorter than the other.

I have used a Value of 1 here for the Epsilon because this way it will exactly cut out what the empty shows with its default cube size of 2 × 2 × 2 m and this way scaling the empty in Object Mode will make the cutout size follow the size of the empty:

empty scaling

This will not only work with scaling, but with rotating too just as if you would use a Boolean modifier with a cube as cutter:

rotating empty

By the way, you can do it without the need of a second object like the empty as well. Just use the cube Object coordinates directly and add some offset to it with a Vector Math node. Of course the empty is a better visual help than just some values, but nevertheless it can all be done within the shader without any other objects:

use original cube

$\endgroup$
5
$\begingroup$

The setup for a cube cutout is simple just test all 3 axes separately or assuming it's an actual cube (all sides equal), take the maximum of all coordinate components and see if the biggest one is outside the cube size.

Imgur mirror (SE image hosting has problems)

BONUS

You can replace the empty with another cube, give it a very similar shading:

Imgur mirror

Flip this Cube2 normals and enable camera backface culling [I think backface culling only works as an optimization, otherwise it's not needed or can even break rendering semi-transparent meshes - thanks Gordon!] in material properties for this boolean-like result:

Imgur mirror

v.5.0.0.

$\endgroup$
6
  • $\begingroup$ Oh, that's the simpler setup I couldn't think of quick enough. Well, mine can still be used if you do not want the cutout to be spaced equal in all directions (I know, you can do this by scaling the axes differently, I'm just clutching for straws to rectify my more complicated solution 🤣). At least my answer was the first... 🤣 $\endgroup$ Commented yesterday
  • $\begingroup$ @GordonBrinkmann your solution is pretty much the same - instead of "absolute"->"greater than" you use "compare". Instead of taking the maximum to make the comparison once, you do 3 separate comparisons, which might be easier to understand or modify. I thought about deleting my answer after seeing yours but figured some people prefer short answers ¯\_(ツ)_/¯ $\endgroup$ Commented yesterday
  • $\begingroup$ No, don't delete it, yours is good too. I just figured mine out quicker as I said, otherwise I would have made it similar to yours too. $\endgroup$ Commented yesterday
  • $\begingroup$ Now that I downloaded your file there's two things I don't understand: I cannot see any difference between enabling and disabling camera backface culling, so why bother is it necessary? The other thing is, I would suppose this to not work in Cycles, because the camera backface culling is only available in EEVEE, which would be a problem if someone wants to render with Cycles (or at least you would need a different material for it). But I just tested it - fortunately, since the culling doesn't seem to have any effect, the material works in Cycles just as well without changing it. $\endgroup$ Commented yesterday
  • $\begingroup$ @GordonBrinkmann You're right. My reasoning was, I don't expect to see the outside of the cutter, but this outside is removed by the alpha calculation anyway. meanwhile the outside that is inside the main object is occluded by that main object. And if you play with transparency then you probably want to display both inside/outside. So I think this backface culling only works as a potential optimization. $\endgroup$ Commented 22 hours ago
3
$\begingroup$

One method is to use a Boolean difference modifier to cut the object using a cube that's assigned a transparent material. If the modifier uses the Materials > Transfer setting, the new faces created by the modifier will have their material set to the transparent material of the cube.

For example, here's Suzanne cut by a Cube:

enter image description here

The material on Suzanne is just a normal Principled BSDF with no special setup. The material on the Cube is just a Transparent BSDF. The following modifier is attached to Suzanne:

enter image description here

Here's my Blend file.

$\endgroup$
1
  • $\begingroup$ Noteworthy to say, the Boolean modifier can be glitchy sometimes and can use more resources. When he doesn't need or doesn't want the newly created faces by the Boolean modifier and just needs simple cutouts like a cube shape, I would prefer one of the other answers here. $\endgroup$ Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.