1uniform sampler2D m_Texture; 2uniform float m_SampleDist; 3uniform float m_SampleStrength; 4uniform float m_Samples[10]; 5varying vec2 texCoord; 6 7void main(void) 8{ 9 // some sample positions 10 //float samples[10] = float[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08); 11 12 // 0.5,0.5 is the center of the screen 13 // so substracting texCoord from it will result in 14 // a vector pointing to the middle of the screen 15 vec2 dir = 0.5 - texCoord; 16 17 // calculate the distance to the center of the screen 18 float dist = sqrt(dir.x*dir.x + dir.y*dir.y); 19 20 // normalize the direction (reuse the distance) 21 dir = dir/dist; 22 23 // this is the original colour of this fragment 24 // using only this would result in a nonblurred version 25 vec4 colorRes = texture2D(m_Texture,texCoord); 26 27 vec4 sum = colorRes; 28 29 // take 10 additional blur samples in the direction towards 30 // the center of the screen 31 for (int i = 0; i < 10; i++) 32 { 33 sum += texture2D( m_Texture, texCoord + dir * m_Samples[i] * m_SampleDist ); 34 } 35 36 // we have taken eleven samples 37 sum *= 1.0/11.0; 38 39 // weighten the blur effect with the distance to the 40 // center of the screen ( further out is blurred more) 41 float t = dist * m_SampleStrength; 42 t = clamp( t ,0.0,1.0); //0 <= t <= 1 43 44 //Blend the original color with the averaged pixels 45 gl_FragColor =mix( colorRes, sum, t ); 46 47}