Blender  V3.3
Macros | Functions
workbench_effect_dof.c File Reference
#include "workbench_private.h"
#include "BKE_camera.h"
#include "DEG_depsgraph_query.h"
#include "DNA_camera_types.h"

Go to the source code of this file.

Macros

#define SQUARE_UNSAFE(a)   ((a) * (a))
 
#define KERNEL_RAD   (3)
 
#define SAMP_LEN   SQUARE_UNSAFE(KERNEL_RAD * 2 + 1)
 

Functions

static void square_to_circle (float x, float y, float *r, float *T)
 
static void workbench_dof_setup_samples (struct GPUUniformBuf **ubo, float **data, float bokeh_sides, float bokeh_rotation, float bokeh_ratio)
 
void workbench_dof_engine_init (WORKBENCH_Data *vedata)
 
void workbench_dof_cache_init (WORKBENCH_Data *vedata)
 
static void workbench_dof_downsample_level (void *userData, int UNUSED(level))
 
void workbench_dof_draw_pass (WORKBENCH_Data *vedata)
 

Detailed Description

Depth of Field Effect:

We use a gather approach by sampling a lowres version of the color buffer. The process can be summarized like this:

This is done after all passes and affects every surfaces.

Definition in file workbench_effect_dof.c.

Macro Definition Documentation

◆ KERNEL_RAD

#define KERNEL_RAD   (3)

Definition at line 59 of file workbench_effect_dof.c.

◆ SAMP_LEN

#define SAMP_LEN   SQUARE_UNSAFE(KERNEL_RAD * 2 + 1)

Definition at line 60 of file workbench_effect_dof.c.

◆ SQUARE_UNSAFE

#define SQUARE_UNSAFE (   a)    ((a) * (a))

Definition at line 58 of file workbench_effect_dof.c.

Function Documentation

◆ square_to_circle()

static void square_to_circle ( float  x,
float  y,
float r,
float T 
)
static

Transform [-1..1] square to unit circle.

Definition at line 29 of file workbench_effect_dof.c.

References M_PI_4, r, T, x, and y.

Referenced by workbench_dof_setup_samples().

◆ workbench_dof_cache_init()

void workbench_dof_cache_init ( WORKBENCH_Data vedata)

Definition at line 241 of file workbench_effect_dof.c.

References WORKBENCH_ViewLayerData::cavity_jitter_tx, WORKBENCH_TextureList::coc_halfres_tx, WORKBENCH_PrivateData::coc_temp_tx, WORKBENCH_PrivateData::coc_tiles_tx, DefaultTextureList::color, DefaultTextureList::depth, WORKBENCH_PrivateData::dof_aperturesize, WORKBENCH_PassList::dof_blur1_ps, WORKBENCH_PassList::dof_blur2_ps, WORKBENCH_PrivateData::dof_blur_tx, WORKBENCH_PassList::dof_dilate_h_ps, WORKBENCH_PassList::dof_dilate_v_ps, WORKBENCH_PassList::dof_down2_ps, WORKBENCH_PassList::dof_down_ps, WORKBENCH_PrivateData::dof_enabled, WORKBENCH_PassList::dof_flatten_h_ps, WORKBENCH_PassList::dof_flatten_v_ps, WORKBENCH_PrivateData::dof_near_far, WORKBENCH_PassList::dof_resolve_ps, WORKBENCH_ViewLayerData::dof_sample_ubo, WORKBENCH_TextureList::dof_source_tx, downsample_sh, DRW_pass_create(), DRW_shgroup_call_procedural_triangles(), DRW_shgroup_create(), DRW_shgroup_uniform_block, DRW_shgroup_uniform_float_copy(), DRW_shgroup_uniform_texture(), DRW_shgroup_uniform_texture_ex(), DRW_shgroup_uniform_vec2(), DRW_shgroup_uniform_vec3(), DRW_STATE_BLEND_CUSTOM, DRW_STATE_WRITE_COLOR, DRW_viewport_invert_size_get(), DRW_viewport_texture_list_get(), float(), GPU_SAMPLER_DEFAULT, max_ii(), NULL, offset, WORKBENCH_Data::psl, WORKBENCH_Data::stl, WORKBENCH_PrivateData::taa_sample, WORKBENCH_PrivateData::taa_sample_len, WORKBENCH_Data::txl, WORKBENCH_PrivateData::vldata, workbench_cavity_samples_ubo_ensure(), workbench_shader_depth_of_field_get(), and WORKBENCH_StorageList::wpd.

Referenced by workbench_cache_init().

◆ workbench_dof_downsample_level()

static void workbench_dof_downsample_level ( void userData,
int   UNUSEDlevel 
)
static

Definition at line 347 of file workbench_effect_dof.c.

References WORKBENCH_PassList::dof_down2_ps, and DRW_draw_pass().

Referenced by workbench_dof_draw_pass().

◆ workbench_dof_draw_pass()

void workbench_dof_draw_pass ( WORKBENCH_Data vedata)

◆ workbench_dof_engine_init()

void workbench_dof_engine_init ( WORKBENCH_Data vedata)

Definition at line 111 of file workbench_effect_dof.c.

References CameraDOFSettings::aperture_blades, CameraDOFSettings::aperture_fstop, CameraDOFSettings::aperture_ratio, CameraDOFSettings::aperture_rotation, BKE_camera_object_dof_distance(), BKE_camera_sensor_size(), CAM_DOF_ENABLED, WORKBENCH_PrivateData::cam_original_ob, View3D::camera, camera, ceilf, Camera::clip_end, Camera::clip_start, WORKBENCH_TextureList::coc_halfres_tx, WORKBENCH_PrivateData::coc_temp_tx, WORKBENCH_PrivateData::coc_tiles_tx, Camera::dof, WORKBENCH_PrivateData::dof_aperturesize, WORKBENCH_PrivateData::dof_blades, WORKBENCH_FramebufferList::dof_blur1_fb, WORKBENCH_FramebufferList::dof_blur2_fb, WORKBENCH_PrivateData::dof_blur_tx, WORKBENCH_FramebufferList::dof_coc_dilate_fb, WORKBENCH_FramebufferList::dof_coc_tile_h_fb, WORKBENCH_FramebufferList::dof_coc_tile_v_fb, WORKBENCH_PrivateData::dof_distance, WORKBENCH_FramebufferList::dof_downsample_fb, WORKBENCH_PrivateData::dof_enabled, WORKBENCH_PrivateData::dof_invsensorsize, WORKBENCH_PrivateData::dof_near_far, WORKBENCH_PrivateData::dof_ratio, WORKBENCH_PrivateData::dof_rotation, WORKBENCH_ViewLayerData::dof_sample_ubo, WORKBENCH_TextureList::dof_source_tx, WORKBENCH_StorageList::dof_ubo_data, draw_engine_workbench, DRW_context_state_get(), DRW_TEX_FILTER, DRW_TEX_MIPMAP, DRW_texture_ensure_2d(), DRW_TEXTURE_FREE_SAFE, DRW_texture_pool_query_2d(), DRW_viewport_size_get(), fabsf, WORKBENCH_Data::fbl, CameraDOFSettings::flag, View3DShading::flag, GPU_RG8, GPU_RGBA16F, Camera::lens, max_ii(), NULL, OB_CAMERA, RegionView3D::persp, DRWContextState::rv3d, RV3D_CAMOB, Camera::sensor_fit, Camera::sensor_x, Camera::sensor_y, WORKBENCH_PrivateData::shading, size(), WORKBENCH_Data::stl, WORKBENCH_Data::txl, DRWContextState::v3d, V3D_SHADING_DEPTH_OF_FIELD, RegionView3D::viewcamtexcofac, WORKBENCH_PrivateData::vldata, workbench_dof_setup_samples(), and WORKBENCH_StorageList::wpd.

Referenced by workbench_engine_init().

◆ workbench_dof_setup_samples()

static void workbench_dof_setup_samples ( struct GPUUniformBuf **  ubo,
float **  data,
float  bokeh_sides,
float  bokeh_rotation,
float  bokeh_ratio 
)
static