See-through for objects occluding player character

Hi guys,

I am currently working on a third-person game with a camera far from the player. As the player travels through the map, some objects occlude him from the camera.

I am using the simple BP solution when I make a capsule multitrace from camera to char and hide all objects hit by trace (and unhide all objects not occluding player any more). I also use custom depth stencil outline for player, in case hiding object is not enough. The next thing I would do is instead of hiding storing the object’s material in the array and setting it’s material to transparent fading material, so it looks like the object fades away when the character is running behind it.

However, all these solutions are far from production-level stuff I would like to have. During one of Epic’s live streams, the guy showed a translucent material which was reading player’s position from dynamic parameters and making the part of itself which obstructs player transparent in a sphere radius. Like this:

Now, there is no way we can afford, both in terms of performance and man power, turning every object’s material into custom translucent material with this depth/location-based functionality. The only way around I see is going into engine srcs and extending Opaque blend mode’s code to employ this player-detecting code (player location would be supplied by Cpp pawn data, I guess; a checkbox disabling the code can also be added into material editor to disable the code).

The problem is - I have no idea how hard it is to put this code into the code for Opaque blending. I also don’t know (yet) where to start looking into those engine shaders.
Any advice?

Hopeless bump :frowning:

There is not much you are going to do by modifying opaque objects. You would just be making them not opaque anymore so it would be pointless. You could use a masked material on everything which is cheaper than translucent as long as the mask is mostly opaque. It will make the overall scene a bit more expensive though.

What I would probably do instead is use a vertex shader trick to make the character render on top of things. The downside is that it will affect the dynamic shadow casting so you may need to have a hidden copy of the player set to “cast hidden shadow” so that the shadow stays correct.

This trick is to simply get the distance from the player to the camera and then multiply that down a tad (or clamp to prevent pulling verts into the clip plane), and then multiply that by CameraVector and add the result into worldposition offset. You can make a scalar to control how far the offset is.

Note that it won’t let you use CameraVector in the vertex shader but it can be computed as simply normalize(worldposition - cameraposition). I might have that backwards, so try multiplying everything by -1 if it doesn’t seem to be working.

Masked material with dithered transparency.

I just had another thought too, you could actually use pixel depth offset on the opaque geomety to push the pixel depth to be behind the characters. This would not come without issues but it could be possible.

To do it you need to just transform the character position into screen space and then use a circle shaped mask to push the pixels around the character. Or you could use a separate scene capture to capture the shape of the character to a render target and then you could reference that texture in any opaque materials.