diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-06-27 15:33:10 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2018-06-27 15:36:01 +0300 |
commit | 310796214fadf1d98e07ee17d20a0427ef36b122 (patch) | |
tree | ce49aa2bb22c0f9a9b1f9d2a68f11be53146e0fa /source/blender/draw | |
parent | d48600fddc5ca629e8a52639a6606977aa5fd35a (diff) |
Workbench: Use different samples in AO per TAA iteration
Per iteration a different AO samples are used, so the final result is
less distorted. Will improve the quality of the image a lot when the
cavity option is turned on.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl | 2 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_deferred.c | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl index a5a5b9e49ba..7b77139fb6c 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl @@ -32,7 +32,7 @@ void ssao_factors( vec2 rotY = vec2(-rotX.y, rotX.x); for (int x = 0; x < num_samples; x++) { - int sample_index = x; + int sample_index = x + (int(ssao_iteration) * num_samples); if (sample_index > 500) { continue; } diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 17470dada39..d5505bf76d0 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -212,18 +212,20 @@ static void select_deferred_shaders(WORKBENCH_PrivateData *wpd) /* Using Hammersley distribution */ -static float *create_disk_samples(int num_samples) +static float *create_disk_samples(int num_samples, int num_iterations) { /* vec4 to ensure memory alignment. */ - float (*texels)[4] = MEM_mallocN(sizeof(float[4]) * num_samples, __func__); + const int total_samples = num_samples * num_iterations; + float (*texels)[4] = MEM_mallocN(sizeof(float[4]) * total_samples, __func__); const float num_samples_inv = 1.0f / num_samples; - for (int i = 0; i < num_samples; i++) { - float r = (i + 0.5f) * num_samples_inv; + for (int i = 0; i < total_samples; i++) { + float it_add = (i / num_samples) * 0.499f; + float r = fmodf((i + 0.5f + it_add) * num_samples_inv, 1.0f); double dphi; BLI_hammersley_1D(i, &dphi); - float phi = (float)dphi * 2.0f * M_PI; + float phi = (float)dphi * 2.0f * M_PI + it_add; texels[i][0] = cosf(phi); texels[i][1] = sinf(phi); /* This deliberatly distribute more samples @@ -381,15 +383,18 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) const DRWContextState *draw_ctx = DRW_context_state_get(); Scene *scene = draw_ctx->scene; /* AO Samples Tex */ + int num_iterations = workbench_taa_calculate_num_iterations(vedata); + const int ssao_samples_single_iteration = scene->display.matcap_ssao_samples; - const int ssao_samples = MIN2(ssao_samples_single_iteration, 500); + const int ssao_samples = MIN2(num_iterations * ssao_samples_single_iteration, 500); + if (e_data.sampling_ubo && (e_data.cached_sample_num != ssao_samples)) { DRW_UBO_FREE_SAFE(e_data.sampling_ubo); DRW_TEXTURE_FREE_SAFE(e_data.jitter_tx); } if (e_data.sampling_ubo == NULL) { - float *samples = create_disk_samples(ssao_samples); + float *samples = create_disk_samples(ssao_samples_single_iteration, num_iterations); e_data.jitter_tx = create_jitter_texture(ssao_samples); e_data.sampling_ubo = DRW_uniformbuffer_create(sizeof(float[4]) * ssao_samples, samples); e_data.cached_sample_num = ssao_samples; |