diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2019-05-17 17:57:31 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-17 18:59:26 +0300 |
commit | bc3139d79226896cf6c2b0813a1188eda70fad09 (patch) | |
tree | e5c7f1f878b4769def10e2ddbc75aacebda4afd5 /source/blender/draw/engines/eevee/eevee_depth_of_field.c | |
parent | 043299ab69ca47a42fc8ca4f629727f8a6a2dd31 (diff) |
Cycles/Eevee: unify depth of field settings for cameras
There is now a checkbox to enable/disable depth of field per camera. For Eevee
this replace the scene level setting. For Cycles there is now only an F-Stop
value, no longer a Radius.
Existing files are converted based on Cycles or Eevee being set in the scene.
Differential Revision: https://developer.blender.org/D4882
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_depth_of_field.c')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_depth_of_field.c | 173 |
1 files changed, 85 insertions, 88 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.c b/source/blender/draw/engines/eevee/eevee_depth_of_field.c index 3d058f7e46e..25d256e86b3 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.c +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.c @@ -79,7 +79,9 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), const DRWContextState *draw_ctx = DRW_context_state_get(); const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph); - if (scene_eval->eevee.flag & SCE_EEVEE_DOF_ENABLED) { + Camera *cam = (camera != NULL) ? camera->data : NULL; + + if (cam && (cam->dof.flag & CAM_DOF_ENABLED)) { RegionView3D *rv3d = draw_ctx->rv3d; const bool use_alpha = !DRW_state_draw_background(); @@ -87,94 +89,89 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), eevee_create_shader_depth_of_field(use_alpha); } - if (camera) { - const float *viewport_size = DRW_viewport_size_get(); - Camera *cam = (Camera *)camera->data; - - /* Retrieve Near and Far distance */ - effects->dof_near_far[0] = -cam->clip_start; - effects->dof_near_far[1] = -cam->clip_end; - - int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2}; - - eGPUTextureFormat down_format = DRW_state_draw_background() ? GPU_R11F_G11F_B10F : - GPU_RGBA16F; - - effects->dof_down_near = DRW_texture_pool_query_2d( - buffer_size[0], buffer_size[1], down_format, &draw_engine_eevee_type); - effects->dof_down_far = DRW_texture_pool_query_2d( - buffer_size[0], buffer_size[1], down_format, &draw_engine_eevee_type); - effects->dof_coc = DRW_texture_pool_query_2d( - buffer_size[0], buffer_size[1], GPU_RG16F, &draw_engine_eevee_type); - - GPU_framebuffer_ensure_config(&fbl->dof_down_fb, - {GPU_ATTACHMENT_NONE, - GPU_ATTACHMENT_TEXTURE(effects->dof_down_near), - GPU_ATTACHMENT_TEXTURE(effects->dof_down_far), - GPU_ATTACHMENT_TEXTURE(effects->dof_coc)}); - - /* Go full 32bits for rendering and reduce the color artifacts. */ - eGPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F; - - effects->dof_blur = DRW_texture_pool_query_2d( - buffer_size[0] * 2, buffer_size[1], fb_format, &draw_engine_eevee_type); - - GPU_framebuffer_ensure_config(&fbl->dof_scatter_fb, - { - GPU_ATTACHMENT_NONE, - GPU_ATTACHMENT_TEXTURE(effects->dof_blur), - }); - - if (!DRW_state_draw_background()) { - effects->dof_blur_alpha = DRW_texture_pool_query_2d( - buffer_size[0] * 2, buffer_size[1], GPU_R32F, &draw_engine_eevee_type); - GPU_framebuffer_texture_attach(fbl->dof_scatter_fb, effects->dof_blur_alpha, 1, 0); - } - - /* Parameters */ - /* TODO UI Options */ - float fstop = cam->gpu_dof.fstop; - float blades = cam->gpu_dof.num_blades; - float rotation = cam->gpu_dof.rotation; - float ratio = 1.0f / cam->gpu_dof.ratio; - float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); - float focus_dist = BKE_camera_object_dof_distance(camera); - float focal_len = cam->lens; - - /* this is factor that converts to the scene scale. focal length and sensor are expressed in - * mm unit.scale_length is how many meters per blender unit we have. We want to convert to - * blender units though because the shader reads coordinates in world space, which is in - * blender units. - * Note however that focus_distance is already in blender units and shall not be scaled here - * (see T48157). */ - float scale = (scene_eval->unit.system) ? scene_eval->unit.scale_length : 1.0f; - float scale_camera = 0.001f / scale; - /* we want radius here for the aperture number */ - float aperture = 0.5f * scale_camera * focal_len / fstop; - float focal_len_scaled = scale_camera * focal_len; - float sensor_scaled = scale_camera * sensor; - - if (rv3d != NULL) { - sensor_scaled *= rv3d->viewcamtexcofac[0]; - } - - effects->dof_params[1] = aperture * - fabsf(focal_len_scaled / (focus_dist - focal_len_scaled)); - effects->dof_params[1] *= viewport_size[0] / sensor_scaled; - effects->dof_params[0] = -focus_dist * effects->dof_params[1]; - - effects->dof_bokeh[0] = rotation; - effects->dof_bokeh[1] = ratio; - effects->dof_bokeh[2] = scene_eval->eevee.bokeh_max_size; - - /* Precompute values to save instructions in fragment shader. */ - effects->dof_bokeh_sides[0] = blades; - effects->dof_bokeh_sides[1] = blades > 0.0f ? 2.0f * M_PI / blades : 0.0f; - effects->dof_bokeh_sides[2] = blades / (2.0f * M_PI); - effects->dof_bokeh_sides[3] = blades > 0.0f ? cosf(M_PI / blades) : 0.0f; - - return EFFECT_DOF | EFFECT_POST_BUFFER; + const float *viewport_size = DRW_viewport_size_get(); + + /* Retrieve Near and Far distance */ + effects->dof_near_far[0] = -cam->clip_start; + effects->dof_near_far[1] = -cam->clip_end; + + int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2}; + + eGPUTextureFormat down_format = DRW_state_draw_background() ? GPU_R11F_G11F_B10F : GPU_RGBA16F; + + effects->dof_down_near = DRW_texture_pool_query_2d( + buffer_size[0], buffer_size[1], down_format, &draw_engine_eevee_type); + effects->dof_down_far = DRW_texture_pool_query_2d( + buffer_size[0], buffer_size[1], down_format, &draw_engine_eevee_type); + effects->dof_coc = DRW_texture_pool_query_2d( + buffer_size[0], buffer_size[1], GPU_RG16F, &draw_engine_eevee_type); + + GPU_framebuffer_ensure_config(&fbl->dof_down_fb, + {GPU_ATTACHMENT_NONE, + GPU_ATTACHMENT_TEXTURE(effects->dof_down_near), + GPU_ATTACHMENT_TEXTURE(effects->dof_down_far), + GPU_ATTACHMENT_TEXTURE(effects->dof_coc)}); + + /* Go full 32bits for rendering and reduce the color artifacts. */ + eGPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F; + + effects->dof_blur = DRW_texture_pool_query_2d( + buffer_size[0] * 2, buffer_size[1], fb_format, &draw_engine_eevee_type); + + GPU_framebuffer_ensure_config(&fbl->dof_scatter_fb, + { + GPU_ATTACHMENT_NONE, + GPU_ATTACHMENT_TEXTURE(effects->dof_blur), + }); + + if (!DRW_state_draw_background()) { + effects->dof_blur_alpha = DRW_texture_pool_query_2d( + buffer_size[0] * 2, buffer_size[1], GPU_R32F, &draw_engine_eevee_type); + GPU_framebuffer_texture_attach(fbl->dof_scatter_fb, effects->dof_blur_alpha, 1, 0); + } + + /* Parameters */ + /* TODO UI Options */ + float fstop = cam->dof.aperture_fstop; + float blades = cam->dof.aperture_blades; + float rotation = cam->dof.aperture_rotation; + float ratio = 1.0f / cam->dof.aperture_ratio; + float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); + float focus_dist = BKE_camera_object_dof_distance(camera); + float focal_len = cam->lens; + + /* this is factor that converts to the scene scale. focal length and sensor are expressed in + * mm unit.scale_length is how many meters per blender unit we have. We want to convert to + * blender units though because the shader reads coordinates in world space, which is in + * blender units. + * Note however that focus_distance is already in blender units and shall not be scaled here + * (see T48157). */ + float scale = (scene_eval->unit.system) ? scene_eval->unit.scale_length : 1.0f; + float scale_camera = 0.001f / scale; + /* we want radius here for the aperture number */ + float aperture = 0.5f * scale_camera * focal_len / fstop; + float focal_len_scaled = scale_camera * focal_len; + float sensor_scaled = scale_camera * sensor; + + if (rv3d != NULL) { + sensor_scaled *= rv3d->viewcamtexcofac[0]; } + + effects->dof_params[1] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled)); + effects->dof_params[1] *= viewport_size[0] / sensor_scaled; + effects->dof_params[0] = -focus_dist * effects->dof_params[1]; + + effects->dof_bokeh[0] = rotation; + effects->dof_bokeh[1] = ratio; + effects->dof_bokeh[2] = scene_eval->eevee.bokeh_max_size; + + /* Precompute values to save instructions in fragment shader. */ + effects->dof_bokeh_sides[0] = blades; + effects->dof_bokeh_sides[1] = blades > 0.0f ? 2.0f * M_PI / blades : 0.0f; + effects->dof_bokeh_sides[2] = blades / (2.0f * M_PI); + effects->dof_bokeh_sides[3] = blades > 0.0f ? cosf(M_PI / blades) : 0.0f; + + return EFFECT_DOF | EFFECT_POST_BUFFER; } /* Cleanup to release memory */ |