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;
}
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:
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.
try to mess around with these new params.
and it is best to scale up the canvas item size or the light fall-off will be hard clipped.
or use vertex
void vertex() {
VERTEX += (VERTEX – //texture_size//) * //scale//;
}
but this will mess up the culling, causing the item to disappear immediately when the smaller (than the actual drawing) culling rect is offscreen.
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;
}
}