1 |
4c1dd6e9
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
d6e94c84
|
Leszek Koltunski
|
precision lowp float;
|
21 |
|
|
|
22 |
|
|
varying vec2 v_TexCoordinate;
|
23 |
4c1dd6e9
|
Leszek Koltunski
|
uniform sampler2D u_Texture;
|
24 |
|
|
uniform vec2 u_objD;
|
25 |
667a1ad9
|
Leszek Koltunski
|
uniform int pNumEffects; // total number of postprocessing effects
|
26 |
4c1dd6e9
|
Leszek Koltunski
|
|
27 |
|
|
#if NUM_POSTPROCESS>0
|
28 |
667a1ad9
|
Leszek Koltunski
|
uniform int pType[NUM_POSTPROCESS]; // their types.
|
29 |
|
|
uniform vec4 pUniforms[NUM_POSTPROCESS]; // i-th effect is 1 vec4: [i].
|
30 |
4c1dd6e9
|
Leszek Koltunski
|
|
31 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
|
|
// BLUR EFFECT
|
33 |
|
|
|
34 |
667a1ad9
|
Leszek Koltunski
|
void blur(out vec4 pixel,float radius)
|
35 |
4c1dd6e9
|
Leszek Koltunski
|
{
|
36 |
d6e94c84
|
Leszek Koltunski
|
pixel = vec4(0.0);
|
37 |
4c1dd6e9
|
Leszek Koltunski
|
|
38 |
|
|
float blurSizeH = 1.0 / u_objD.x;
|
39 |
|
|
float blurSizeV = 1.0 / u_objD.y;
|
40 |
667a1ad9
|
Leszek Koltunski
|
float denom = 1.0 / ((2.0*radius+1.0)*(2.0*radius+1.0));
|
41 |
4c1dd6e9
|
Leszek Koltunski
|
|
42 |
667a1ad9
|
Leszek Koltunski
|
for (float x = -radius; x <= radius; x+=1.0)
|
43 |
|
|
for (float y = -radius; y <= radius; y+=1.0)
|
44 |
d6e94c84
|
Leszek Koltunski
|
{
|
45 |
667a1ad9
|
Leszek Koltunski
|
pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x*blurSizeH, v_TexCoordinate.y + y*blurSizeV) ) *denom;
|
46 |
d6e94c84
|
Leszek Koltunski
|
}
|
47 |
4c1dd6e9
|
Leszek Koltunski
|
}
|
48 |
|
|
|
49 |
|
|
#endif
|
50 |
|
|
|
51 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
52 |
|
|
|
53 |
|
|
void main()
|
54 |
|
|
{
|
55 |
|
|
vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
|
56 |
|
|
|
57 |
|
|
#if NUM_POSTPROCESS>0
|
58 |
d6e94c84
|
Leszek Koltunski
|
for(int i=0; i<pNumEffects; i++)
|
59 |
4c1dd6e9
|
Leszek Koltunski
|
{
|
60 |
667a1ad9
|
Leszek Koltunski
|
if( pType[i]==BLUR ) blur(pixel,pUniforms[i].x);
|
61 |
4c1dd6e9
|
Leszek Koltunski
|
}
|
62 |
|
|
#endif
|
63 |
|
|
|
64 |
|
|
gl_FragColor = pixel;
|
65 |
|
|
}
|