2D Rim Light

Rim Light – Activates a border on your 2D sprite that reacts brightly to light. This border is based off of the outline shader code from GDQuest.

Rim Thickness – Changes the line thickness.

Rim Intense – Increase or decrease the brightness or intensity.

Rim Extra Thick – Adds another pass that thickens the border.

Shader code
shader_type canvas_item;

uniform bool rim_light = false;
uniform float rim_thickness : hint_range(0, 40) = 5.0;
uniform float rim_intense : hint_range(0, 1) = 1.0;
uniform bool rim_extra_thick = false;

void light() {
	if (rim_light) {
		vec2 size = TEXTURE_PIXEL_SIZE * rim_thickness;
		float outline = texture(TEXTURE, UV + vec2(-size.x, 0)).a;
		outline *= texture(TEXTURE, UV + vec2(0, size.y)).a;
		outline *= texture(TEXTURE, UV + vec2(size.x, 0)).a;
		outline *= texture(TEXTURE, UV + vec2(0, -size.y)).a;
		if (rim_extra_thick) {
			outline *= texture(TEXTURE, UV + vec2(-size.x, size.y)).a;
			outline *= texture(TEXTURE, UV + vec2(size.x, size.y)).a;
			outline *= texture(TEXTURE, UV + vec2(-size.x, -size.y)).a;
			outline *= texture(TEXTURE, UV + vec2(size.x, -size.y)).a;
		}
		outline = 1.0 - outline;

		vec4 color = texture(TEXTURE, UV);
		float rim_cap = outline * color.a * rim_intense;
		LIGHT += rim_cap;
	}
}
Tags
light, light2d, sprite
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.

More from MightyMochiGames

Modulate Before Light

2D Light Z-Depth

2D Cel / Toon Shader v2 (Basic)

Related shaders

2D Rim Light

UCBC’s Stylized Light with Light Masking

2D Light Z-Depth

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Naldo
Naldo
2 months ago

It doesnt react to lights direction :/