R2 Shaders
R2BoxBlur.h
Go to the documentation of this file.
1 #ifndef R2_BOX_BLUR_H
2 #define R2_BOX_BLUR_H
3 
4 /// \file R2BoxBlur.h
5 /// \brief Functions for performing box blurs.
6 
7 const float R2_boxBlurGaussWeight2 = 0.0702702703;
8 const float R2_boxBlurGaussOffset2 = 3.2307692308;
9 const float R2_boxBlurGaussWeight1 = 0.3162162162;
10 const float R2_boxBlurGaussOffset1 = 1.3846153846;
11 const float R2_boxBlurGaussWeight0 = 0.2270270270;
12 
13 ///
14 /// Perform a single vertical blur sample for texel \a uv in \a t.
15 ///
16 /// @param t A texture
17 /// @param uv The coordinates of the current texel
18 /// @param size The blur size
19 ///
20 
21 vec4
23  const sampler2D t,
24  const vec2 uv,
25  const float size)
26 {
27  float size_inv = 1.0 / size;
28  float y;
29  vec2 c;
30 
31  vec4 sum = textureLod (t, uv, 0.0) * R2_boxBlurGaussWeight0;
32 
33  y = uv.y + (size_inv * R2_boxBlurGaussOffset1);
34  c = vec2 (uv.x, y);
35  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight1;
36 
37  y = uv.y + (size_inv * R2_boxBlurGaussOffset2);
38  c = vec2 (uv.x, y);
39  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight2;
40 
41  y = uv.y - (size_inv * R2_boxBlurGaussOffset1);
42  c = vec2 (uv.x, y);
43  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight1;
44 
45  y = uv.y - (size_inv * R2_boxBlurGaussOffset2);
46  c = vec2 (uv.x, y);
47  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight2;
48 
49  return sum;
50 }
51 
52 ///
53 /// Perform a single horizontal blur sample for texel \a uv in \a t.
54 ///
55 /// @param t A texture
56 /// @param uv The coordinates of the current texel
57 /// @param size The blur size
58 ///
59 
60 vec4
62  const sampler2D t,
63  const vec2 uv,
64  const float size)
65 {
66  float size_inv = 1.0 / size;
67  float x;
68  vec2 c;
69 
70  vec4 sum = textureLod (t, uv, 0.0) * R2_boxBlurGaussWeight0;
71 
72  x = uv.x + (size_inv * R2_boxBlurGaussOffset1);
73  c = vec2 (x, uv.y);
74  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight1;
75 
76  x = uv.x + (size_inv * R2_boxBlurGaussOffset2);
77  c = vec2 (x, uv.y);
78  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight2;
79 
80  x = uv.x - (size_inv * R2_boxBlurGaussOffset1);
81  c = vec2 (x, uv.y);
82  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight1;
83 
84  x = uv.x - (size_inv * R2_boxBlurGaussOffset2);
85  c = vec2 (x, uv.y);
86  sum += textureLod (t, c, 0.0) * R2_boxBlurGaussWeight2;
87 
88  return sum;
89 }
90 
91 #endif // R2_BOX_BLUR_H
vec4 R2_boxBlurHorizontal4f(const sampler2D t, const vec2 uv, const float size)
Definition: R2BoxBlur.h:61
vec4 R2_boxBlurVertical4f(const sampler2D t, const vec2 uv, const float size)
Definition: R2BoxBlur.h:22