• Godot HelpShaders
  • High-Quality Object Outline Shader with outline width staying unchanged by camera distance?

For my current game I need an outline shader with these requirements:

  1. The outline should stay the same thickness reguardless of camera distance and viewing angle.
  2. The outline width should be configurable to more than just 1 pixel
  3. The outline should Only be outside the mesh. There should Not be outlines inside the mesh.

Hint: The example image does not accurately represent 3D rendering in Godot (or in general) since I made it in Inkscape. It was the best way I knew of to quickly give an idea about the effect I want.

---

One possible solution to this challenge could be to:

  1. Render the 3D object into a framebuffer.
  2. Apply the 2D outline shader from the 2D shaders demo (View here, desired shader is on the 2nd Godette in the 1st row)
  3. Render the result onto the screen.

I'm not suggesting that this is the only or even the best solution to the problem. It's just the only one that came to mind because of my relative inexperience with shaders.

You can use the grow option to get an okay outline.

This is the reverse hull method, which I honestly think looks dated, but it's an easy solution built-in.

You can also look into Sobel filters. This looks more like what they did in Borderlands, but it's a fullscreen shader meaning you lose some control over the outline (it's applied to everything). https://docs.godotengine.org/en/stable/tutorials/viewports/custom_postprocessing.html

I used the Post-Processing Shader to make a Full-Screen Black-White Outline Filter.

Thanks very much for pointing to the Post-Processing guide. And for the makers of the Post-Processing guide. And the makers of Godot Engine itself. It's very easy to use. The final effect looks awesome. Almost like a Vector Display, but it might actually be better because the inaccuracies compared to a real vector display make for more interesting visuals, especially in motion.

You can't see the effect in motion because recording video is way too inconvenient for just a 5 second-clip in a forum comment, but I might put the source code on GitHub if I get enough demand.

4 months later

Hi Sosasees, would you share the code of your shader? I could also need it. Have a nice day! Thanks, Frank

I'll have to see if I have the shader project backed up on my archive drive.

To get the shader working as I wanted, I had to go through some really specific workarounds that would be very difficult to adapt to other projects (like disabling all light and shadow effects, and coloring specific objects in specific colors). And even then, this only gives an outline to the silhouette of the object and it overwrites everything that isn't the outlines to black, which makes for the visuals I wanted but I don't know if this is what You would want.

Because it was literally one of the first shaders I made, it's so unwieldy and specific that there's a 99% chance that writing your own specific shader is a much better choice (and I haven't gotten any better at shaders ever since because I changed my game dev plans and have no reasons to use shaders right now)

12 days later

I found the original project and attached it to this comment (in the exact state that it was back then). I made it on 2021 07 08 (date in YYYY MM DD format).

a year later