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