Download

How to add an outline around an object in the world?

I’d like to add a glowing outline around objects to indicate that they can be interacted with (when the player gets within a certain distance).

Haven’t been able to find any examples yet. Does anyone have any ideas?

Cheers

I don’t think there’s a simple way to draw an outline around an object. But there might be some other techniques that could accomplish the same goal of providing a visual cue that the player can interact with something.

One option is to create a material that’s basically the same as the material already on the mesh, but you plug the normal map into a Fresnel, and plug that into emissive, which kind of creates a glowing outline. Switch materials when the player approaches.

Another option that someone recommended, but I haven’t tried yet is to make another copy of the mesh, but flip all of the face normals so that they’re facing in. Then make that mesh slightly larger and give it an emissive material. Put it in the same location and make that mesh visible or invisible when you want to turn the outline on or off.

If you really just want an outline, then here’s an idea, and I’m really not sure if it will work. And if it can work, it will probably require a lot of effort.

Implement the Sobel edge detection gem, but make it only operate on objects in the foreground layer (which I’m not sure can be done). When the player sees something interactive, make a copy of it in the foreground so that the Sobel post process effect draws an outline. That would then create the problem of seeing the whole mesh in the foreground, ignoring occlusion. So maybe you could copy the mesh into the foreground and give it a fully transparent material, which if you don’t have separate translucency enabled, should still active the Sobel post process. That’s a lot of work and that’s a lot of steps that may or may not work as intended, but it’s the only thing I can think of that would do exactly what you’re looking for.

the simple answer is that you can’t get a proper per-pixel outline via conventional methods without modifying the engine source (which we can’t)

the most common workaround is to make an “inline” rather than an “outline”, by applying a very thin and very strong fresnel like Nathaniel initially suggested
the other workaround of duplicating the mesh with inverted normals will cause the outline to have some artifacts where the shape is non-convex (i.e. it would behave like a toon shader, where you’d get partial outlines in the visible bounds of the mesh, rather than just an outline on the perimeter of the shape). and then you need to re-import each mesh with inverted normals with is quite a hassle

Nathaniel: the sobel edge postprocess idea isn’t bad but has a couple of impasses: you can’t make a postprocess where you only “see” foreground actors, and even if you could, then the outline would render “on top” of everything even if it would be partially/fully behind other objects while the object would not render on top of them (might be the intended way but not likely).

Thanks for the info guys. Sounds a bit of a headache…