Back home 🏡 WGSL Spec Bevy WGSL Functions

dof.wgsl

Constants

Name Type Value
COS_NEG_FRAC_PI_6 # f32 0.8660254037844387
SIN_NEG_FRAC_PI_6 # f32 -0.5
COS_NEG_FRAC_PI_5_6 # f32 -0.8660254037844387
SIN_NEG_FRAC_PI_5_6 # f32 -0.5

Bindings

Name Group Binding index Binding type Type Shader Def
depth_texture # 0 1 texture_depth_multisampled_2d 🟢 MULTISAMPLED
depth_texture # 0 1 texture_depth_2d 🔴 MULTISAMPLED
color_texture_a # 0 2 texture_2d<f32>
color_texture_b # 0 3 texture_2d<f32> 🟢 DUAL_INPUT
dof_params # 1 0 <uniform> DepthOfFieldParams
color_texture_sampler # 1 1 sampler

Structures

DepthOfFieldParams

#
Parameters that control the depth of field effect. See bevy_core_pipeline::dof::DepthOfFieldUniforms for information on what these parameters mean.
Name Type
focal_distance f32
focal_length f32
coc_scale_factor f32
max_circle_of_confusion_diameter f32
max_depth f32
pad_a u32
pad_b u32
pad_c u32

DualOutput

#
The first bokeh pass outputs to two render targets. We declare them here.
Annotation Name Type
location(0) output_0 vec4<f32>
location(1) output_1 vec4<f32>

Functions

calculate_circle_of_confusion

#
Calculates and returns the diameter (not the radius) of the [circle of confusion]. [circle of confusion]: https://en.wikipedia.org/wiki/Circle_of_confusion
fn calculate_circle_of_confusion(in_frag_coord: vec4<f32>) -> f32
Parameter Type
in_frag_coord vec4<f32>
Returns: f32

gaussian_blur

#
Performs a single direction of the separable Gaussian blur kernel. * frag_coord is the screen-space pixel coordinate of the fragment (i.e. the position input to the fragment). * coc is the diameter (not the radius) of the circle of confusion for this fragment. * frag_offset is the vector, in screen-space units, from one sample to the next. For a horizontal blur this will be vec2(1.0, 0.0); for a vertical blur this will be vec2(0.0, 1.0). Returns the resulting color of the fragment.
fn gaussian_blur(frag_coord: vec4<f32>, coc: f32, frag_offset: vec2<f32>) -> vec4<f32>
Parameter Type
frag_coord vec4<f32>
coc f32
frag_offset vec2<f32>
Returns: vec4<f32>

box_blur_a

#
Performs a box blur in a single direction, sampling color_texture_a. * frag_coord is the screen-space pixel coordinate of the fragment (i.e. the position input to the fragment). * coc is the diameter (not the radius) of the circle of confusion for this fragment. * frag_offset is the vector, in screen-space units, from one sample to the next. This need not be horizontal or vertical.
fn box_blur_a(frag_coord: vec4<f32>, coc: f32, frag_offset: vec2<f32>) -> vec4<f32>
Parameter Type
frag_coord vec4<f32>
coc f32
frag_offset vec2<f32>
Returns: vec4<f32>

box_blur_b

#

Shader defs:

🟢 DUAL_INPUT

fn box_blur_b(frag_coord: vec4<f32>, coc: f32, frag_offset: vec2<f32>) -> vec4<f32>
Parameter Type
frag_coord vec4<f32>
coc f32
frag_offset vec2<f32>
Returns: vec4<f32>

gaussian_horizontal

#
@fragment
Calculates the horizontal component of the separable Gaussian blur.
fn gaussian_horizontal(in: FullscreenVertexOutput) -> @location(0) vec4<f32>
Parameter Type
in FullscreenVertexOutput
Returns: @location(0) vec4<f32>

gaussian_vertical

#
@fragment
Calculates the vertical component of the separable Gaussian blur.
fn gaussian_vertical(in: FullscreenVertexOutput) -> @location(0) vec4<f32>
Parameter Type
in FullscreenVertexOutput
Returns: @location(0) vec4<f32>

bokeh_pass_0

#
@fragment
Calculates the vertical and first diagonal components of the separable hexagonal bokeh blur. ╱ ╱ • │ │
fn bokeh_pass_0(in: FullscreenVertexOutput) -> DualOutput
Parameter Type
in FullscreenVertexOutput
Returns: DualOutput

bokeh_pass_1

#
@fragment

Shader defs:

🟢 DUAL_INPUT

fn bokeh_pass_1(in: FullscreenVertexOutput) -> @location(0) vec4<f32>
Parameter Type
in FullscreenVertexOutput
Returns: @location(0) vec4<f32>