Skip to content

Commit

Permalink
perf: put maximum cap on gradient values to avoid over-extrapolation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Feb 19, 2021
1 parent e8a7d22 commit 8749da3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/notes/ReleaseNotes
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 5 additions & 2 deletions src/rt/ambient.c
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 8749da3

Please sign in to comment.