21 |
|
#include "ambient.h" |
22 |
|
#include "random.h" |
23 |
|
|
24 |
< |
#ifdef NEWAMB |
24 |
> |
#ifndef OLDAMB |
25 |
|
|
26 |
|
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
27 |
|
|
68 |
|
setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); |
69 |
|
else |
70 |
|
copycolor(ar.rcoef, hp->acoef); |
71 |
< |
if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0) { |
72 |
< |
if (!n) memset(ap, 0, sizeof(AMBSAMP)); |
71 |
> |
if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0) |
72 |
|
return(0); |
74 |
– |
} |
73 |
|
if (ambacc > FTINY) { |
74 |
|
multcolor(ar.rcoef, hp->acoef); |
75 |
|
scalecolor(ar.rcoef, 1./AVGREFL); |
78 |
|
hlist[1] = j; |
79 |
|
hlist[2] = i; |
80 |
|
multisamp(spt, 2, urand(ilhash(hlist,3)+n)); |
81 |
< |
if (!n) { /* avoid border samples for n==0 */ |
81 |
> |
/* avoid coincident samples */ |
82 |
> |
if (!n && (0 < i) & (i < hp->ns-1) && |
83 |
> |
(0 < j) & (j < hp->ns-1)) { |
84 |
|
if ((spt[0] < 0.1) | (spt[0] >= 0.9)) |
85 |
|
spt[0] = 0.1 + 0.8*frandom(); |
86 |
|
if ((spt[1] < 0.1) | (spt[1] >= 0.9)) |
99 |
|
if (ar.rt <= FTINY) |
100 |
|
return(0); /* should never happen */ |
101 |
|
multcolor(ar.rcol, ar.rcoef); /* apply coefficient */ |
102 |
< |
if (!n || ar.rt*ap->d < 1.0) /* new/closer distance? */ |
102 |
> |
if (ar.rt*ap->d < 1.0) /* new/closer distance? */ |
103 |
|
ap->d = 1.0/ar.rt; |
104 |
|
if (!n) { /* record first vertex & value */ |
105 |
|
if (ar.rt > 10.0*thescene.cusize) |
180 |
|
float *earr = getambdiffs(hp); |
181 |
|
double e2rem = 0; |
182 |
|
AMBSAMP *ap; |
183 |
– |
RAY ar; |
183 |
|
float *ep; |
184 |
|
int i, j, n, nss; |
185 |
|
|
194 |
|
if (e2rem <= FTINY) |
195 |
|
goto done; /* nothing left to do */ |
196 |
|
nss = *ep/e2rem*cnt + frandom(); |
197 |
< |
for (n = 1; n <= nss; n++) |
198 |
< |
cnt -= ambsample(hp, i, j, n); |
197 |
> |
for (n = 1; n <= nss && ambsample(hp,i,j,n); n++) |
198 |
> |
--cnt; |
199 |
|
e2rem -= *ep++; /* update remainder */ |
200 |
|
} |
201 |
|
done: |
228 |
|
hp->rp = r; |
229 |
|
hp->ns = n; |
230 |
|
hp->acol[RED] = hp->acol[GRN] = hp->acol[BLU] = 0.0; |
231 |
+ |
memset(hp->sa, 0, sizeof(AMBSAMP)*n*n); |
232 |
|
hp->sampOK = 0; |
233 |
|
/* assign coefficient */ |
234 |
|
copycolor(hp->acoef, rcol); |
235 |
|
d = 1.0/(n*n); |
236 |
|
scalecolor(hp->acoef, d); |
237 |
|
/* make tangent plane axes */ |
238 |
< |
hp->uy[0] = 0.5 - frandom(); |
239 |
< |
hp->uy[1] = 0.5 - frandom(); |
240 |
< |
hp->uy[2] = 0.5 - frandom(); |
241 |
< |
for (i = 3; i--; ) |
242 |
< |
if ((-0.6 < r->ron[i]) & (r->ron[i] < 0.6)) |
243 |
< |
break; |
244 |
< |
if (i < 0) |
238 |
> |
if (!getperpendicular(hp->ux, r->ron, 1)) |
239 |
|
error(CONSISTENCY, "bad ray direction in samp_hemi"); |
246 |
– |
hp->uy[i] = 1.0; |
247 |
– |
VCROSS(hp->ux, hp->uy, r->ron); |
248 |
– |
normalize(hp->ux); |
240 |
|
VCROSS(hp->uy, r->ron, hp->ux); |
241 |
|
/* sample divisions */ |
242 |
|
for (i = hp->ns; i--; ) |
600 |
|
ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, const double r1) |
601 |
|
{ |
602 |
|
const double max_d = 1.0/(minarad*ambacc + 0.001); |
603 |
< |
const double ang_res = 0.5*PI/(hp->ns-1); |
604 |
< |
const double ang_step = ang_res/((int)(16/PI*ang_res) + (1+FTINY)); |
603 |
> |
const double ang_res = 0.5*PI/hp->ns; |
604 |
> |
const double ang_step = ang_res/((int)(16/PI*ang_res) + 1.01); |
605 |
|
double avg_d = 0; |
606 |
|
uint32 flgs = 0; |
607 |
|
FVECT vec; |
608 |
< |
double d, u, v; |
608 |
> |
double u, v; |
609 |
|
double ang, a1; |
610 |
|
int i, j; |
611 |
|
/* don't bother for a few samples */ |
627 |
|
if ((ap->d <= FTINY) | (ap->d >= max_d)) |
628 |
|
continue; /* too far or too near */ |
629 |
|
VSUB(vec, ap->p, hp->rp->rop); |
630 |
< |
d = DOT(vec, hp->rp->ron); |
631 |
< |
d = 1.0/sqrt(DOT(vec,vec) - d*d); |
632 |
< |
u = DOT(vec, uv[0]) * d; |
642 |
< |
v = DOT(vec, uv[1]) * d; |
643 |
< |
if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= 1.0) |
630 |
> |
u = DOT(vec, uv[0]); |
631 |
> |
v = DOT(vec, uv[1]); |
632 |
> |
if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= u*u + v*v) |
633 |
|
continue; /* occluder outside ellipse */ |
634 |
|
ang = atan2a(v, u); /* else set direction flags */ |
635 |
< |
for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step) |
635 |
> |
for (a1 = ang-ang_res; a1 <= ang+ang_res; a1 += ang_step) |
636 |
|
flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); |
637 |
|
} |
638 |
|
/* add low-angle incident (< 20deg) */ |
685 |
|
return(0); |
686 |
|
|
687 |
|
if ((ra == NULL) & (pg == NULL) & (dg == NULL) || |
688 |
< |
(hp->sampOK < 0) | (hp->ns < 4)) { |
688 |
> |
(hp->sampOK < 0) | (hp->ns < 6)) { |
689 |
|
free(hp); /* Hessian not requested/possible */ |
690 |
|
return(-1); /* value-only return value */ |
691 |
|
} |