From ed779333bb82a483c3f7833b959610c08f0bacb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 7 Sep 2019 00:44:07 +0200 Subject: EEVEE: Shadows: Fix correlation issue between Shadows and Anti-Aliasing To fix this, we just scramble the halton sequence by multiplying by a large prime number. It seems to work fine in practice. We also tried Sobol sequence but it has a less uniform pattern for low number of sample. Fix T68594 Eevee: Soft shadows causing flickering in animation and temporal AA in scenes --- source/blender/draw/engines/eevee/eevee_sampling.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source') diff --git a/source/blender/draw/engines/eevee/eevee_sampling.c b/source/blender/draw/engines/eevee/eevee_sampling.c index 9d91e000562..39a0358cb6c 100644 --- a/source/blender/draw/engines/eevee/eevee_sampling.c +++ b/source/blender/draw/engines/eevee/eevee_sampling.c @@ -38,6 +38,11 @@ void EEVEE_sample_ball(int sample_ofs, float radius, float rsample[3]) BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point); + /* Decorelate AA and shadow samples. (see T68594) */ + ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0); + ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0); + ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0); + float omega = ht_point[1] * 2.0f * M_PI; rsample[2] = ht_point[0] * 2.0f - 1.0f; /* cos theta */ @@ -64,6 +69,10 @@ void EEVEE_sample_rectangle(int sample_ofs, BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point); + /* Decorelate AA and shadow samples. (see T68594) */ + ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0); + ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0); + /* Change ditribution center to be 0,0 */ ht_point[0] = (ht_point[0] > 0.5f) ? ht_point[0] - 1.0f : ht_point[0]; ht_point[1] = (ht_point[1] > 0.5f) ? ht_point[1] - 1.0f : ht_point[1]; @@ -86,6 +95,10 @@ void EEVEE_sample_ellipse(int sample_ofs, BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point); + /* Decorelate AA and shadow samples. (see T68594) */ + ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0); + ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0); + /* Uniform disc sampling. */ float omega = ht_point[1] * 2.0f * M_PI; float r = sqrtf(ht_point[0]); @@ -105,6 +118,11 @@ void EEVEE_random_rotation_m4(int sample_ofs, float scale, float r_mat[4][4]) BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point); + /* Decorelate AA and shadow samples. (see T68594) */ + ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0); + ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0); + ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0); + rotate_m4(r_mat, 'X', ht_point[0] * scale); rotate_m4(r_mat, 'Y', ht_point[1] * scale); rotate_m4(r_mat, 'Z', ht_point[2] * scale); -- cgit v1.2.3