1#extension GL_OES_EGL_image_external : require 2precision mediump float; 3 4uniform vec3 uResolution; 5uniform samplerExternalOES sTexture; 6uniform float uRadius; 7varying vec2 vTextureCoord; 8 9float computeWeight(float x) { 10 return -((x * x) / (uRadius * uRadius)) + 1.0; 11} 12 13/** 14* This shader sets the colour of each fragment to be the weighted average of the uRadius fragments 15* horizontally adjacent to it to produce a blur effect along the x-axis of the texture 16* 17* The weights come from the following curve: f(x) = 1 - (x^2)/(r^2) 18* where r is the radius of the blur 19*/ 20void main() { 21 vec4 sampledColor = vec4(0.0); 22 vec4 weightedColor = vec4(0.0); 23 24 float divisor = 0.0; 25 float weight = 0.0; 26 27 for (float x = -uRadius; x <= uRadius; x++) 28 { 29 sampledColor = texture2D(sTexture, vTextureCoord + vec2(x / uResolution.x, 0.0)); 30 weight = computeWeight(x); 31 weightedColor += sampledColor * weight; 32 divisor += weight; 33 } 34 35 gl_FragColor = vec4(weightedColor.r / divisor, weightedColor.g / divisor, weightedColor.b / divisor, 1.0); 36} 37