Highlight objects behind other objects

The typical case in an RTS where an unit goes behind a building so you draw an outline around the actor in background to let the player know it’s there.
Now, I’m sure I can code a solution for this but I feel this could really hurt performance when doing it wrongly, so I better ask first.
What’s a suggested method?

Hey @DEV7591!

So the typical way to go about this would be a post-process volume! We have a tutorial for this! :slight_smile:
As far as the behind-a-building thing, as-is, this should supply that functionality.

Let me know if it doesn’t because it should just be a minor adjustment!

1 Like

Thank you very much, I will try to implement it following that tutorial and let you know the result.

I watched the video and I don’t see what I asked about is mentioned anywhere there.
It barely deal with the material part and that’s it.

Yeah, if that is the video I’m thinking about, then it doesn’t render outlines around things that are hidden behind walls.

To achieve the effect in question, perhaps the best way to do this is using a custom depth stencil, and a postprocess. This is also done in that video – you just need to configure it differently. You’ll want to render objects that need an outline into that pass. Then you’ll want to have a post-process that renders an outline where a neighboring pixel has custom stencil, but the depth test in the regular frambuffer fails.

Here’s a resource on custom depth stencil that collects a few other good links: Custom Depth and Custom Depth Stencil in UE4 - Superyateam Gamedev

Pay special attention to this example:

1 Like

It seems all the logic is in the material itself, honestly I was expecting to handle it at code level, I mean the part where you decide if the actor must be outlined or not.
Anyway, I’ll take a look there, thank you.

The way this works, is that you draw every unit that might have an outline into the buffer, and then you apply the shader to apply the outline, based on the contents of this buffer. The CPU doesn’t need to be involved at all. (Well, any more than normal :smiley: )

So I was able to replicate it with some minor issues.
For example the outline kinda flickers, probably because the character has multiple skeletal meshes, not really sure, will check later.


@DEV7591 Sorry for the late reply! @jwatte thanks for the assist!

The flicker, I believe, is possibly affected by the multiple skeletal meshes, you are likely correct. It depends on how the code is set up and what it’s looking for, and if it’s looking for skeletal meshes and you have 2 or more colliding (say, a sword stuck in a guy’s chest or a skeletal mesh helmet that covers a head that’s part of its own skeletal mesh) I could for sure see that causing an issue.