Project

General

Profile

« Previous | Next » 

Revision d6e94c84

Added by Leszek Koltunski over 7 years ago

progress with Postprocessing.

View differences:

src/main/res/raw/post_fragment_shader.glsl
17 17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18 18
//////////////////////////////////////////////////////////////////////////////////////////////
19 19

  
20
varying vec2 vTexCoordinate;
20
#define NUM_POSTPROCESS 3
21
#define BLUR 0
22

  
23
precision lowp float;
24

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

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

  
30 34
//////////////////////////////////////////////////////////////////////////////////////////////
31 35
// BLUR EFFECT
32 36

  
33
void blur(out vec4 color)
37
void blur(out vec4 pixel)
34 38
  {
35
  color = vec4(0.0);
39
  pixel = vec4(0.0);
36 40

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

  
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;
44
  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
      }
43 49
  }
44 50

  
45 51
#endif
......
51 57
  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
52 58

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

Also available in: Unified diff