51 |
|
#define MAX_SORT_INTVL (SORT_INTVL<<6) |
52 |
|
#endif |
53 |
|
|
54 |
+ |
|
55 |
+ |
static double qambacc = 0.; /* ambient accuracy to the 1/4 power */ |
56 |
|
static double avsum = 0.; /* computed ambient value sum (log) */ |
57 |
|
static unsigned int navsum = 0; /* number of values in avsum */ |
58 |
|
static unsigned int nambvals = 0; /* total number of indirect values */ |
134 |
|
if (newa < 0.0) |
135 |
|
newa = 0.0; |
136 |
|
ambdiff = fabs(newa - ambacc); |
137 |
< |
if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0) |
138 |
< |
sortambvals(1); /* rebuild tree */ |
137 |
> |
if (ambdiff >= .01 && (ambacc = newa) > FTINY) { |
138 |
> |
qambacc = sqrt(sqrt(ambacc)); |
139 |
> |
if (nambvals > 0) |
140 |
> |
sortambvals(1); /* rebuild tree */ |
141 |
> |
} |
142 |
|
} |
143 |
|
|
144 |
|
|
152 |
|
ambdone(); |
153 |
|
/* init ambient limits */ |
154 |
|
setambres(ambres); |
155 |
< |
setambacc(ambacc); |
155 |
> |
qambacc = sqrt(sqrt(ambacc *= (ambacc > FTINY))); |
156 |
|
if (ambfile == NULL || !ambfile[0]) |
157 |
|
return; |
158 |
|
if (ambacc <= FTINY) { |
325 |
|
ok = makeambient(acol, r, nrm, rdepth-1); |
326 |
|
rdepth--; |
327 |
|
if (ok) { |
328 |
< |
multcolor(aval, acol); /* got new value */ |
328 |
> |
multcolor(aval, acol); /* computed new value */ |
329 |
|
return; |
330 |
|
} |
331 |
|
dumbamb: /* return global value */ |
357 |
|
FVECT c0, |
358 |
|
double s |
359 |
|
) |
360 |
< |
{ /* initial limit is ambacc radians */ |
361 |
< |
const double maxangle = (ambacc-PI/2.)*pow(r->rweight,0.13) + PI/2.; |
360 |
> |
{ /* initial limit is 5 degrees plus ambacc radians */ |
361 |
> |
const double minangle = 5.0 * PI/180.; |
362 |
> |
const double maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13) |
363 |
> |
+ PI/2.; |
364 |
|
double wsum = 0.0; |
365 |
|
FVECT ck0; |
366 |
|
int i, j; |
400 |
|
delta_t2 = d*d; |
401 |
|
d = DOT(ck0, uvw[1]) / av->rad[1]; |
402 |
|
delta_t2 += d*d; |
403 |
< |
if (delta_t2 >= ambacc*ambacc) |
403 |
> |
if (delta_t2 >= qambacc*qambacc) |
404 |
|
continue; |
405 |
|
/* |
406 |
|
* Intersection behind test |
408 |
|
d = 0.0; |
409 |
|
for (j = 0; j < 3; j++) |
410 |
|
d += (r->rop[j] - av->pos[j])*(uvw[2][j] + r->ron[j]); |
411 |
< |
if (d*0.5 < -minarad*ambacc-.001) |
411 |
> |
if (d*0.5 < -minarad*qambacc-.001) |
412 |
|
continue; |
413 |
|
/* |
414 |
|
* Extrapolate value and compute final weight (hat function) |
415 |
|
*/ |
416 |
|
extambient(ct, av, r->rop, rn, uvw); |
417 |
|
d = tfunc(maxangle, sqrt(delta_r2), 0.0) * |
418 |
< |
tfunc(ambacc, sqrt(delta_t2), 0.0); |
418 |
> |
tfunc(qambacc, sqrt(delta_t2), 0.0); |
419 |
|
scalecolor(ct, d); |
420 |
|
addcolor(acol, ct); |
421 |
|
wsum += d; |
461 |
|
amb.weight = 1.25*r->rweight; |
462 |
|
setcolor(acol, AVGREFL, AVGREFL, AVGREFL); |
463 |
|
/* compute ambient */ |
464 |
< |
if (!doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir)) { |
458 |
< |
setcolor(acol, 0.0, 0.0, 0.0); |
459 |
< |
return(0); |
460 |
< |
} |
464 |
> |
i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir); |
465 |
|
scalecolor(acol, 1./AVGREFL); /* undo assumed reflectance */ |
466 |
+ |
if (i <= 0 || amb.rad[0] <= FTINY) /* no Hessian or zero radius */ |
467 |
+ |
return(i); |
468 |
|
/* store value */ |
469 |
|
VCOPY(amb.pos, r->rop); |
470 |
|
amb.ndir = encodedir(r->ron); |
536 |
|
at = &atrunk; |
537 |
|
VCOPY(ck0, thescene.cuorg); |
538 |
|
s = thescene.cusize; |
539 |
< |
while (s*(OCTSCALE/2) > av->rad[1]*ambacc) { |
539 |
> |
while (s*(OCTSCALE/2) > av->rad[1]*qambacc) { |
540 |
|
if (at->kid == NULL) |
541 |
|
if ((at->kid = newambtree()) == NULL) |
542 |
|
error(SYSTEM, "out of memory in avinsert"); |