Skip to content

Instantly share code, notes, and snippets.

@Volcanoscar
Forked from LRitesh/gaussianBloom.frag
Created January 19, 2017 08:47
Show Gist options
  • Save Volcanoscar/1ac6a63a359a291eada1329661550573 to your computer and use it in GitHub Desktop.
Save Volcanoscar/1ac6a63a359a291eada1329661550573 to your computer and use it in GitHub Desktop.
Gaussian Bloom
uniform sampler2D renderedTexture;
uniform bool bloom;
uniform float bloomIntensity;
uniform float windowWidth;
uniform float windowHeight;
varying vec4 texCoord;
void main()
{
vec4 sum = vec4(0);
if( bloom ) {
vec4 source = texture2D(renderedTexture, vec2(texCoord.x, texCoord.y));
float xBlurSize = 1.0 / windowWidth;
sum += texture2D(renderedTexture, vec2(texCoord.x - 4.0*xBlurSize, texCoord.y)) * 0.05;
sum += texture2D(renderedTexture, vec2(texCoord.x - 3.0*xBlurSize, texCoord.y)) * 0.09;
sum += texture2D(renderedTexture, vec2(texCoord.x - 2.0*xBlurSize, texCoord.y)) * 0.12;
sum += texture2D(renderedTexture, vec2(texCoord.x - xBlurSize, texCoord.y)) * 0.15;
sum += source * 0.16;
sum += texture2D(renderedTexture, vec2(texCoord.x + xBlurSize, texCoord.y)) * 0.15;
sum += texture2D(renderedTexture, vec2(texCoord.x + 2.0*xBlurSize, texCoord.y)) * 0.12;
sum += texture2D(renderedTexture, vec2(texCoord.x + 3.0*xBlurSize, texCoord.y)) * 0.09;
sum += texture2D(renderedTexture, vec2(texCoord.x + 4.0*xBlurSize, texCoord.y)) * 0.05;
// blur in y (vertical)
// take nine samples, with the distance blurSize between them
float yBlurSize = 1.0 / windowHeight;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y - 4.0*yBlurSize)) * 0.05;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y - 3.0*yBlurSize)) * 0.09;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y - 2.0*yBlurSize)) * 0.12;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y - yBlurSize)) * 0.15;
sum += source * 0.16;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y + yBlurSize)) * 0.15;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y + 2.0*yBlurSize)) * 0.12;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y + 3.0*yBlurSize)) * 0.09;
sum += texture2D(renderedTexture, vec2(texCoord.x, texCoord.y + 4.0*yBlurSize)) * 0.05;
}
gl_FragColor = sum * bloomIntensity + texture2D(renderedTexture, texCoord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment