272 |
|
FVECT nrm |
273 |
|
) |
274 |
|
{ |
275 |
+ |
static double logAvgAbsorp = 1; |
276 |
|
static int rdepth = 0; /* ambient recursion */ |
277 |
|
COLOR acol, caustic; |
278 |
|
int i, ok; |
284 |
|
if (ambPmap(aval, r, rdepth)) |
285 |
|
return; |
286 |
|
|
287 |
+ |
if (logAvgAbsorp > 0) /* exclude in -aw to avoid growth */ |
288 |
+ |
logAvgAbsorp = log(1.-AVGREFL); |
289 |
+ |
|
290 |
|
/* PMAP: Factor in specular-diffuse ambient (caustics) from photon |
291 |
|
* map, if enabled and ray is primary, else caustic is zero. Continue |
292 |
|
* with RADIANCE ambient calculation */ |
372 |
|
|
373 |
|
l = bright(ambval); /* average in computations */ |
374 |
|
if (l > FTINY) { |
375 |
< |
d = (log(l)*(double)ambvwt + avsum) / |
375 |
> |
d = (log(l)*(double)ambvwt + avsum + logAvgAbsorp*navsum) / |
376 |
|
(double)(ambvwt + navsum); |
377 |
|
d = exp(d) / l; |
378 |
|
scalecolor(aval, d); |
379 |
|
multcolor(aval, ambval); /* apply color of ambval */ |
380 |
|
} else { |
381 |
< |
d = exp( avsum / (double)navsum ); |
381 |
> |
d = exp( avsum/(double)navsum + logAvgAbsorp ); |
382 |
|
scalecolor(aval, d); /* neutral color */ |
383 |
|
} |
384 |
|
} |
587 |
|
) |
588 |
|
{ |
589 |
|
const double min_d = 0.05; |
590 |
+ |
const double max_d = 20.; |
591 |
|
static FVECT my_uvw[3]; |
592 |
|
FVECT v1; |
593 |
|
int i; |
607 |
|
for (i = 3; i--; ) |
608 |
|
d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); |
609 |
|
|
610 |
< |
if (d < min_d) /* should not use if we can avoid it */ |
610 |
> |
if (d < min_d) /* clamp min/max scaling */ |
611 |
|
d = min_d; |
612 |
+ |
else if (d > max_d) |
613 |
+ |
d = max_d; |
614 |
|
copycolor(cr, ap->val); |
615 |
|
scalecolor(cr, d); |
616 |
|
return(d > min_d); |
982 |
|
|
983 |
|
if (typ == fls.l_type) /* already called? */ |
984 |
|
return; |
985 |
+ |
|
986 |
|
fls.l_type = typ; |
987 |
< |
if (fcntl(fileno(ambfp), F_SETLKW, &fls) < 0) |
988 |
< |
error(SYSTEM, "cannot (un)lock ambient file"); |
987 |
> |
do |
988 |
> |
if (fcntl(fileno(ambfp), F_SETLKW, &fls) != -1) |
989 |
> |
return; |
990 |
> |
while (errno == EINTR); |
991 |
> |
|
992 |
> |
error(SYSTEM, "cannot (un)lock ambient file"); |
993 |
|
} |
994 |
|
|
995 |
|
|