How to render an outline around 3D objects?

Godot Version

4.2

Question

So I looked at different shaders and posts for how to create an outline around a 3D object in scene, but none of those seem to work well.

What is the go-to method for creating outlines for 3D objects right now? Is there any?

Basically this if for marking 3D object in the scene as interactable when the player gets close to them.

I have been wanting to do this myself and was looking at these shaders . Whats wrong with them Clean pixel perfect outline via material - Godot Shaders

I tried something, have a look here

So they all had different kind of issues, basically they work well in isolation but don’t exactly work well with other objects in the scene. That is why I am wondering if there is a go-to solution.

Ah nice, will have a look and give you feedback.

I was thinking around the lines of rending objects to a viewport and doing the outline in 2D, too. Especially, since I already have a nice 2D outline shader from our previous game.

I’m also looking for the same outline effect. I checked your scene but it doesn’t highlight the box. Do you have any idea why it would be?

I updated the shader to Godot 4.3, does it work now?

1 Like

Yes it does work now, I really appriciate the help, thank you.
Now I’ll check it detailed to figure out how it works :slight_smile:

I checked it a bit, trying to understand.
What I’m trying to do is highlighting only ‘selected objects’ not all objects in the scene. So, I thought playing with VisualInstance layers and camera culling mask layers to match these only for the ‘selected objects’ would make it work. But I couldn’t figure it out.
Do you have a way of doing this?

In my example scene highlighted objects are those with the VisualInstance3D Layer 11. You can change this as you wish by changing the CullMask Layer in the “HighlightCamera3D” node and the VisualInstance3D Layer in the “HighlightEffectDepth” node.

Does this help? If not you have to be more specific what exactly works and what not.

In my scene, I see that all of the boxes are highlighted, regardless of their layers.
I guess your reply also answers my ‘would be next question’:
Why is there a Box and Box2 and BoxHighlighted nodes in different layers and everything is still highlighted? :smiley:

So the question now is why my scene highlights all of the boxes and does not take into account the VisualInstance3D layer of the objects

Extra Note: When I add your scene to my game project that I have been working on, I see everything is highlighted. But when I add your scene to a completely new/blank project, I don’t see any highlight at all, only the white shapes. So it may be related to project settings somehow.

OK I figured it out.

It doesn’t work properly in Mobile rendering, causing weird issues depending on the settings like anti-aliasing . But it works as expected in Forward+ rendering.

1 Like