A shader that makes everything transparent inside the cube

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thisischico

Is it possible to write a shader that makes all the nodes transparent inside the cube? Except that it doesn’t affect the lighting in any way. Anything inside the cube that became transparent should cast a shadow as usual.

If yes, please tell me what I need to deal with to achieve this result!

:bust_in_silhouette: Reply From: DaddyMonster

The complexity here depends on the exact behaviour you want.

If you want the whole object to blink out when it enters the cube, then just make the cube an Area, and use the collision to drive a is_inside bool. Send this in as a uniform, let it drive the alpha and job done.

Another way that makes only the parts of the obj that are inside the cube transparent is to send the cube’s origin in as a uniform, calculate the cube and set alpha accordingly. I’d start with a sphere as it’s much simpler.

Two further approaches that I’m not certain about: 1) viewports projected on sides of cubes (like the Portal 2 method) 2) It might be possible to use passes. Not sure.

I’m also not certain about alpha and shadow behaviour. Try it and see.