109 |
|
/* set min & max radii */ |
110 |
|
if (ar <= 0) { |
111 |
|
minarad = 0; |
112 |
< |
maxarad = thescene.cusize*0.5; |
112 |
> |
maxarad = thescene.cusize*0.2; |
113 |
|
} else { |
114 |
|
minarad = thescene.cusize / ar; |
115 |
|
maxarad = 64.0 * minarad; /* heuristic */ |
116 |
< |
if (maxarad > thescene.cusize*0.5) |
117 |
< |
maxarad = thescene.cusize*0.5; |
116 |
> |
if (maxarad > thescene.cusize*0.2) |
117 |
> |
maxarad = thescene.cusize*0.2; |
118 |
|
} |
119 |
|
if (minarad <= FTINY) |
120 |
|
minarad = 10.0*FTINY; |
165 |
|
initambfile(0); /* file exists */ |
166 |
|
lastpos = ftell(ambfp); |
167 |
|
while (readambval(&amb, ambfp)) |
168 |
< |
avinsert(avstore(&amb)); |
168 |
> |
avstore(&amb); |
169 |
|
nambshare = nambvals; /* share loaded values */ |
170 |
|
if (readonly) { |
171 |
|
sprintf(errmsg, |
263 |
|
|
264 |
|
/************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/ |
265 |
|
|
266 |
< |
#ifdef NEWAMB |
266 |
> |
#ifndef OLDAMB |
267 |
|
|
268 |
|
#define tfunc(lwr, x, upr) (((x)-(lwr))/((upr)-(lwr))) |
269 |
|
|
271 |
|
static double sumambient(COLOR acol, RAY *r, FVECT rn, int al, |
272 |
|
AMBTREE *at, FVECT c0, double s); |
273 |
|
static int makeambient(COLOR acol, RAY *r, FVECT rn, int al); |
274 |
< |
static void extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
274 |
> |
static int extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, |
275 |
|
FVECT uvw[3]); |
276 |
|
|
277 |
|
void |
443 |
|
/* |
444 |
|
* Ambient level test |
445 |
|
*/ |
446 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
446 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
447 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
448 |
|
break; |
448 |
– |
if (av->weight < 0.9*r->rweight) |
449 |
– |
continue; |
449 |
|
/* |
450 |
|
* Direction test using unperturbed normal |
451 |
|
*/ |
486 |
|
/* |
487 |
|
* Extrapolate value and compute final weight (hat function) |
488 |
|
*/ |
489 |
< |
extambient(ct, av, r->rop, rn, uvw); |
489 |
> |
if (!extambient(ct, av, r->rop, rn, uvw)) |
490 |
> |
continue; |
491 |
|
d = tfunc(maxangle, sqrt(delta_r2), 0.0) * |
492 |
|
tfunc(ambacc, sqrt(delta_t2), 0.0); |
493 |
|
scalecolor(ct, d); |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
< |
static void |
541 |
> |
static int |
542 |
|
extambient( /* extrapolate value at pv, nv */ |
543 |
|
COLOR cr, |
544 |
|
AMBVAL *ap, |
547 |
|
FVECT uvw[3] |
548 |
|
) |
549 |
|
{ |
550 |
+ |
const double min_d = 0.05; |
551 |
|
static FVECT my_uvw[3]; |
552 |
|
FVECT v1; |
553 |
|
int i; |
567 |
|
for (i = 3; i--; ) |
568 |
|
d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); |
569 |
|
|
570 |
< |
if (d <= 0.0) { |
571 |
< |
setcolor(cr, 0.0, 0.0, 0.0); |
571 |
< |
return; |
572 |
< |
} |
570 |
> |
if (d < min_d) /* should not use if we can avoid it */ |
571 |
> |
d = min_d; |
572 |
|
copycolor(cr, ap->val); |
573 |
|
scalecolor(cr, d); |
574 |
+ |
return(d > min_d); |
575 |
|
} |
576 |
|
|
577 |
|
|
608 |
|
} |
609 |
|
avh.next = at->alist; /* order by increasing level */ |
610 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
611 |
< |
if (ap->next->lvl >= av->lvl) |
611 |
> |
if ( ap->next->lvl > av->lvl || |
612 |
> |
(ap->next->lvl == av->lvl) & |
613 |
> |
(ap->next->weight <= av->weight) ) |
614 |
|
break; |
615 |
|
av->next = ap->next; |
616 |
|
ap->next = (AMBVAL*)av; |
723 |
|
/* |
724 |
|
* Ambient level test. |
725 |
|
*/ |
726 |
< |
if (av->lvl > al) /* list sorted, so this works */ |
726 |
> |
if (av->lvl > al || /* list sorted, so this works */ |
727 |
> |
(av->lvl == al) & (av->weight < 0.9*r->rweight)) |
728 |
|
break; |
726 |
– |
if (av->weight < 0.9*r->rweight) |
727 |
– |
continue; |
729 |
|
/* |
730 |
|
* Ambient radius test. |
731 |
|
*/ |
907 |
|
} |
908 |
|
avh.next = at->alist; /* order by increasing level */ |
909 |
|
for (ap = &avh; ap->next != NULL; ap = ap->next) |
910 |
< |
if (ap->next->lvl >= av->lvl) |
910 |
> |
if ( ap->next->lvl > av->lvl || |
911 |
> |
(ap->next->lvl == av->lvl) & |
912 |
> |
(ap->next->weight <= av->weight) ) |
913 |
|
break; |
914 |
|
av->next = ap->next; |
915 |
|
ap->next = (AMBVAL*)av; |
961 |
|
AMBVAL *av |
962 |
|
) |
963 |
|
{ |
964 |
< |
avinsert(avstore(av)); |
964 |
> |
avstore(av); |
965 |
|
if (ambfp == NULL) |
966 |
|
return; |
967 |
|
if (writambval(av, ambfp) < 0) |
976 |
|
|
977 |
|
|
978 |
|
static AMBVAL * |
979 |
< |
avstore( /* allocate memory and store aval */ |
979 |
> |
avstore( /* allocate memory and save aval */ |
980 |
|
AMBVAL *aval |
981 |
|
) |
982 |
|
{ |
994 |
|
avsum += log(d); |
995 |
|
navsum++; |
996 |
|
} |
997 |
+ |
avinsert(av); /* insert in our cache tree */ |
998 |
|
return(av); |
999 |
|
} |
1000 |
|
|
1195 |
|
if (i_avlist < nambvals) |
1196 |
|
error(CONSISTENCY, "missing ambient values in sortambvals"); |
1197 |
|
#endif |
1198 |
< |
qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp); |
1199 |
< |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp); |
1198 |
> |
qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp); |
1199 |
> |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1200 |
|
for (i = 0; i < nambvals; i++) { |
1201 |
|
if (avlist1[i].p == NULL) |
1202 |
|
continue; |
1277 |
|
error(WARNING, errmsg); |
1278 |
|
break; |
1279 |
|
} |
1280 |
< |
avinsert(avstore(&avs)); |
1280 |
> |
avstore(&avs); |
1281 |
|
n -= AMBVALSIZ; |
1282 |
|
} |
1283 |
|
lastpos = flen - n; |