Skip to content

Instantly share code, notes, and snippets.

@jimmyjonezz
Created November 23, 2020 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyjonezz/8485dfbccce6e94eaf0d5e7ab2dea20d to your computer and use it in GitHub Desktop.
Save jimmyjonezz/8485dfbccce6e94eaf0d5e7ab2dea20d to your computer and use it in GitHub Desktop.
Glowing
shader_type canvas_item;
uniform float amount : hint_range(0,0.5);
vec4 sample_glow_pixel(sampler2D tex, vec2 uv) {
float hdr_threshold = amount;
return max(textureLod(tex, uv, 2.0) - hdr_threshold, vec4(0.0));
}
void fragment() {
vec2 ps = SCREEN_PIXEL_SIZE;
// Get blurred color from pixels considered glowing
vec4 col0 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(-ps.x, 0));
vec4 col1 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(ps.x, 0));
vec4 col2 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(0, -ps.y));
vec4 col3 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(0, ps.y));
vec4 col = texture(SCREEN_TEXTURE, SCREEN_UV);
vec4 glowing_col = 0.25 * (col0 + col1 + col2 + col3);
COLOR = vec4(col.rgb + glowing_col.rgb, col.a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment