Project

General

Profile

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

library / src / main / res / raw / blur2_fragment_shader.glsl @ fd2db957

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 f1d5ea12 Leszek Koltunski
// You should have received a copy of the GNU General Public License                        //
17 4c1dd6e9 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18
//////////////////////////////////////////////////////////////////////////////////////////////
19
20 2e7ad49f Leszek Koltunski
precision lowp float;
21
22 94f6d472 Leszek Koltunski
#if __VERSION__ != 100
23 f2367b75 Leszek Koltunski
in vec2 v_TexCoordinate;
24
out vec4 fragColor;
25 1cbf4103 leszek
#define TEXTURE texture
26
#define FRAG_COLOR fragColor
27 94f6d472 Leszek Koltunski
#else
28
varying vec2 v_TexCoordinate;
29 1cbf4103 leszek
#define TEXTURE texture2D
30
#define FRAG_COLOR gl_FragColor
31 94f6d472 Leszek Koltunski
#endif
32
33 f2367b75 Leszek Koltunski
uniform sampler2D u_ColorTexture;
34
uniform sampler2D u_DepthTexture;
35 5ccafcca Leszek Koltunski
uniform float u_Offsets[MAX_BLUR];
36 0d81d0fb Leszek Koltunski
uniform float u_Weights[MAX_BLUR];
37
uniform int u_Radius;
38 4c1dd6e9 Leszek Koltunski
39
//////////////////////////////////////////////////////////////////////////////////////////////
40
41
void main()
42
  {
43 fd2db957 Leszek Koltunski
  float depth = TEXTURE(u_DepthTexture,v_TexCoordinate).r;
44
45
  if( u_Radius>1 )
46
    {
47
    float offset = u_Offsets[u_Radius];
48
49
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y+offset)).r);
50
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y-offset)).r);
51
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x+offset,v_TexCoordinate.y)).r);
52
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x-offset,v_TexCoordinate.y)).r);
53
    }
54
55
  gl_FragDepth = depth;
56 f2367b75 Leszek Koltunski
57 94f6d472 Leszek Koltunski
  vec4 pixel= TEXTURE(u_ColorTexture,v_TexCoordinate) * u_Weights[0];
58 0d81d0fb Leszek Koltunski
59 9d5bb851 Leszek Koltunski
  for (int i=1; i<=u_Radius; i+=1)
60 0d81d0fb Leszek Koltunski
    {
61 ed5bf324 Leszek Koltunski
    pixel += ( TEXTURE(u_ColorTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y+u_Offsets[i])) +
62
               TEXTURE(u_ColorTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y-u_Offsets[i])) ) * u_Weights[i];
63 0d81d0fb Leszek Koltunski
    }
64 f1d5ea12 Leszek Koltunski
65 1cbf4103 leszek
  FRAG_COLOR = pixel;
66 4c1dd6e9 Leszek Koltunski
  }