50 #define CAMERA_JITTER_RING_DENSITY 6
56 if (multiplier == 0.0f || bias == 0.0f) {
60 return (camera_depth + multiplier / bias) * multiplier;
62 return multiplier / camera_depth - bias;
67 return 2.0 *
sin(
M_PI / sides_count);
75 float side_angle = (2.0f *
M_PI) / sides_count;
76 return cosf(side_angle * 0.5f) /
84 float side_angle = (2.0f *
M_PI) / sides_count;
85 float halfside_angle = side_angle * 0.5f;
86 float side =
floorf(theta / side_angle);
91 float local_theta = theta - side * side_angle;
92 float ratio = (local_theta - halfside_angle) / halfside_angle;
95 float opposite = ratio * halfside_len;
98 float final_local_theta =
atanf(opposite / adjacent);
100 return side * side_angle + final_local_theta;
105 return ((ring_count * ring_count + ring_count) / 2) * ring_density + 1;
110 float *r_focus_distance)
123 int ring_sample_count = 1;
126 s = s * (ring_density - 1);
127 s = s % sample_count;
129 int samples_passed = 1;
130 while (s >= samples_passed) {
132 ring_sample_count = ring * ring_density;
133 ring_sample = s - samples_passed;
134 ring_sample = (ring_sample + 1) % ring_sample_count;
135 samples_passed += ring_sample_count;
138 r_jitter[0] = (
float)ring / ring_count;
139 r_jitter[1] = (
float)ring_sample / ring_sample_count;
143 float r = r_jitter[0];
144 float T = r_jitter[1] * 2.0f *
M_PI;
153 r_jitter[0] =
r *
cosf(
T);
154 r_jitter[1] =
r *
sinf(
T);
170 if (r_ring_count !=
NULL) {
184 float discriminant = 1.0f + 4.0f *
x;
185 int ring_count =
ceilf(0.5f * (
sqrt(discriminant) - 1.0f));
189 if (r_ring_count !=
NULL) {
190 *r_ring_count = ring_count;
227 float focal_len = cam->
lens;
236 const float scale_camera = (is_ortho) ? 1.0 : 0.001f;
238 float aperture = 0.5f * scale_camera * focal_len / fstop;
239 float focal_len_scaled = scale_camera * focal_len;
240 float sensor_scaled = scale_camera * sensor;
253 fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
273 float minimal_overblur = 1.0f /
sqrtf(sample_count);
308 float max_abs_fg_coc, max_abs_bg_coc;
319 float max_coc =
max_ff(max_abs_bg_coc, max_abs_fg_coc);
347 #define WITH_FILTERING (GPU_SAMPLER_MIPMAP | GPU_SAMPLER_FILTER)
348 #define NO_FILTERING GPU_SAMPLER_MIPMAP
349 #define COLOR_FORMAT fx->dof_color_format
350 #define FG_TILE_FORMAT GPU_RGBA16F
351 #define BG_TILE_FORMAT GPU_R11F_G11F_B10F
387 GPU_ATTACHMENT_TEXTURE(fx->dof_bokeh_gather_lut_tx),
388 GPU_ATTACHMENT_TEXTURE(fx->dof_bokeh_scatter_lut_tx),
389 GPU_ATTACHMENT_TEXTURE(fx->dof_bokeh_resolve_lut_tx),
422 GPU_ATTACHMENT_TEXTURE(fx->dof_half_res_color_tx),
423 GPU_ATTACHMENT_TEXTURE(fx->dof_half_res_coc_tx),
453 GPU_ATTACHMENT_TEXTURE(fx->dof_coc_tiles_fg_tx),
454 GPU_ATTACHMENT_TEXTURE(fx->dof_coc_tiles_bg_tx),
475 for (
int pass = 0; pass < 2; pass++) {
493 GPU_ATTACHMENT_TEXTURE(fx->dof_coc_dilated_tiles_fg_tx),
494 GPU_ATTACHMENT_TEXTURE(fx->dof_coc_dilated_tiles_bg_tx),
502 for (
int pass = 0; pass < 2; pass++) {
510 int dilation_radius = 0;
511 while (dilation_radius < dilation_end_radius) {
515 int remainder = dilation_end_radius - dilation_radius;
517 int max_multiplier = dilation_radius + 1;
520 int multiplier =
min_ii(max_multiplier,
floor(remainder / (
float)ring_count));
522 dilation_radius += ring_count * multiplier;
560 int multiple = 2 << (mip_count - 1);
561 int res[2] = {(multiple *
divide_ceil_u(fullres[0], multiple)) / 2,
586 GPU_ATTACHMENT_TEXTURE(fx->dof_downsample_tx),
593 const bool is_copy_pass =
true;
617 const bool is_copy_pass =
false;
653 GPU_ATTACHMENT_TEXTURE(txl->dof_reduced_color),
654 GPU_ATTACHMENT_TEXTURE(txl->dof_reduced_coc),
660 GPU_ATTACHMENT_TEXTURE(txl->dof_reduced_color),
661 GPU_ATTACHMENT_TEXTURE(txl->dof_reduced_coc),
662 GPU_ATTACHMENT_TEXTURE(fx->dof_scatter_src_tx),
680 float uv_correction_fac[2] = {res[0] / (
float)input_size[0], res[1] / (
float)input_size[1]};
681 float output_texel_size[2] = {1.0f / res[0], 1.0f / res[1]};
709 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_color_tx),
710 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_weight_tx),
749 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_color_tx),
750 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_weight_tx),
751 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_occlusion_tx),
784 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_color_tx),
785 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_holefill_weight_tx),
786 GPU_ATTACHMENT_TEXTURE(fx->dof_bg_occlusion_tx),
813 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_color_tx),
814 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_weight_tx),
820 GPU_ATTACHMENT_TEXTURE(fx->dof_bg_color_tx),
821 GPU_ATTACHMENT_TEXTURE(fx->dof_bg_weight_tx),
834 int input_size[2], target_size[2];
838 int sprite_count = (input_size[0] / 2) * (input_size[1] / 2);
839 float target_texel_size[2] = {1.0f / target_size[0], 1.0f / target_size[1]};
845 const bool is_foreground =
true;
867 GPU_ATTACHMENT_TEXTURE(fx->dof_fg_color_tx),
873 const bool is_foreground =
false;
891 GPU_ATTACHMENT_TEXTURE(fx->dof_bg_color_tx),
typedef float(TangentPoint)[2]
Camera data-block and utility functions.
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
float BKE_camera_object_dof_distance(struct Object *ob)
MINLINE unsigned int log2_ceil_u(unsigned int x)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE float clamp_f(float value, float min, float max)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
MINLINE void mul_v2_v2(float r[2], const float a[2])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void negate_v2(float r[2])
MINLINE void invert_v2(float r[2])
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
@ SCE_EEVEE_DOF_HQ_SLIGHT_FOCUS
@ DRW_STATE_BLEND_ADD_FULL
#define DRW_PASS_CREATE(pass, state)
#define DRW_TEXTURE_FREE_SAFE(tex)
struct GPUFrameBuffer GPUFrameBuffer
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
struct GPUShader GPUShader
struct GPUTexture GPUTexture
int GPU_texture_width(const GPUTexture *tex)
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_generate_mipmap(GPUTexture *tex)
const DRWContextState * DRW_context_state_get(void)
const float * DRW_viewport_size_get(void)
DefaultTextureList * DRW_viewport_texture_list_get(void)
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_uniform_texture_ref_ex(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex, eGPUSamplerState sampler_state)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob, uint tri_count)
void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value)
void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_shgroup_uniform_vec2_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_draw_pass(DRWPass *pass)
void DRW_stats_group_start(const char *name)
void DRW_stats_group_end(void)
GPUTexture * DRW_texture_pool_query_2d(int w, int h, eGPUTextureFormat format, DrawEngineType *engine_type)
static float circle_to_polygon_angle(float sides_count, float theta)
int EEVEE_depth_of_field_sample_count_get(EEVEE_EffectsInfo *effects, int sample_count, int *r_ring_count)
#define CAMERA_JITTER_RING_DENSITY
static int dof_jitter_total_sample_count(int ring_density, int ring_count)
static void dof_flatten_tiles_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
static void dof_filter_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
static float coc_radius_from_camera_depth(bool is_ortho, EEVEE_EffectsInfo *fx, float camera_depth)
static void dof_scatter_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_TextureList *txl, EEVEE_EffectsInfo *fx)
static float circle_to_polygon_radius(float sides_count, float theta)
static void dof_recursive_reduce(void *vedata, int UNUSED(level))
static void dof_setup_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
static void dof_recombine_pass_init(EEVEE_FramebufferList *UNUSED(fbl), EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
void EEVEE_depth_of_field_draw(EEVEE_Data *vedata)
int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
static void dof_reduce_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_TextureList *txl, EEVEE_EffectsInfo *fx)
void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
static void dof_gather_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_TextureList *txl, EEVEE_EffectsInfo *fx)
static void dof_dilate_tiles_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
static float polygon_sides_length(float sides_count)
static void dof_dilate_tiles_pass_draw(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
static void dof_bokeh_pass_init(EEVEE_FramebufferList *fbl, EEVEE_PassList *psl, EEVEE_EffectsInfo *fx)
bool EEVEE_depth_of_field_jitter_get(EEVEE_EffectsInfo *fx, float r_jitter[2], float *r_focus_distance)
struct GPUTexture * EEVEE_materials_get_util_tex(void)
struct GPUShader * EEVEE_shaders_depth_of_field_setup_get(void)
struct GPUShader * EEVEE_shaders_depth_of_field_bokeh_get(void)
struct GPUShader * EEVEE_shaders_depth_of_field_dilate_tiles_get(bool pass)
int EEVEE_temporal_sampling_sample_count_get(const Scene *scene, const EEVEE_StorageList *stl)
#define DOF_BOKEH_LUT_SIZE
#define DOF_DILATE_RING_COUNT
struct GPUShader * EEVEE_shaders_depth_of_field_scatter_get(bool is_foreground, bool bokeh_tx)
struct GPUShader * EEVEE_shaders_depth_of_field_gather_get(EEVEE_DofGatherPass pass, bool bokeh_tx)
#define DOF_GATHER_RING_COUNT
struct GPUShader * EEVEE_shaders_depth_of_field_flatten_tiles_get(void)
struct GPUShader * EEVEE_shaders_depth_of_field_resolve_get(bool use_bokeh_tx, bool use_hq_gather)
struct GPUShader * EEVEE_shaders_depth_of_field_reduce_get(bool is_copy_pass)
struct GPUShader * EEVEE_shaders_depth_of_field_downsample_get(void)
struct GPUShader * EEVEE_shaders_depth_of_field_filter_get(void)
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb, int max_lvl, void(*callback)(void *userData, int level), void *userData)
MINLINE uint divide_ceil_u(uint a, uint b)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
struct CameraDOFSettings dof
struct Depsgraph * depsgraph
struct RegionView3D * rv3d
struct GPUTexture * depth
EEVEE_FramebufferList * fbl
struct GPUTexture * dof_scatter_src_tx
struct GPUTexture * dof_coc_dilated_tiles_bg_tx
struct GPUTexture * source_buffer
struct GPUTexture * dof_bokeh_scatter_lut_tx
struct GPUTexture * dof_reduce_input_color_tx
struct GPUTexture * dof_coc_dilated_tiles_fg_tx
struct GPUTexture * dof_fg_holefill_weight_tx
struct GPUTexture * dof_fg_color_tx
float dof_scatter_color_threshold
struct GPUTexture * dof_bg_color_tx
struct GPUFrameBuffer * target_buffer
struct GPUTexture * dof_coc_tiles_bg_tx
float dof_bokeh_aniso_inv[2]
struct GPUTexture * dof_downsample_tx
struct GPUTexture * dof_fg_weight_tx
struct GPUTexture * dof_fg_occlusion_tx
int dof_jitter_ring_count
EEVEE_EffectsFlag enabled_effects
int dof_dilate_slight_focus
struct GPUTexture * dof_half_res_color_tx
struct GPUTexture * dof_bokeh_resolve_lut_tx
float dof_scatter_coc_threshold
struct GPUTexture * dof_reduce_input_coc_tx
struct GPUTexture * dof_fg_holefill_color_tx
struct GPUTexture * dof_coc_tiles_fg_tx
eGPUTextureFormat dof_color_format
int dof_dilate_ring_width_multiplier
float dof_scatter_neighbor_max_color
struct GPUTexture * dof_bg_occlusion_tx
struct GPUTexture * dof_bokeh_gather_lut_tx
struct GPUTexture * dof_half_res_coc_tx
int dof_dilate_ring_count
struct GPUTexture * dof_bg_weight_tx
struct GPUFrameBuffer * dof_gather_fg_fb
struct GPUFrameBuffer * dof_reduce_copy_fb
struct GPUFrameBuffer * dof_flatten_tiles_fb
struct GPUFrameBuffer * dof_filter_fg_fb
struct GPUFrameBuffer * dof_bokeh_fb
struct GPUFrameBuffer * dof_setup_fb
struct GPUFrameBuffer * dof_downsample_fb
struct GPUFrameBuffer * dof_reduce_fb
struct GPUFrameBuffer * dof_gather_bg_fb
struct GPUFrameBuffer * dof_scatter_bg_fb
struct GPUFrameBuffer * dof_dilate_tiles_fb
struct GPUFrameBuffer * dof_gather_fg_holefill_fb
struct GPUFrameBuffer * dof_scatter_fg_fb
struct GPUFrameBuffer * dof_filter_bg_fb
struct DRWPass * dof_reduce_copy
struct DRWPass * dof_setup
struct DRWPass * dof_gather_bg
struct DRWPass * dof_bokeh
struct DRWPass * dof_gather_fg
struct DRWPass * dof_gather_fg_holefill
struct DRWPass * dof_scatter_fg
struct DRWPass * dof_scatter_bg
struct DRWPass * dof_reduce
struct DRWPass * dof_downsample
struct DRWPass * dof_flatten_tiles
struct DRWPass * dof_resolve
struct DRWPass * dof_dilate_tiles_minmax
struct DRWPass * dof_dilate_tiles_minabs
struct DRWPass * dof_filter
struct EEVEE_EffectsInfo * effects
struct GPUTexture * dof_reduced_coc
struct GPUTexture * dof_reduced_color
ccl_device_inline float2 floor(const float2 &a)