- Home /
Make wall partially transparent when player is behind it
Hi guys, I'm trying to create a specific shader for my game. It's an isometric game, and any time the player is obscured behind a wall I want to be able to "cut out" a circle in the geometry around him so that he can be seen at all times. A perfect example can be seen in this video from Fallout 1, at exactly 8:36;
http://www.youtube.com/watch?v=tlxRCi9OvZo
I particularly like how the circle has soft edges and really want to emulate that specifically.
Now I've actually made some decent progress with this, but I'm still not an expert with shaders so I defo still need some advice on getting it properly implemented. Thanks to other forum posts and tutorials I've experimented with the "depth mask" here; ( http://wiki.unity3d.com/index.php?title=DepthMask ) and managed to "cut out" a solid circle in my walls which exposes my character, by simply placing a "mask" object in front of him at all times. However it cuts out ALL walls including those deeper into the scene behind him, not just the front most, and it also doesn't have the smooth edges I'm looking for either. Has potential, but I put it on old.
I then found an old thread on these forums ( http://forum.unity3d.com/threads/35808-Projecting-a-hole ) about someone using a projector to "paint" transparency over objects as needed, with the projector essentially cutting through anything it shines on. This looks really nice, works well, and with the right shaped round alpha, even has nice soft edges. The down side is that the example(s) in the thread only work on very, very simple materials. As in, solid coloured objects and nothing more. I need fully materialed objects with their own textures, lighting, possibly even normals, etc, that I can still project a hole whenever needed.
Would really appreciate any tips or advice, or even solutions if you guys have any. I know it's quite a tall order, but it would really make my game shine. I could possibly provide a (very) small payment if anyone's willing to write the whole thing from scratch if it looks as good as in Fallout.
Answer by ivan2532 · Aug 07, 2013 at 02:49 PM
Hello Diggler, you should create two materials. Here is the code:
var transparentMaterial : Material;
private var myMaterial : Material;
function Awake()
{
myMaterial = gameObject.renderer.material;
}
function Update()
{
if(<here is the code to check if he is behind the wall>)
{
gameObject.renderer.material = transparentMaterial;
}
else
{
gameObject.renderer.material = myMaterial;
}
}
Tell me if it works, and tell me if it doesn't!
Ivan Božović
I would personally define the two textures in the inspector, then assign it on Awake() ins$$anonymous$$d of assigning my$$anonymous$$aterial to the current texture. Other than that, good answer.
Answer by bear1998 · Feb 25, 2019 at 03:24 PM
hey know this is an old post but im stuck on this also and cant really work out what exactly I need to be doing to achieve desiered effects
Something that might come in useful for your case is the stencil buffer. I think the stencil buffer was not accessible to Unity users at the time of this thread's creation, however now it can be utilized in shader code to basically get such a cutout effect. Im currently working on a similar effect myself, though its not at all what its supposed to be yet.
Answer by nwsx · Mar 27, 2014 at 05:03 PM
http://steamcommunity.com/sharedfiles/filedetails/?id=240845770 check this out this unity game has fallout style wall holes
Answer by CatsPawGames · Nov 18, 2014 at 04:04 PM
You can use See-Through System to achieve that. It's shader-independent, so you don't need to change your materials. It's avaliable on asset store: http://www.assetstore.unity3d.com/#/content/24707