0

I'm trying to make a shader graph, which makes the object transparent if the player is behind it.

My approach was giving the player's(represented as a sphere here) depth as a parameter, and comparing it with the scene depth. Here is my shader and the result:

Shader graph example

And the result is:

Result image

The problem is, I want to make the red wall entirely transparent.

dreamend
  • 59
  • 4
  • 19
  • Considering you want the entire wall to be transparent when the player is behind it, it may be simpler and more efficient to simply apply a _transparency effect_ `(float alpha)` and simply have C# work out whether its 100% or 50% based on Z. We're only talking about a **single comparison** here rather than _1 comparison per pixel via your shader_ even if it is being done on the GPU. –  Sep 24 '22 at 11:08
  • Thanks @MickyD but how can I check if the object is behind the wall? – dreamend Sep 24 '22 at 11:38
  • Comparing z-coordinates? –  Sep 24 '22 at 11:44
  • Sorry I couldnt do it. Can you give me an example? – dreamend Sep 24 '22 at 12:51
  • Not off hand, but it did remind me of a Brackeys video. If you are using URP check out [this video](https://www.youtube.com/watch?v=szsWx9IQVDI). In it the characters are drawn differently when passing behind objects but you could possibly reverse that to make the object go transparent instead. All of this via zero coding using custom renderers and shader graphs! –  Sep 24 '22 at 22:24

0 Answers0