Imagine a scene with a minecraft style world held in a bounded container and is being viewed from a isometric 3rd person camera that has a fixed orientation. I want to create a shader that expresses as much information the player might want to know, e.g. x-ray vision of tunnels and areas behind walls that the player might be in close proximity to but would normally be occluded by the terrain. Objects (such as the player) can be inside the object and should be blended nicely with the x-rayed layers.
Here is a rough illustration to convey the idea:
- Render back to front
- The first (furthest depth) fragment has an alpha of 1, and after that each overlapping fragment is alpha blended using an alpha of 0.5 (or maybe of decreasing alpha, so e.g. 2nd fragment is 0.5, 3rd is 0.33, 4th is 0.25 so we favor preserving further fragments information).
So AFAICT, this shader would alpha blend like a normal transparent shader, except that it doesn't blend/interact with anything but itself. How to do that?
I have little experience with shaders but am comfortable if I know where to read. So I'd really appreciate it if someone could point me in the direction I can look to create such a shader. The project is using Unity at the moment but I don't think that changes the approach to this problem.
Update: After clarifying some thoughts I realize that the approach described above wouldn't be the most suitable solution in my case. This is because I forgot to emphasize that the most important thing is to visualize geometry within a proximity around the player, and that current approach would potentially obscure too much of the players view if there is a lot of layers drawn in front, and it would also look a bit too "busy" in general; the player should probably prefer to just know the information most relevant to him and nothing that is relatively far away. So instead I think the blending should be most x-ray view for geometry within close proximity to the player, and fade out to the foreground as it gets more distant.