Project

General

Profile

Download (2.83 KB) Statistics
| Branch: | Revision:

library / src / main / res / raw / post_fragment_shader.glsl @ d6e94c84

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
#define NUM_POSTPROCESS 3
21
#define BLUR 0
22
23
precision lowp float;
24
25
varying vec2 v_TexCoordinate;
26 4c1dd6e9 Leszek Koltunski
uniform sampler2D u_Texture;
27
uniform vec2 u_objD;
28 d6e94c84 Leszek Koltunski
uniform int pNumEffects;                   // total number of postprocessing effects
29 4c1dd6e9 Leszek Koltunski
30
#if NUM_POSTPROCESS>0
31
uniform int pType[NUM_POSTPROCESS];        // their types.
32
uniform vec4 pUniforms[2*NUM_POSTPROCESS]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1].
33
34
//////////////////////////////////////////////////////////////////////////////////////////////
35
// BLUR EFFECT
36
37 d6e94c84 Leszek Koltunski
void blur(out vec4 pixel)
38 4c1dd6e9 Leszek Koltunski
  {
39 d6e94c84 Leszek Koltunski
  pixel = vec4(0.0);
40 4c1dd6e9 Leszek Koltunski
41
  float blurSizeH = 1.0 / u_objD.x;
42
  float blurSizeV = 1.0 / u_objD.y;
43
44 d6e94c84 Leszek Koltunski
  for (float x = -4.0; x <= 4.0; x+=1.0)
45
    for (float y = -4.0; y <= 4.0; y+=1.0)
46
      {
47
      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x * blurSizeH, v_TexCoordinate.y + y * blurSizeV) ) / 81.0;
48
      }
49 4c1dd6e9 Leszek Koltunski
  }
50
51
#endif
52
53
//////////////////////////////////////////////////////////////////////////////////////////////
54
55
void main()
56
  {
57
  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
58
59
#if NUM_POSTPROCESS>0
60 d6e94c84 Leszek Koltunski
  for(int i=0; i<pNumEffects; i++)
61 4c1dd6e9 Leszek Koltunski
    {
62
    if( pType[i]==BLUR ) blur(pixel);
63
    }
64
#endif
65
66
  gl_FragColor = pixel;
67
  }