Skip to content

Instantly share code, notes, and snippets.

@mebens
Created December 5, 2012 19:36
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mebens/4218802 to your computer and use it in GitHub Desktop.
Save mebens/4218802 to your computer and use it in GitHub Desktop.
Simple glow/bloom GLSL shader for Love2D
// adapted from http://www.youtube.com/watch?v=qNM0k522R7o
extern vec2 size;
extern int samples = 5; // pixels per axis; higher = bigger glow, worse performance
extern float quality = 2.5; // lower = smaller glow, better quality
vec4 effect(vec4 colour, Image tex, vec2 tc, vec2 sc)
{
vec4 source = Texel(tex, tc);
vec4 sum = vec4(0);
int diff = (samples - 1) / 2;
vec2 sizeFactor = vec2(1) / size * quality;
for (int x = -diff; x <= diff; x++)
{
for (int y = -diff; y <= diff; y++)
{
vec2 offset = vec2(x, y) * sizeFactor;
sum += Texel(tex, tc + offset);
}
}
return ((sum / (samples * samples)) + source) * colour;
}
@gamepopper
Copy link

What does size represent?

@AxisAngles
Copy link

Probably the canvas or window size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment