From 8749da357e7d923e032de27e9a1fa2878cfe9851 Mon Sep 17 00:00:00 2001 From: "Gregory J. Ward" Date: Fri, 19 Feb 2021 22:05:46 +0000 Subject: [PATCH] perf: put maximum cap on gradient values to avoid over-extrapolation --- doc/notes/ReleaseNotes | 3 +++ src/rt/ambient.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/notes/ReleaseNotes b/doc/notes/ReleaseNotes index 9a93cba33..255539ce9 100644 --- a/doc/notes/ReleaseNotes +++ b/doc/notes/ReleaseNotes @@ -2420,3 +2420,6 @@ Thanks to Helen Rose Wilson for the suggestion and informing me that such a thing exists. Removed upper limit on number of modifiers in rcontrib. + +Put cap on maximum ambient gradient to avoid over-extrapolation of +poorly computed irradiance cache values. diff --git a/src/rt/ambient.c b/src/rt/ambient.c index 7cff4149e..a5f8e1554 100644 --- a/src/rt/ambient.c +++ b/src/rt/ambient.c @@ -1,4 +1,4 @@ -static const char RCSid[] = "$Id: ambient.c,v 2.109 2020/03/10 15:57:52 greg Exp $"; +static const char RCSid[] = "$Id: ambient.c,v 2.110 2021/02/19 22:05:46 greg Exp $"; /* * ambient.c - routines dealing with ambient (inter-reflected) component. * @@ -583,6 +583,7 @@ extambient( /* extrapolate value at pv, nv */ ) { const double min_d = 0.05; + const double max_d = 20.; static FVECT my_uvw[3]; FVECT v1; int i; @@ -602,8 +603,10 @@ extambient( /* extrapolate value at pv, nv */ for (i = 3; i--; ) d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); - if (d < min_d) /* should not use if we can avoid it */ + if (d < min_d) /* clamp min/max scaling */ d = min_d; + else if (d > max_d) + d = max_d; copycolor(cr, ap->val); scalecolor(cr, d); return(d > min_d);