/// ============================================================================ /* Copyright (C) 2005 Robert Beckebans Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /// ============================================================================ uniform float u_BlurMagnitude; uniform sampler2D u_ColorMap; uniform sampler2D u_ContrastMap; uniform vec2 u_FBufScale; uniform vec2 u_NPotScale; #define KERNEL_SIZE 9 float kernel[KERNEL_SIZE]; vec2 offset[KERNEL_SIZE]; const float step_w = 1.0/512.0; const float step_h = 1.0/512.0; void main(void) { vec4 sum = vec4(0.0); vec2 st00 = gl_FragCoord.st; // calculate the screen texcoord in the 0.0 to 1.0 range st00 *= u_FBufScale; // scale by the screen non-power-of-two-adjust st00 *= u_NPotScale; // base color vec4 base = texture2D(u_ColorMap, st00); offset[0] = vec2(-step_w, -step_h); offset[1] = vec2(0.0, -step_h); offset[2] = vec2(step_w, -step_h); offset[3] = vec2(-step_w, 0.0); offset[4] = vec2(0.0, 0.0); offset[5] = vec2(step_w, 0.0); offset[6] = vec2(-step_w, step_h); offset[7] = vec2(0.0, step_h); offset[8] = vec2(step_w, step_h); kernel[0] = 1.0/16.0; kernel[1] = 2.0/16.0; kernel[2] = 1.0/16.0; kernel[3] = 2.0/16.0; kernel[4] = 4.0/16.0; kernel[5] = 2.0/16.0; kernel[6] = 1.0/16.0; kernel[7] = 2.0/16.0; kernel[8] = 1.0/16.0; // do blur vec4 tmp = texture2D(u_ContrastMap, st00 + offset[0]); sum += tmp * kernel[0]; tmp = texture2D(u_ContrastMap, st00 + offset[1]); sum += tmp * kernel[1]; tmp = texture2D(u_ContrastMap, st00 + offset[2]); sum += tmp * kernel[2]; tmp = texture2D(u_ContrastMap, st00 + offset[3]); sum += tmp * kernel[3]; tmp = texture2D(u_ContrastMap, st00 + offset[4]); sum += tmp * kernel[4]; tmp = texture2D(u_ContrastMap, st00 + offset[5]); sum += tmp * kernel[5]; tmp = texture2D(u_ContrastMap, st00 + offset[6]); sum += tmp * kernel[6]; tmp = texture2D(u_ContrastMap, st00 + offset[7]); sum += tmp * kernel[7]; tmp = texture2D(u_ContrastMap, st00 + offset[8]); sum += tmp * kernel[8]; sum *= u_BlurMagnitude; gl_FragColor = base + sum; }