From 32ca8e58a374dc28df0b0a744e407a8ebf58e56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 24 Feb 2021 11:36:16 +0100 Subject: Workbench: Fix samples taken outside of pixel footprint With the previous implementation, we could have pixels with offset larger than 1 pixel. Also fix a bug when the closest_index is not last. The sample positions were incorrect in this case. --- .../draw/engines/workbench/workbench_effect_antialiasing.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c index 77fdbde99ef..84cc4359aa6 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c +++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c @@ -64,10 +64,17 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num) } } - /* move jitter table so that closest sample is in center */ + float closest_sample[2]; + copy_v2_v2(closest_sample, table[closest_index]); for (int index = 0; index < num; index++) { - sub_v2_v2(table[index], table[closest_index]); - mul_v2_fl(table[index], 2.0f); + /* move jitter table so that closest sample is in center */ + sub_v2_v2(table[index], closest_sample); + for (int i = 0; i < 2; i++) { + /* Avoid samples outside range (wrap arround). */ + table[index][i] = fmodf(table[index][i] + 0.5f, 1.0f); + /* Recenter the distribution[-1..1]. */ + table[index][i] += table[index][i] * 2.0f - 1.0f; + } } /* swap center sample to the start of the table */ -- cgit v1.2.3