How can I allow an object to be seen through another object, such as an x-ray?

Hi! As in the title, I want to create an x-ray effect for my character, I want to have a skeleton inside and be visible through the character mesh.
I m not good enough with post-process materials and other material effects.

If you know a way or even an asset that can help me, I would appreciate it!!

up?

Hi @WDRK23,

Your character will need to have a translucent material in order for this to work, as it’s the only way to evaluate depth with interior objects also being lit properly without custom engine code.

This is what that shader looks like:



This code compares the scene depth (the depth without transparency) to the pixel depth (the depth with transparency). If there is a difference between the two but it is less than the size of the mesh, then the object must be inside the mesh and therefore the mesh’s transparency must be 0 to allow it to be seen through.

You will need to adjust the B number by the general size of the character. This is also only starter code, as getting the actual full effect will take a lot more work. Likely, you’ll need to use a postprocess with custom depth evaluations to re-sort the assets and make sure only the object inside the character is seen.

Good luck with this. Definitely not an easy effect to achieve.

1 Like

Actually, after digging a little bit more I realized you can use Custom Depth within a translucent material. This setup will be much more accurate:

All you have to do is set your skeleton to render in custom depth and it will be shown through the main mesh with no hiccups.

Good luck! Let me know if you have any other questions.

1 Like

hi @WDRK23

I think the X-ray image is just some lighting information on the mesh.
how to get lighting information on mesh :

Lighting data = Scene color - (material) base color 

please refer to : https://youtu.be/exMzwH7EJUY?t=997

Alternatively , considerate Lighting Channels ? Using Lighting Channels in Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

Thanks for the reply!!
The problem now is that the translucent object will be visible through other objects, even if they don’t have Render Custom Depth Pass on.

2025 05 24 10 13 58

I want it to be visible only through the character mesh.

Hi @WDRK23,

Let me clarify a little bit here.

Your character will need to have a translucent material with the code I sent above.

The sphere will need to be set to “Render Custom Depth”

There is no postprocess material needed.

Custom depth is an additional depth pass- it does not replace the default depth pass unless you overwrite it. There are a few reasons you need to do this within the actual character material:

  • You have found the main issue, which is that there is no way to specify which objects to see through. Technically, there is probably a way around this with Custom Stencils, but it would be very messy.
  • Any method other than the one I sent leads to the interior sphere appearing as a blob of color, like you’re seeing now. This is because of the character is opaque, no light or color information can pass through to the sphere- only the shape. If you want a full detailed mesh to pass through, the character needs to have translucency.