600 |
|
const double ang_step = ang_res/((int)(16/PI*ang_res) + (1+FTINY)); |
601 |
|
double avg_d = 0; |
602 |
|
uint32 flgs = 0; |
603 |
+ |
FVECT vec; |
604 |
+ |
double u, v; |
605 |
+ |
double ang, a1; |
606 |
|
int i, j; |
607 |
|
/* don't bother for a few samples */ |
608 |
|
if (hp->ns < 12) |
620 |
|
for (i = 0; i < hp->ns; i++) |
621 |
|
for (j = 0; j < hp->ns; j += !i|(i==hp->ns-1) ? 1 : hp->ns-1) { |
622 |
|
AMBSAMP *ap = &ambsam(hp,i,j); |
620 |
– |
FVECT vec; |
621 |
– |
double u, v; |
622 |
– |
double ang, a1; |
623 |
– |
int abp; |
623 |
|
if ((ap->d <= FTINY) | (ap->d >= max_d)) |
624 |
|
continue; /* too far or too near */ |
625 |
|
VSUB(vec, ap->p, hp->rp->rop); |
631 |
|
for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step) |
632 |
|
flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); |
633 |
|
} |
634 |
+ |
/* add low-angle incident (< 20deg) */ |
635 |
+ |
if (fabs(hp->rp->rod) <= 0.342) { |
636 |
+ |
u = -DOT(hp->rp->rdir, uv[0]); |
637 |
+ |
v = -DOT(hp->rp->rdir, uv[1]); |
638 |
+ |
if ((r0*r0*u*u + r1*r1*v*v) > hp->rp->rot*hp->rp->rot) { |
639 |
+ |
ang = atan2a(v, u); |
640 |
+ |
ang += 2.*PI*(ang < 0); |
641 |
+ |
ang *= 16/PI; |
642 |
+ |
if ((ang < .5) | (ang >= 31.5)) |
643 |
+ |
flgs |= 0x80000001; |
644 |
+ |
else |
645 |
+ |
flgs |= 3L<<(int)(ang-.5); |
646 |
+ |
} |
647 |
+ |
} |
648 |
|
return(flgs); |
649 |
|
} |
650 |
|
|
689 |
|
addcolor(acol, ap->v); |
690 |
|
++cnt; |
691 |
|
} |
692 |
< |
if (!cnt) { |
693 |
< |
setcolor(rcol, 0.0, 0.0, 0.0); |
681 |
< |
free(hp); |
682 |
< |
return(0); /* no valid samples */ |
683 |
< |
} |
684 |
< |
if (cnt < hp->ns*hp->ns) { /* incomplete sampling? */ |
692 |
> |
if ((hp->ns < 4) | (cnt < hp->ns*hp->ns)) { |
693 |
> |
free(hp); /* inadequate sampling */ |
694 |
|
copycolor(rcol, acol); |
695 |
< |
free(hp); |
687 |
< |
return(-1); /* return value w/o Hessian */ |
695 |
> |
return(-cnt); /* value-only result */ |
696 |
|
} |
697 |
|
cnt = ambssamp*wt + 0.5; /* perform super-sampling? */ |
698 |
|
if (cnt > 8) |
700 |
|
copycolor(rcol, acol); /* final indirect irradiance/PI */ |
701 |
|
if ((ra == NULL) & (pg == NULL) & (dg == NULL)) { |
702 |
|
free(hp); |
703 |
< |
return(-1); /* no radius or gradient calc. */ |
703 |
> |
return(-1); /* no Hessian or gradients requested */ |
704 |
|
} |
705 |
|
if ((d = bright(acol)) > FTINY) { /* normalize Y values */ |
706 |
|
d = 0.99*(hp->ns*hp->ns)/d; |
746 |
|
ra[0] = maxarad; |
747 |
|
} |
748 |
|
/* flag encroached directions */ |
749 |
< |
if ((wt >= 0.5-FTINY) & (crlp != NULL)) |
749 |
> |
if ((wt >= 0.89*AVGREFL) & (crlp != NULL)) |
750 |
|
*crlp = ambcorral(hp, uv, ra[0]*ambacc, ra[1]*ambacc); |
751 |
|
if (pg != NULL) { /* cap gradient if necessary */ |
752 |
|
d = pg[0]*pg[0]*ra[0]*ra[0] + pg[1]*pg[1]*ra[1]*ra[1]; |