2014-05-05 13:27:47 +08:00
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
varying vec4 v_fragmentColor;
|
|
|
|
varying vec2 v_texCoord;
|
|
|
|
|
2014-06-11 14:54:14 +08:00
|
|
|
uniform vec2 resolution;
|
|
|
|
uniform float blurRadius;
|
2014-06-12 09:49:48 +08:00
|
|
|
uniform float sampleNum;
|
2014-06-11 14:54:14 +08:00
|
|
|
|
|
|
|
vec3 blur(vec2);
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
vec3 col = blur(v_texCoord);
|
2014-06-12 09:49:48 +08:00
|
|
|
gl_FragColor = vec4(col, 1.0) * v_fragmentColor;
|
2014-06-11 14:54:14 +08:00
|
|
|
}
|
2014-05-05 13:27:47 +08:00
|
|
|
|
2014-06-11 14:54:14 +08:00
|
|
|
vec3 blur(vec2 p)
|
|
|
|
{
|
2014-06-12 09:49:48 +08:00
|
|
|
if (blurRadius > 0.0 && sampleNum > 1.0)
|
2014-06-11 14:54:14 +08:00
|
|
|
{
|
|
|
|
vec3 col = vec3(0);
|
|
|
|
vec2 unit = 1.0 / resolution.xy;
|
|
|
|
|
|
|
|
float r = blurRadius;
|
2014-06-12 09:49:48 +08:00
|
|
|
float sampleStep = r / sampleNum;
|
2014-06-11 14:54:14 +08:00
|
|
|
|
|
|
|
float count = 0.0;
|
|
|
|
|
|
|
|
for(float x = -r; x < r; x += sampleStep)
|
|
|
|
{
|
|
|
|
for(float y = -r; y < r; y += sampleStep)
|
|
|
|
{
|
|
|
|
float weight = (r - abs(x)) * (r - abs(y));
|
|
|
|
col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight;
|
|
|
|
count += weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return col / count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture2D(CC_Texture0, p).rgb;
|
2014-05-05 13:27:47 +08:00
|
|
|
}
|