Project

General

Profile

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

library / src / main / res / raw / post_fragment_shader.glsl @ 47d838ca

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[2*NUM_POSTPROCESS]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1].
30

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

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

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

    
41
  for (float x = -4.0; x <= 4.0; x+=1.0)
42
    for (float y = -4.0; y <= 4.0; y+=1.0)
43
      {
44
      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x * blurSizeH, v_TexCoordinate.y + y * blurSizeV) ) / 81.0;
45
      }
46
  }
47

    
48
#endif
49

    
50
//////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
void main()
53
  {
54
  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
55

    
56
#if NUM_POSTPROCESS>0
57
  for(int i=0; i<pNumEffects; i++)
58
    {
59
    if( pType[i]==BLUR ) blur(pixel);
60
    }
61
#endif
62

    
63
  gl_FragColor = pixel;
64
  }
(3-3/4)