glowing rect 2d

use it with colorrect or sprite2d …

should scale up the node2d applied to, or it will clip the light

if you don’t want glow for 2d

Shader code
shader_type canvas_item;
render_mode blend_add;
uniform vec2 rect_size = vec2(.1, .1);
uniform float bness = 1.0;
uniform float fall_off_scale = 3.0;
uniform float b_offset = 0.0; 
void fragment() {
	vec2 uv = UV - vec2(.5);
	vec2 cloest_rect_point; 
	cloest_rect_point = uv; 
	cloest_rect_point.x = clamp(uv.x, -rect_size.x, rect_size.x);  
	cloest_rect_point.y = clamp(uv.y, -rect_size.y, rect_size.y);   
	vec2 cuv = uv - cloest_rect_point;
	float d2c = length(cuv);
	COLOR.a = - log(d2c*fall_off_scale + b_offset) * bness; 
} 
 
Tags
glow, light
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 Grandpa_Pit

Weird tube with balls

electric ball canvas item

canvas cube glowing and stuff

Related shaders

canvas cube glowing and stuff

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
eliacanavera
eliacanavera
3 months ago

Hi! I’m trying to use this beauty for my white circular sprite2Ds,
and the glow effect works great for me if edited like this:

shader_type canvas_item;
render_mode blend_add;
uniform float bness = 1.0;

void fragment() {
	float d2c = length(UV - vec2(0.5));
	COLOR.a = -log(d2c * 3.0) * bness;
}

But this scales down the sprite to about half of its original size, any way to keep the same starting size? (without having to change scale property of the sprite outside the shader code). I tried playing with the bness parameter, but no success.

eliacanavera
eliacanavera
3 months ago
Reply to  Grandpa_Pit

THANKS! This is my wonderful result:
shader_type canvas_item;

uniform float bness = 1.0;
uniform float fall = 3.0;
uniform float scale = 2.5;
uniform float onoff = 0;

void fragment() {
float d2c = length(UV – vec2(0.5));
float glow = – log(d2c * fall) * bness;
COLOR.a = mix(COLOR.a, glow, onoff);
}

void vertex() {
if (onoff == 1.0) {
VERTEX += VERTEX * scale;
}
}

Last edited 3 months ago by eliacanavera