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:
- add next pass (with shader material) to the object that should have outline
- set this shader in this material
- 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;
}