Workbench: TAA optimalization

First frame of the TAA is just a regular copy of the previous buffer. so
we write directly to the final buffer and skip the taa shader. We do
init the history buffer via blit so it will be initialized for the other
iterations.
This commit is contained in:
Jeroen Bakker 2018-06-29 09:22:50 +02:00
parent 18d87e79e9
commit 3169160a97
4 changed files with 25 additions and 24 deletions

View File

@ -8,14 +8,7 @@ uniform float mixFactor;
void main()
{
ivec2 texel = ivec2(gl_FragCoord.xy);
vec4 color_buffer = texelFetch(colorBuffer, texel, 0);
if (mixFactor == 1.0)
{
colorOutput = color_buffer;
}
else {
vec4 history_buffer = texelFetch(historyBuffer, texel, 0);
colorOutput = mix(history_buffer, color_buffer, mixFactor);
}
vec4 history_buffer = texelFetch(historyBuffer, texel, 0);
colorOutput = mix(history_buffer, color_buffer, mixFactor);
}

View File

@ -61,11 +61,23 @@ void workbench_aa_draw_pass(WORKBENCH_Data *vedata, GPUTexture *tx)
DRW_draw_pass(psl->effect_aa_pass);
}
else if (TAA_ENABLED(wpd)) {
GPU_framebuffer_bind(fbl->effect_fb);
DRW_transform_to_display(tx);
GPU_framebuffer_bind(dfbl->color_only_fb);
workbench_taa_draw_pass(effect_info, psl->effect_aa_pass);
/*
* when drawing the first TAA frame, we transform directly to the
* color_only_fb as the TAA shader is just performing a direct copy.
* the workbench_taa_draw_screen_end will fill the history buffer
* for the other iterations.
*/
if (effect_info->jitter_index == 1)
{
GPU_framebuffer_bind(dfbl->color_only_fb);
DRW_transform_to_display(tx);
}
else {
GPU_framebuffer_bind(fbl->effect_fb);
DRW_transform_to_display(tx);
GPU_framebuffer_bind(dfbl->color_only_fb);
DRW_draw_pass(psl->effect_aa_pass);
}
workbench_taa_draw_scene_end(vedata);
}
else {

View File

@ -56,6 +56,7 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num)
/* move jitter table so that closest sample is in center */
for (int index = 0; index < num; index++) {
sub_v2_v2(table[index], table[closest_index]);
mul_v2_fl(table[index], 2.0f);
}
/* swap center sample to the start of the table */
@ -104,7 +105,8 @@ int workbench_taa_calculate_num_iterations(WORKBENCH_Data *vedata)
{
result = 16;
}
else {
else
{
result = 32;
}
}
@ -203,11 +205,12 @@ void workbench_taa_draw_scene_start(WORKBENCH_Data *vedata)
WORKBENCH_EffectInfo *effect_info = stl->effects;
const float *viewport_size = DRW_viewport_size_get();
int num_samples = 8;
float (*samples)[2] = e_data.jitter_8;
float (*samples)[2];
float mix_factor;
num_samples = workbench_taa_calculate_num_iterations(vedata);
switch (num_samples) {
default:
case 8:
samples = e_data.jitter_8;
break;
@ -215,7 +218,6 @@ void workbench_taa_draw_scene_start(WORKBENCH_Data *vedata)
samples = e_data.jitter_16;
break;
case 32:
default:
samples = e_data.jitter_32;
break;
}
@ -262,9 +264,9 @@ void workbench_taa_draw_scene_end(WORKBENCH_Data *vedata)
* default depth buffer
*/
const WORKBENCH_StorageList *stl = vedata->stl;
const WORKBENCH_EffectInfo *effect_info = stl->effects;
const WORKBENCH_FramebufferList *fbl = vedata->fbl;
const DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
WORKBENCH_EffectInfo *effect_info = stl->effects;
if (effect_info->jitter_index == 1) {
GPU_framebuffer_blit(dfbl->depth_only_fb, 0, fbl->depth_buffer_fb, 0, GPU_DEPTH_BIT);
@ -276,11 +278,6 @@ void workbench_taa_draw_scene_end(WORKBENCH_Data *vedata)
GPU_framebuffer_blit(dfbl->color_only_fb, 0, fbl->effect_taa_fb, 0, GPU_COLOR_BIT);
DRW_viewport_matrix_override_unset_all();
}
void workbench_taa_draw_pass(WORKBENCH_EffectInfo *effect_info, DRWPass *pass)
{
DRW_draw_pass(pass);
copy_m4_m4(effect_info->last_mat, effect_info->curr_mat);
if (effect_info->jitter_index != 0) {

View File

@ -257,7 +257,6 @@ DRWPass *workbench_fxaa_create_pass(GPUTexture **color_buffer_tx);
void workbench_taa_engine_init(WORKBENCH_Data *vedata);
void workbench_taa_engine_free(void);
DRWPass *workbench_taa_create_pass(WORKBENCH_Data *vedata, GPUTexture **color_buffer_tx);
void workbench_taa_draw_pass(WORKBENCH_EffectInfo *effect_info, /*WORKBENCH_PrivateData *wpd, , GPUFrameBuffer *fb, GPUTexture *tx, */DRWPass *effect_aa_pass);
void workbench_taa_draw_scene_start(WORKBENCH_Data *vedata);
void workbench_taa_draw_scene_end(WORKBENCH_Data *vedata);
void workbench_taa_view_updated(WORKBENCH_Data *vedata);