Project

General

Profile

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

library / src / main / res / raw / post_fragment_shader.glsl @ 4c1dd6e9

1
//////////////////////////////////////////////////////////////////////////////////////////////
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
varying vec2 vTexCoordinate;
21
uniform sampler2D u_Texture;
22
uniform vec2 u_objD;
23
uniform int fNumEffects;                   // total number of postprocessing effects
24

    
25
#if NUM_POSTPROCESS>0
26
uniform int pType[NUM_POSTPROCESS];        // their types.
27
uniform vec4 pUniforms[2*NUM_POSTPROCESS]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1].
28
                                           //
29

    
30
//////////////////////////////////////////////////////////////////////////////////////////////
31
// BLUR EFFECT
32

    
33
void blur(out vec4 color)
34
  {
35
  color = vec4(0.0);
36

    
37
  float blurSizeH = 1.0 / u_objD.x;
38
  float blurSizeV = 1.0 / u_objD.y;
39

    
40
  for (int x = -4; x <= 4; x++)
41
    for (int y = -4; y <= 4; y++)
42
      color += texture( u_Texture, vec2(vTexCoord.x + x * blurSizeH, vTexCoord.y + y * blurSizeV) ) / 81.0;
43
  }
44

    
45
#endif
46

    
47
//////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
void main()
50
  {
51
  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
52

    
53
#if NUM_POSTPROCESS>0
54
  for(int i=0; i<fNumEffects; i++)
55
    {
56
    if( pType[i]==BLUR ) blur(pixel);
57
    }
58
#endif
59

    
60
  gl_FragColor = pixel;
61
  }
(3-3/4)