UFO: Alien Invasion
convolve3_fs.glsl
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief convolve3 fragment shader.
4  */
5 
6 #ifndef glsl110
7  /** After glsl1110 this need to be explicitly declared; used by fixed functionality at the end of the OpenGL pipeline.*/
8  out vec4 gl_FragColor;
9 #endif
10 
11 uniform sampler2D SAMPLER0;
12 uniform float COEFFICIENTS[3];
13 uniform vec2 OFFSETS[3];
14 
15 /**
16  * @brief Fragment shader that convolves a 3 element filter with the specified texture.
17  *
18  * Orientation of the filter is controlled by "OFFSETS".
19  * The filter itself is specified by "COEFFICIENTS".
20  */
21 void main(void) {
22  vec2 inColor = gl_TexCoord[0].st;
23  vec4 outColor = vec4(0, 0, 0, 1);
24 
25  outColor += COEFFICIENTS[0] * texture2D(SAMPLER0, inColor + OFFSETS[0]);
26  outColor += COEFFICIENTS[1] * texture2D(SAMPLER0, inColor + OFFSETS[1]);
27  outColor += COEFFICIENTS[2] * texture2D(SAMPLER0, inColor + OFFSETS[2]);
28 
29  gl_FragColor = outColor;
30 }