Blame view

res/shaders/gaussian.frag 2.3 KB
9f1cb386   dangge   auto package
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  uniform float u_resolution;
  uniform float u_radius;
  uniform vec2 u_direction;
  
  varying vec4 v_fragmentColor;
  varying vec2 v_texCoord;
  
  void main() {
  	//this will be our RGBA sum
  	vec4 sum = vec4(0.0);
  	
  	//our original texcoord for this fragment
  	vec2 tc = v_texCoord;
  	
  	//the amount to blur, i.e. how far off center to sample from 
  	//1.0 -> blur by one pixel
  	//2.0 -> blur by two pixels, etc.
  	float blur = u_radius/u_resolution;
      
      //the u_direction of our blur
      //(1.0, 0.0) -> x-axis blur
      //(0.0, 1.0) -> y-axis blur
  	float hstep = u_direction.x;
  	float vstep = u_direction.y;
  	
      //apply blurring, using a 15-tap filter with predefined gaussian weights
  	sum += texture2D(CC_Texture0, vec2(tc.x - 7.0*blur*hstep, tc.y - 7.0*blur*vstep)) * 0.0044299121055113265;
      sum += texture2D(CC_Texture0, vec2(tc.x - 6.0*blur*hstep, tc.y - 6.0*blur*vstep)) * 0.00895781211794;
      sum += texture2D(CC_Texture0, vec2(tc.x - 5.0*blur*hstep, tc.y - 5.0*blur*vstep)) * 0.0215963866053;
      sum += texture2D(CC_Texture0, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0443683338718;
      sum += texture2D(CC_Texture0, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0776744219933;
      sum += texture2D(CC_Texture0, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.115876621105;
      sum += texture2D(CC_Texture0, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.147308056121;
      sum += texture2D(CC_Texture0, vec2(tc.x, tc.y)) * 0.159576912161;
      sum += texture2D(CC_Texture0, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.147308056121;
      sum += texture2D(CC_Texture0, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.115876621105;
      sum += texture2D(CC_Texture0, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0776744219933;
      sum += texture2D(CC_Texture0, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0443683338718;
      sum += texture2D(CC_Texture0, vec2(tc.x + 5.0*blur*hstep, tc.y + 5.0*blur*vstep)) * 0.0215963866053;
      sum += texture2D(CC_Texture0, vec2(tc.x + 6.0*blur*hstep, tc.y + 6.0*blur*vstep)) * 0.00895781211794;
      sum += texture2D(CC_Texture0, vec2(tc.x + 7.0*blur*hstep, tc.y + 7.0*blur*vstep)) * 0.0044299121055113265;
  
  	//discard alpha for our simple demo, multiply by vertex color and return
  	gl_FragColor = v_fragmentColor * vec4(sum.rgb, 1.0);
  }