axmol/tests/cpp-tests/Content/Shaders/example_Bloom.fsh

54 lines
2.3 KiB
Plaintext
Raw Normal View History

2015-05-26 17:21:35 +08:00
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform vec2 resolution;
2022-07-04 21:26:48 +08:00
uniform sampler2D u_tex0;
2015-05-26 17:21:35 +08:00
const float blurSize = 1.0/512.0;
const float intensity = 0.35;
void main()
{
vec4 sum = vec4(0);
vec2 texcoord = v_texCoord.xy;
int j;
int i;
//thank you! http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/ for the
//blur tutorial
// blur in y (vertical)
// take nine samples, with the distance blurSize between them
2022-07-04 21:26:48 +08:00
sum += texture2D(u_tex0, vec2(texcoord.x - 4.0*blurSize, texcoord.y)) * 0.05;
sum += texture2D(u_tex0, vec2(texcoord.x - 3.0*blurSize, texcoord.y)) * 0.09;
sum += texture2D(u_tex0, vec2(texcoord.x - 2.0*blurSize, texcoord.y)) * 0.12;
sum += texture2D(u_tex0, vec2(texcoord.x - blurSize, texcoord.y)) * 0.15;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y)) * 0.16;
sum += texture2D(u_tex0, vec2(texcoord.x + blurSize, texcoord.y)) * 0.15;
sum += texture2D(u_tex0, vec2(texcoord.x + 2.0*blurSize, texcoord.y)) * 0.12;
sum += texture2D(u_tex0, vec2(texcoord.x + 3.0*blurSize, texcoord.y)) * 0.09;
sum += texture2D(u_tex0, vec2(texcoord.x + 4.0*blurSize, texcoord.y)) * 0.05;
2015-05-26 17:21:35 +08:00
// blur in y (vertical)
// take nine samples, with the distance blurSize between them
2022-07-04 21:26:48 +08:00
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y - 4.0*blurSize)) * 0.05;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y - 3.0*blurSize)) * 0.09;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y - 2.0*blurSize)) * 0.12;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y - blurSize)) * 0.15;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y)) * 0.16;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y + blurSize)) * 0.15;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y + 2.0*blurSize)) * 0.12;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y + 3.0*blurSize)) * 0.09;
sum += texture2D(u_tex0, vec2(texcoord.x, texcoord.y + 4.0*blurSize)) * 0.05;
2015-05-26 17:21:35 +08:00
//increase blur with intensity!
2022-07-04 21:26:48 +08:00
gl_FragColor = sum*intensity + texture2D(u_tex0, texcoord);
2015-05-26 17:21:35 +08:00
return;
/*if(sin(iGlobalTime) > 0.0)
gl_FragColor = sum * sin(iGlobalTime)+ texture2D(iChannel0, texcoord);
else
gl_FragColor = sum * -sin(iGlobalTime)+ texture2D(iChannel0, texcoord);
*/
}