diff options
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 | 92 |
1 files changed, 38 insertions, 54 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 dcd45e27337..c137aa8da24 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,6 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v { EEVEE_StorageList *stl = vedata->stl; EEVEE_FramebufferList *fbl = vedata->fbl; - EEVEE_TextureList *txl = vedata->txl; EEVEE_EffectsInfo *effects = stl->effects; const DRWContextState *draw_ctx = DRW_context_state_get(); @@ -104,39 +103,36 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2}; - /* Reuse buffer from Bloom if available */ - /* WATCH IT : must have the same size */ - struct GPUTexture **dof_down_near; - - if ((effects->enabled_effects & EFFECT_BLOOM) != 0) { - dof_down_near = &txl->bloom_downsample[0]; - } - else { - dof_down_near = &txl->dof_down_near; - } + effects->dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10, + &draw_engine_eevee_type); + effects->dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10, + &draw_engine_eevee_type); + effects->dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RG_16, + &draw_engine_eevee_type); - /* Setup buffers */ - DRWFboTexture tex_down[3] = { - {dof_down_near, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER}, /* filter to not interfeer with bloom */ - {&txl->dof_down_far, DRW_TEX_RGB_11_11_10, 0}, - {&txl->dof_coc, DRW_TEX_RG_16, 0}, - }; - DRW_framebuffer_init( - &fbl->dof_down_fb, &draw_engine_eevee_type, - buffer_size[0], buffer_size[1], tex_down, 3); + 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. */ DRWTextureFormat fb_format = DRW_state_is_image_render() ? DRW_TEX_RGBA_32 : DRW_TEX_RGBA_16; - DRWFboTexture tex_scatter_far = {&txl->dof_far_blur, fb_format, DRW_TEX_FILTER}; - DRW_framebuffer_init( - &fbl->dof_scatter_far_fb, &draw_engine_eevee_type, - buffer_size[0], buffer_size[1], &tex_scatter_far, 1); + effects->dof_far_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format, + &draw_engine_eevee_type); + GPU_framebuffer_ensure_config(&fbl->dof_scatter_far_fb, { + GPU_ATTACHMENT_NONE, + GPU_ATTACHMENT_TEXTURE(effects->dof_far_blur), + }); - DRWFboTexture tex_scatter_near = {&txl->dof_near_blur, fb_format, DRW_TEX_FILTER}; - DRW_framebuffer_init( - &fbl->dof_scatter_near_fb, &draw_engine_eevee_type, - buffer_size[0], buffer_size[1], &tex_scatter_near, 1); + effects->dof_near_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format, + &draw_engine_eevee_type); + GPU_framebuffer_ensure_config(&fbl->dof_scatter_near_fb, { + GPU_ATTACHMENT_NONE, + GPU_ATTACHMENT_TEXTURE(effects->dof_near_blur), + }); /* Parameters */ /* TODO UI Options */ @@ -178,14 +174,9 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v } /* Cleanup to release memory */ - DRW_TEXTURE_FREE_SAFE(txl->dof_down_near); - DRW_TEXTURE_FREE_SAFE(txl->dof_down_far); - DRW_TEXTURE_FREE_SAFE(txl->dof_coc); - DRW_TEXTURE_FREE_SAFE(txl->dof_far_blur); - DRW_TEXTURE_FREE_SAFE(txl->dof_near_blur); - DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb); - DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb); - DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb); + GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb); + GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb); + GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb); return 0; } @@ -194,7 +185,6 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ { EEVEE_PassList *psl = vedata->psl; EEVEE_StorageList *stl = vedata->stl; - EEVEE_TextureList *txl = vedata->txl; EEVEE_EffectsInfo *effects = stl->effects; DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); @@ -229,7 +219,7 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct); DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->unf_source_buffer); - DRW_shgroup_uniform_buffer(grp, "cocBuffer", &txl->dof_coc); + DRW_shgroup_uniform_buffer(grp, "cocBuffer", &effects->dof_coc); DRW_shgroup_uniform_vec2(grp, "layerSelection", effects->dof_layer_select, 1); DRW_shgroup_uniform_vec4(grp, "bokehParams", effects->dof_bokeh, 1); @@ -237,8 +227,8 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ grp = DRW_shgroup_create(e_data.dof_resolve_sh, psl->dof_resolve); DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->source_buffer); - DRW_shgroup_uniform_buffer(grp, "nearBuffer", &txl->dof_near_blur); - DRW_shgroup_uniform_buffer(grp, "farBuffer", &txl->dof_far_blur); + DRW_shgroup_uniform_buffer(grp, "nearBuffer", &effects->dof_near_blur); + DRW_shgroup_uniform_buffer(grp, "farBuffer", &effects->dof_far_blur); DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth); DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1); DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1); @@ -259,31 +249,25 @@ void EEVEE_depth_of_field_draw(EEVEE_Data *vedata) float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; /* Downsample */ - DRW_framebuffer_bind(fbl->dof_down_fb); + GPU_framebuffer_bind(fbl->dof_down_fb); DRW_draw_pass(psl->dof_down); /* Scatter Far */ - effects->unf_source_buffer = txl->dof_down_far; + effects->unf_source_buffer = effects->dof_down_far; copy_v2_fl2(effects->dof_layer_select, 0.0f, 1.0f); - DRW_framebuffer_bind(fbl->dof_scatter_far_fb); - DRW_framebuffer_clear(true, false, false, clear_col, 0.0f); + GPU_framebuffer_bind(fbl->dof_scatter_far_fb); + GPU_framebuffer_clear_color(fbl->dof_scatter_far_fb, clear_col); DRW_draw_pass(psl->dof_scatter); /* Scatter Near */ - if ((effects->enabled_effects & EFFECT_BLOOM) != 0) { - /* Reuse bloom half res buffer */ - effects->unf_source_buffer = txl->bloom_downsample[0]; - } - else { - effects->unf_source_buffer = txl->dof_down_near; - } + effects->unf_source_buffer = effects->dof_down_near; copy_v2_fl2(effects->dof_layer_select, 1.0f, 0.0f); - DRW_framebuffer_bind(fbl->dof_scatter_near_fb); - DRW_framebuffer_clear(true, false, false, clear_col, 0.0f); + GPU_framebuffer_bind(fbl->dof_scatter_near_fb); + GPU_framebuffer_clear_color(fbl->dof_scatter_near_fb, clear_col); DRW_draw_pass(psl->dof_scatter); /* Resolve */ - DRW_framebuffer_bind(effects->target_buffer); + GPU_framebuffer_bind(effects->target_buffer); DRW_draw_pass(psl->dof_resolve); SWAP_BUFFERS(); } |