R2 Shaders
Functions | Variables
R2BoxBlur.h File Reference

Functions for performing box blurs. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vec4 R2_boxBlurVertical4f (const sampler2D t, const vec2 uv, const float size)
 
vec4 R2_boxBlurHorizontal4f (const sampler2D t, const vec2 uv, const float size)
 

Variables

const float R2_boxBlurGaussWeight2 = 0.0702702703
 
const float R2_boxBlurGaussOffset2 = 3.2307692308
 
const float R2_boxBlurGaussWeight1 = 0.3162162162
 
const float R2_boxBlurGaussOffset1 = 1.3846153846
 
const float R2_boxBlurGaussWeight0 = 0.2270270270
 

Detailed Description

Functions for performing box blurs.

Definition in file R2BoxBlur.h.

Function Documentation

§ R2_boxBlurHorizontal4f()

vec4 R2_boxBlurHorizontal4f ( const sampler2D  t,
const vec2  uv,
const float  size 
)

Perform a single horizontal blur sample for texel uv in t.

Parameters
tA texture
uvThe coordinates of the current texel
sizeThe blur size

Definition at line 61 of file R2BoxBlur.h.

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 }

§ R2_boxBlurVertical4f()

vec4 R2_boxBlurVertical4f ( const sampler2D  t,
const vec2  uv,
const float  size 
)

Perform a single vertical blur sample for texel uv in t.

Parameters
tA texture
uvThe coordinates of the current texel
sizeThe blur size

Definition at line 22 of file R2BoxBlur.h.

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 }