Project

General

Profile

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

library / src / main / res / raw / post_fragment_shader.glsl @ 667a1ad9

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
precision lowp float;
21

    
22
varying vec2 v_TexCoordinate;
23
uniform sampler2D u_Texture;
24
uniform vec2 u_objD;
25
uniform int pNumEffects;                 // total number of postprocessing effects
26

    
27
#if NUM_POSTPROCESS>0
28
uniform int pType[NUM_POSTPROCESS];      // their types.
29
uniform vec4 pUniforms[NUM_POSTPROCESS]; // i-th effect is 1 vec4: [i].
30

    
31
//////////////////////////////////////////////////////////////////////////////////////////////
32
// BLUR EFFECT
33

    
34
void blur(out vec4 pixel,float radius)
35
  {
36
  pixel = vec4(0.0);
37

    
38
  float blurSizeH = 1.0 / u_objD.x;
39
  float blurSizeV = 1.0 / u_objD.y;
40
  float denom     = 1.0 / ((2.0*radius+1.0)*(2.0*radius+1.0));
41

    
42
  for (float x = -radius; x <= radius; x+=1.0)
43
    for (float y = -radius; y <= radius; y+=1.0)
44
      {
45
      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x*blurSizeH, v_TexCoordinate.y + y*blurSizeV) ) *denom;
46
      }
47
  }
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
  for(int i=0; i<pNumEffects; i++)
59
    {
60
    if( pType[i]==BLUR ) blur(pixel,pUniforms[i].x);
61
    }
62
#endif
63

    
64
  gl_FragColor = pixel;
65
  }
(3-3/6)