R2 Shaders
Data Structures | Functions
R2BilateralBlur.h File Reference

Functions for performing bilateral blurs. More...

#include "R2LogDepth.h"
Include dependency graph for R2BilateralBlur.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  R2_bilateral_blur_depth_aware_t
 Parameters for the blur effect. More...
 

Functions

vec4 R2_bilateralBlurDepthAwareSample4f (const sampler2D t, const sampler2D d, const R2_bilateral_blur_depth_aware_t blur, const vec2 uv, const float radius, const vec4 center_val, const float center_depth, inout float weight_total)
 
vec4 R2_bilateralBlurDepthAwareHorizontal4f (const sampler2D t, const sampler2D d, const R2_bilateral_blur_depth_aware_t blur, const vec2 uv)
 
vec4 R2_bilateralBlurDepthAwareVertical4f (const sampler2D t, const sampler2D d, const R2_bilateral_blur_depth_aware_t blur, const vec2 uv)
 

Detailed Description

Functions for performing bilateral blurs.

Definition in file R2BilateralBlur.h.

Function Documentation

§ R2_bilateralBlurDepthAwareHorizontal4f()

vec4 R2_bilateralBlurDepthAwareHorizontal4f ( const sampler2D  t,
const sampler2D  d,
const R2_bilateral_blur_depth_aware_t  blur,
const vec2  uv 
)

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

The texture d is assumed to hold logarithmicaly-encoded depth samples, and the values contained within will be used to determine how much each sample contributes to the blur effect.

Parameters
tA texture
uvThe coordinates of the current texel

Definition at line 65 of file R2BilateralBlur.h.

70 {
71  float weight_total = 0.0;
72 
73  vec4 center_val =
74  textureLod (t, uv, 0.0);
75  float center_depth =
76  R2_logDepthDecode (textureLod (d, uv, 0.0).x, blur.depth_coefficient);
77 
78  vec4 sum = vec4 (0.0);
79  for (float r = -blur.radius; r <= blur.radius; ++r)
80  {
81  vec2 uv_off =
82  uv + vec2 (r * blur.output_image_size_inverse.x, 0);
83  sum += R2_bilateralBlurDepthAwareSample4f(
84  t, d, blur, uv_off, r, center_val, center_depth, weight_total);
85  }
86 
87  return sum / weight_total;
88 }
vec2 output_image_size_inverse
The inverse of the output image size: (1 / width, 1 / height)
float radius
The blur radius in texels (typically between 3 and 7)
float depth_coefficient
The depth coefficient that was used to produce the scene&#39;s depth values.
float R2_logDepthDecode(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:72

§ R2_bilateralBlurDepthAwareVertical4f()

vec4 R2_bilateralBlurDepthAwareVertical4f ( const sampler2D  t,
const sampler2D  d,
const R2_bilateral_blur_depth_aware_t  blur,
const vec2  uv 
)

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

The texture d is assumed to hold logarithmicaly-encoded depth samples, and the values contained within will be used to determine how much each sample contributes to the blur effect.

Parameters
tA texture
uvThe coordinates of the current texel

Definition at line 102 of file R2BilateralBlur.h.

107 {
108  float weight_total = 0.0;
109 
110  vec4 center_val =
111  textureLod (t, uv, 0.0);
112  float center_depth =
113  R2_logDepthDecode (textureLod (d, uv, 0.0).x, blur.depth_coefficient);
114 
115  vec4 sum = vec4 (0.0);
116  for (float r = -blur.radius; r <= blur.radius; ++r)
117  {
118  vec2 uv_off =
119  uv + vec2 (0, r * blur.output_image_size_inverse.y);
120  sum += R2_bilateralBlurDepthAwareSample4f(
121  t, d, blur, uv_off, r, center_val, center_depth, weight_total);
122  }
123 
124  return sum / weight_total;
125 }
vec2 output_image_size_inverse
The inverse of the output image size: (1 / width, 1 / height)
float radius
The blur radius in texels (typically between 3 and 7)
float depth_coefficient
The depth coefficient that was used to produce the scene&#39;s depth values.
float R2_logDepthDecode(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:72