Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_effect_antialiasing.c
| Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
| void workbench_antialiasing_view_updated(WORKBENCH_Data *vedata) | void workbench_antialiasing_view_updated(WORKBENCH_Data *vedata) | ||||
| { | { | ||||
| WORKBENCH_StorageList *stl = vedata->stl; | WORKBENCH_StorageList *stl = vedata->stl; | ||||
| if (stl && stl->wpd) { | if (stl && stl->wpd) { | ||||
| stl->wpd->view_updated = true; | stl->wpd->view_updated = true; | ||||
| } | } | ||||
| } | } | ||||
| /* This function checks if the overlay engine should need center in front depth's. | |||||
| * When that is the case the in front depth are stored and restored. Otherwise it | |||||
| * will be filled with the current sample data. */ | |||||
| static bool workbench_in_front_history_needed(WORKBENCH_Data *vedata) | |||||
| { | |||||
| WORKBENCH_StorageList *stl = vedata->stl; | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| const View3D *v3d = draw_ctx->v3d; | |||||
| const Object *obact = draw_ctx->obact; | |||||
| if (!v3d || (v3d->flag2 & V3D_HIDE_OVERLAYS)) { | |||||
| return false; | |||||
| } | |||||
| if (stl->wpd->is_playback) { | |||||
| return false; | |||||
| } | |||||
| if (!obact || draw_ctx->object_mode != OB_MODE_WEIGHT_PAINT || | |||||
| v3d->overlay.weight_paint_mode_opacity == 0.0) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| void workbench_antialiasing_engine_init(WORKBENCH_Data *vedata) | void workbench_antialiasing_engine_init(WORKBENCH_Data *vedata) | ||||
| { | { | ||||
| WORKBENCH_FramebufferList *fbl = vedata->fbl; | WORKBENCH_FramebufferList *fbl = vedata->fbl; | ||||
| WORKBENCH_TextureList *txl = vedata->txl; | WORKBENCH_TextureList *txl = vedata->txl; | ||||
| WORKBENCH_PrivateData *wpd = vedata->stl->wpd; | WORKBENCH_PrivateData *wpd = vedata->stl->wpd; | ||||
| DrawEngineType *owner = (DrawEngineType *)&workbench_antialiasing_engine_init; | DrawEngineType *owner = (DrawEngineType *)&workbench_antialiasing_engine_init; | ||||
| wpd->view = NULL; | wpd->view = NULL; | ||||
| Show All 19 Lines | if (wpd->view_updated) { | ||||
| } | } | ||||
| } | } | ||||
| if (wpd->taa_sample_len > 0) { | if (wpd->taa_sample_len > 0) { | ||||
| workbench_taa_jitter_init(); | workbench_taa_jitter_init(); | ||||
| DRW_texture_ensure_fullscreen_2d(&txl->history_buffer_tx, GPU_RGBA16F, DRW_TEX_FILTER); | DRW_texture_ensure_fullscreen_2d(&txl->history_buffer_tx, GPU_RGBA16F, DRW_TEX_FILTER); | ||||
| DRW_texture_ensure_fullscreen_2d(&txl->depth_buffer_tx, GPU_DEPTH24_STENCIL8, 0); | DRW_texture_ensure_fullscreen_2d(&txl->depth_buffer_tx, GPU_DEPTH24_STENCIL8, 0); | ||||
| const bool in_front_history = workbench_in_front_history_needed(vedata); | |||||
| if (in_front_history) { | |||||
| DRW_texture_ensure_fullscreen_2d(&txl->depth_in_front_buffer_tx, GPU_DEPTH24_STENCIL8, 0); | |||||
| } | |||||
| else { | |||||
| DRW_TEXTURE_FREE_SAFE(txl->depth_in_front_buffer_tx); | |||||
| } | |||||
| wpd->smaa_edge_tx = DRW_texture_pool_query_fullscreen(GPU_RG8, owner); | wpd->smaa_edge_tx = DRW_texture_pool_query_fullscreen(GPU_RG8, owner); | ||||
| wpd->smaa_weight_tx = DRW_texture_pool_query_fullscreen(GPU_RGBA8, owner); | wpd->smaa_weight_tx = DRW_texture_pool_query_fullscreen(GPU_RGBA8, owner); | ||||
| GPU_framebuffer_ensure_config(&fbl->antialiasing_fb, | GPU_framebuffer_ensure_config(&fbl->antialiasing_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_TEXTURE(txl->depth_buffer_tx), | GPU_ATTACHMENT_TEXTURE(txl->depth_buffer_tx), | ||||
| GPU_ATTACHMENT_TEXTURE(txl->history_buffer_tx), | GPU_ATTACHMENT_TEXTURE(txl->history_buffer_tx), | ||||
| }); | }); | ||||
| if (in_front_history) { | |||||
| GPU_framebuffer_ensure_config(&fbl->antialiasing_in_front_fb, | |||||
| { | |||||
| GPU_ATTACHMENT_TEXTURE(txl->depth_in_front_buffer_tx), | |||||
| }); | |||||
| } | |||||
| GPU_framebuffer_ensure_config(&fbl->smaa_edge_fb, | GPU_framebuffer_ensure_config(&fbl->smaa_edge_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_NONE, | GPU_ATTACHMENT_NONE, | ||||
| GPU_ATTACHMENT_TEXTURE(wpd->smaa_edge_tx), | GPU_ATTACHMENT_TEXTURE(wpd->smaa_edge_tx), | ||||
| }); | }); | ||||
| GPU_framebuffer_ensure_config(&fbl->smaa_weight_fb, | GPU_framebuffer_ensure_config(&fbl->smaa_weight_fb, | ||||
| Show All 34 Lines | if (txl->smaa_search_tx == NULL) { | ||||
| GPU_texture_filter_mode(txl->smaa_area_tx, true); | GPU_texture_filter_mode(txl->smaa_area_tx, true); | ||||
| GPU_texture_unbind(txl->smaa_area_tx); | GPU_texture_unbind(txl->smaa_area_tx); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Cleanup */ | /* Cleanup */ | ||||
| DRW_TEXTURE_FREE_SAFE(txl->history_buffer_tx); | DRW_TEXTURE_FREE_SAFE(txl->history_buffer_tx); | ||||
| DRW_TEXTURE_FREE_SAFE(txl->depth_buffer_tx); | DRW_TEXTURE_FREE_SAFE(txl->depth_buffer_tx); | ||||
| DRW_TEXTURE_FREE_SAFE(txl->depth_in_front_buffer_tx); | |||||
| DRW_TEXTURE_FREE_SAFE(txl->smaa_search_tx); | DRW_TEXTURE_FREE_SAFE(txl->smaa_search_tx); | ||||
| DRW_TEXTURE_FREE_SAFE(txl->smaa_area_tx); | DRW_TEXTURE_FREE_SAFE(txl->smaa_area_tx); | ||||
| } | } | ||||
| } | } | ||||
| void workbench_antialiasing_cache_init(WORKBENCH_Data *vedata) | void workbench_antialiasing_cache_init(WORKBENCH_Data *vedata) | ||||
| { | { | ||||
| WORKBENCH_TextureList *txl = vedata->txl; | WORKBENCH_TextureList *txl = vedata->txl; | ||||
| ▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | void workbench_antialiasing_draw_pass(WORKBENCH_Data *vedata) | ||||
| * If TAA accumulation is finished, we only blit the result. | * If TAA accumulation is finished, we only blit the result. | ||||
| */ | */ | ||||
| if (wpd->taa_sample == 0) { | if (wpd->taa_sample == 0) { | ||||
| /* In playback mode, we are sure the next redraw will not use the same viewmatrix. | /* In playback mode, we are sure the next redraw will not use the same viewmatrix. | ||||
| * In this case no need to save the depth buffer. */ | * In this case no need to save the depth buffer. */ | ||||
| eGPUFrameBufferBits bits = GPU_COLOR_BIT | (!wpd->is_playback ? GPU_DEPTH_BIT : 0); | eGPUFrameBufferBits bits = GPU_COLOR_BIT | (!wpd->is_playback ? GPU_DEPTH_BIT : 0); | ||||
| GPU_framebuffer_blit(dfbl->default_fb, 0, fbl->antialiasing_fb, 0, bits); | GPU_framebuffer_blit(dfbl->default_fb, 0, fbl->antialiasing_fb, 0, bits); | ||||
| if (workbench_in_front_history_needed(vedata)) { | |||||
| GPU_framebuffer_blit(dfbl->in_front_fb, 0, fbl->antialiasing_in_front_fb, 0, GPU_DEPTH_BIT); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| /* Accumulate result to the TAA buffer. */ | /* Accumulate result to the TAA buffer. */ | ||||
| GPU_framebuffer_bind(fbl->antialiasing_fb); | GPU_framebuffer_bind(fbl->antialiasing_fb); | ||||
| DRW_draw_pass(psl->aa_accum_ps); | DRW_draw_pass(psl->aa_accum_ps); | ||||
| /* Copy back the saved depth buffer for correct overlays. */ | /* Copy back the saved depth buffer for correct overlays. */ | ||||
| GPU_framebuffer_blit(fbl->antialiasing_fb, 0, dfbl->default_fb, 0, GPU_DEPTH_BIT); | GPU_framebuffer_blit(fbl->antialiasing_fb, 0, dfbl->default_fb, 0, GPU_DEPTH_BIT); | ||||
| if (workbench_in_front_history_needed(vedata)) { | |||||
| GPU_framebuffer_blit(fbl->antialiasing_in_front_fb, 0, dfbl->in_front_fb, 0, GPU_DEPTH_BIT); | |||||
| } | |||||
| } | } | ||||
| if (!DRW_state_is_image_render() || wpd->taa_sample + 1 == wpd->taa_sample_len) { | if (!DRW_state_is_image_render() || wpd->taa_sample + 1 == wpd->taa_sample_len) { | ||||
| /* After a certain point SMAA is no longer necessary. */ | /* After a certain point SMAA is no longer necessary. */ | ||||
| wpd->smaa_mix_factor = 1.0f - clamp_f(wpd->taa_sample / 4.0f, 0.0f, 1.0f); | wpd->smaa_mix_factor = 1.0f - clamp_f(wpd->taa_sample / 4.0f, 0.0f, 1.0f); | ||||
| wpd->taa_sample_inv = 1.0f / (wpd->taa_sample + 1); | wpd->taa_sample_inv = 1.0f / (wpd->taa_sample + 1); | ||||
| if (wpd->smaa_mix_factor > 0.0f) { | if (wpd->smaa_mix_factor > 0.0f) { | ||||
| Show All 17 Lines | |||||