3
$\begingroup$

There are two objects, for example, a cylinder and a sphere placed at the same point. The third object should act as a scanner or X-ray. Only ball is visible without an X-ray, and if you look through the X-ray, the ball is not visible, but the cylinder is visible. Let me clarify that we are talking about rendering.

UPD: I'll ask more simply. How to make an object visible if you look at it through another transparent object and vice versa - how to make another object invisible if you look at it through a transparent object.

This should be a dynamic effect.

UPD2: Clarification: only one defined object should be transparent, others should not become transparent. Accordingly, another object should become visible only within the limits of the "X-ray - object". It should not be visible outside of it.

UPD3: "Inside and outside" is not meant literally. We are talking about examining objects through an "X-ray object" as if through a magnifying glass or something.

$\endgroup$

1 Answer 1

3
+100
$\begingroup$

You can accomplish this using View Layers and Compositing.

Cryptomatte composite

A slightly complex setup using view layers and a cryptomatte mask:

Cryptomatte example Cryptomatte setup

To set this up, move objects into collections based on when they should be visible. The red cube is in a collection named "both", pink suzanne is in one named "xray only", and the yellow sphere is in one named "base only". Then I put the xray lens in its own collection.

Then create a second View Layer, this lets you toggle the visibility on the collections to create two renders with different objects visible. In the base, I've just disabled the "xray only" collection. In the xray view layer, I've disable both the "base only" and the "xray lens" collections.

In the base layer I enabled the Cryptomatte Material pass, then in the compositor used the Cryptomatte node to mask the xray layer and overlay it onto the base layer only where the lens material is.

Simple Alpha Over composite

Heres a very simple setup using a holdout collection and an alpha over node:

Base Render Layer with a holdout collection: Base Render Layer with a holdout collection

Xray view layer with duplicated meshes assigned different materials: Xray view layer with duplicated meshes assigned different materials

Simple compositor setup to combine the two layers: Simple compositor setup to combine the two layers

Whats happening here is each View Layer is rendered separately, and the holdout collection punches a hole in the first View Layer by setting its pixels to alpha. So that when it's overlayed, the xray View Layer is seen through the hole. So you can hide everything in the first View Layer, and unhide just the suzanne in the xray View Layer. You can compose them any way you need for all kinds of effects.

$\endgroup$
5
  • 1
    $\begingroup$ Can you attach this blend-file please? $\endgroup$
    – arachnoden
    Jul 20, 2022 at 7:12
  • 1
    $\begingroup$ Heres a link that will expire in a week: we.tl/t-4Zb958eBYI I'm not aware of a good way to attach it to the answer yet, I will if I find it $\endgroup$
    – Bloop
    Jul 21, 2022 at 0:55
  • 1
    $\begingroup$ almost what I wanted, but if you hiding both spheres, Suzanne is completely visible, and she should be "cropped" outside the "x-ray cube". Can you supplement your answer with this in mind? $\endgroup$
    – arachnoden
    Jul 21, 2022 at 7:33
  • 1
    $\begingroup$ Bingo. Just what i need. But when I click on the link it says "that page can’t be found". Can you upload file to some other file exchanger please? $\endgroup$
    – arachnoden
    Jul 21, 2022 at 18:56
  • $\begingroup$ @arachnoden Reupload that should work, I'll find a better one to use in the future: we.tl/t-KLtNpibC7C $\endgroup$
    – Bloop
    Jul 21, 2022 at 20:00

You must log in to answer this question.

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