The simplest outline shader (via material)

Very simple outline shader, but I think it’s useful.

It create outline by drawing scaled up object with inverted backface culling, so:

  • requires correct setting of normal vectors
  • breaks transparency obtained by backface culling (alpha-based transparency works ok)

  • works OK with background objects
  • outline is drawed around object (oustide, not on the object)

How to use:

  1. add next pass (with shader material) to the object that should have outline
  2. set this shader in this material
  3. adjust parameters (outline color and size, note: size is depending on object size – it’s scale factor)

Tested in Godot 4.3 with Forward+ (Vulkan) rendering. Inspirited by this video.

Shader code
shader_type spatial;
render_mode blend_mix, cull_front, unshaded;

uniform vec4 color : source_color = vec4(1,0,0,1);
uniform float size : hint_range(1.0, 1.5, 0.01) = 1.05;

void vertex() {
	VERTEX *= size;
}

void fragment() {
	ALBEDO = color.rgb;
	ALPHA = color.a;
}
Tags
outline
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Clean pixel perfect outline via material

3D Pixelation via material

Custom Phong shader written via Nodes

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments