3D Capsule/cone mask in material? (solution for seeing through obstacles)

I’m trying to figure out some GPU based solution for seeing through obstacles that occlude player character. It’s for a topdown/isometric game. Here is what I have for now, prototyping stage:

The material has a SphereMask in position of camera + offset towards camera forward vector, so it’s around between camera and player. The mask serves as an alpha for DitherTemporalAA plugged into Pixel Depth Offset.
This is my first idea: Every object that can be an ‘occluder’ (e.g. trees, buildings, etc.) have this masked ‘transparency’ material logic (I’d probably collapse it to a function) added to its material.

It works, but as you can see, the fade-off starts too early because of sphere mask radius. If I decrease the radius, it won’t work at all. That’s why it’d be great to have something like CapsuleMask, where besides capsule position + radius we could also control capsule height. This way we could have a mask like that, so it would work perfectly for seeing through obstacles:

… I suspect that I could solve this by setting multiple sphere masks uniformly distributed between player and camera and adding all of them in material, but is there a better solution? Something like a capsule mask/cone mask that works similarly to the SphereMask…? But is it possible? I’d be grateful for some hints.

PS. I’ve tried CPU based solutions like line/multiSphere traces + hiding/changing object material, but I need a solution that will hide only a part of object, exactly around player character. This is because with the CPU solution, when camera detects e.g. tree leafs, then it hides whole tree instead of only the leaf area that is occluding player.

Maybe you should just transform pixel position into camera space and use BoxMask 3D?

Thank you, I’m trying to implement this, but without luck yet - I got the BoxMask 3D working, but it’s not rotated towards camera direction:

I’ve found a way to rotate the BoxMask 3D: How to rotate output of Box Mask 3D Node? - Rendering - Epic Developer Community Forums
… But can’t figure out how to rotate it towards camera direction:

Some kind of ‘LookAt’ rotation would be handy, but it’s not present in material editor…

Maybe that transform to camera space that you’ve suggested should solve this somehow, but I don’t understand how it works/where to plug it in.

You do not need to rotate anything, if you are feeding pixel position transformed to camera-space.

http://image.prntscr.com/image/27d70381f2a44efdacd9fa38c00c0122.png

Thank you, it works pretty well :slight_smile: Naturally the mask appears rectangle-shaped, but with bigger Edge Falloff it appears more spherical (close to my initial capsule-mask idea). Now I’ll try to learn how the world space -> camera space transformation works and fine tune the effect. Thanks again!

You’re welcome.

Capsule - like mask can be implemented with something like this:

http://image.prntscr.com/image/831fc0b117384599a8ca48a10de1aee8.png

Could be done slightly cheaper though.

Try Drawline-3D, it is basically a capsule. Should be cheaper as it does not require transforms.

Thank you, I’ll try this solution soon.

Could we get an example on how to use that node ? I mean “DrawLine-3D”