Render oject A when behind object B, but not if behind object B and object C
Hi there,
I'd like to start off by saying that my shader coding knowledge is pretty limited. I know the basics and I can eventually understand how a shader works, but that's about it.
Please have a look at the following image:
I have 4 objects in the scene above. The ground (beige), one red cube on the left side that's above the ground, one red cube on the right side that's half above and half under the ground and a blue wall in front of the 2 cubes. The red cubes render only if they're behind the wall so if I was to delete the wall they would become invisible.
What I would like to achieve is to have the red cubes be visible when behind the wall, but not the area that's under ground. So the right cube should only be rendering the top red part and not the bottom beige part as well.
Here are the 3 shaders that I'm using:
Cubes: https://pastebin.com/msuyi1zj
Ground: https://pastebin.com/ttL45Gjm
Wall: https://pastebin.com/QcL0uY8j
To gives you a scenario where I would be using something like this, imagine an RTS game where you want units behind walls or other objects to be visible so the cube shader would be like an outline or silhouette shader. Now imagine that you also want these units to hide by going underground. Currently, if they were to go underground but were also behind a wall, they would be visible.
Thank you very much in advance!
One idea could be to compare the output color and if it's not red then don't output anything, but I'm not too sure how to write that so it works :(. If you look at http://www.pulciu.com/screenshot.jpg the right cube which is half above the ground and half under, prints the top part as red and that's all that I would like to keep.
Answer by stefanplc · Jul 31, 2019 at 02:55 PM
If anyone else runs into this issue, the answer has been posted here: https://forum.unity.com/threads/need-help-with-my-outline-shaders-visibility-behind-walls.718499/