Simple Highlight Effect

Uses an SDF provided by a LightOccluder2D object to create a highlight effect

Shader code
shader_type canvas_item;
render_mode world_vertex_coords;

uniform float outline_width;
uniform vec2 lower_limit;
uniform vec2 upper_limit;

uniform vec4 color : source_color;

void vertex() {
	vec2 disp;
	
	// resizes the 
	switch (VERTEX_ID)
	{
		case 0:
			disp = vec2(lower_limit.x, lower_limit.y);
			break;
		case 1:
			disp = vec2(lower_limit.x, upper_limit.y);
			break;
		case 2:
			disp = vec2(upper_limit.x, upper_limit.y);
			break;
		case 3:
			disp = vec2(upper_limit.x, lower_limit.y);
			break;
	}
	
	VERTEX = disp;
}

void fragment() {
	float alpha;
	
	// use sdf to calculate the alpha of the highlight
	alpha = 1.0 - texture_sdf(screen_uv_to_sdf(SCREEN_UV)) / float(outline_width);
	COLOR = color;
	COLOR.a = alpha;
}
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

Simple 2D Highlight

2D Highlight Effect

Simple Transition Effect

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments