Texture-Clipped Pulse Glow

From: https://godotshaders.com/shader/item-pulse-glow/#comment-4039

Shader code
shader_type canvas_item;
render_mode blend_add; // This makes it ‘glow’ against the world

uniform vec4 glow_color : source_color = vec4(1.0, 0.9, 0.5, 1.0);
uniform float intensity : hint_range(0.0, 5.0) = 1.5;
uniform float spread : hint_range(0.1, 2.0) = 1.0;
uniform float pulse_speed : hint_range(0.0, 10.0) = 1.0;

void fragment() {
  // 1. Get the shape of your sprite
  float sprite_shape = texture(TEXTURE, UV).a;
   
  // 2. Your original circle logic
  vec2 centered_uv = UV - vec2(0.5);
  float dist = length(centered_uv) * spread;
  float alpha = max(0.0, 1.0 - dist);
   
  // 3. Your original pulse logic
  alpha *= (1.0 + 0.2 * sin(TIME * pulse_speed));
  alpha = clamp(alpha * intensity, 0.0, 1.0);
   
  // 4. THE FIX: Multiply by sprite_shape so the glow stays 
  // within the bounds of the sprite (prevents a giant square box)
  COLOR = glow_color * alpha * sprite_shape;
}
Live Preview
Tags
glow
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

guest

0 Comments
Oldest
Newest Most Voted