58 |
|
FVECT dv |
59 |
|
) |
60 |
|
{ |
61 |
< |
const double cos_thresh = 0.9999995; /* about 3.44 arcminutes */ |
62 |
< |
int ii, jj; |
63 |
< |
|
61 |
> |
double cos_thresh; |
62 |
> |
int ii, jj; |
63 |
> |
/* min. spacing = 1/4th division */ |
64 |
> |
cos_thresh = (PI/4.)/(double)hp->ns; |
65 |
> |
cos_thresh = 1. - .5*cos_thresh*cos_thresh; |
66 |
> |
/* check existing neighbors */ |
67 |
|
for (ii = i-1; ii <= i+1; ii++) { |
68 |
|
if (ii < 0) continue; |
69 |
|
if (ii >= hp->ns) break; |
75 |
|
if (jj >= hp->ns) break; |
76 |
|
if ((ii==i) & (jj==j)) continue; |
77 |
|
ap = &ambsam(hp,ii,jj); |
78 |
< |
if (ap->d <= .5/FHUGE) continue; |
78 |
> |
if (ap->d <= .5/FHUGE) |
79 |
> |
continue; /* no one home */ |
80 |
|
VSUB(avec, ap->p, hp->rp->rop); |
81 |
|
dprod = DOT(avec, dv); |
82 |
|
if (dprod >= cos_thresh*VLEN(avec)) |
83 |
|
return(1); /* collision */ |
84 |
|
} |
85 |
|
} |
86 |
< |
return(0); |
86 |
> |
return(0); /* nothing to worry about */ |
87 |
|
} |
88 |
|
|
89 |
|
|
126 |
|
/* avoid coincident samples */ |
127 |
|
if (!n && ambcollision(hp, i, j, ar.rdir)) { |
128 |
|
spt[0] = frandom(); spt[1] = frandom(); |
129 |
< |
goto resample; |
129 |
> |
goto resample; /* reject this sample */ |
130 |
|
} |
131 |
|
dimlist[ndims++] = AI(hp,i,j) + 90171; |
132 |
|
rayvalue(&ar); /* evaluate ray */ |
137 |
|
if (ar.rt*ap->d < 1.0) /* new/closer distance? */ |
138 |
|
ap->d = 1.0/ar.rt; |
139 |
|
if (!n) { /* record first vertex & value */ |
140 |
< |
if (ar.rt > 10.0*thescene.cusize) |
141 |
< |
ar.rt = 10.0*thescene.cusize; |
140 |
> |
if (ar.rt > 10.0*thescene.cusize + 1000.) |
141 |
> |
ar.rt = 10.0*thescene.cusize + 1000.; |
142 |
|
VSUM(ap->p, ar.rorg, ar.rdir, ar.rt); |
143 |
|
copycolor(ap->v, ar.rcol); |
144 |
|
} else { /* else update recorded value */ |
160 |
|
static float * |
161 |
|
getambdiffs(AMBHEMI *hp) |
162 |
|
{ |
163 |
+ |
const double normf = 1./bright(hp->acoef); |
164 |
|
float *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float)); |
165 |
|
float *ep; |
166 |
|
AMBSAMP *ap; |
174 |
|
for (j = 0; j < hp->ns; j++, ap++, ep++) { |
175 |
|
b = bright(ap[0].v); |
176 |
|
if (i) { /* from above */ |
177 |
< |
d2 = b - bright(ap[-hp->ns].v); |
177 |
> |
d2 = normf*(b - bright(ap[-hp->ns].v)); |
178 |
|
d2 *= d2; |
179 |
|
ep[0] += d2; |
180 |
|
ep[-hp->ns] += d2; |
181 |
|
} |
182 |
|
if (!j) continue; |
183 |
|
/* from behind */ |
184 |
< |
d2 = b - bright(ap[-1].v); |
184 |
> |
d2 = normf*(b - bright(ap[-1].v)); |
185 |
|
d2 *= d2; |
186 |
|
ep[0] += d2; |
187 |
|
ep[-1] += d2; |
188 |
|
if (!i) continue; |
189 |
|
/* diagonal */ |
190 |
< |
d2 = b - bright(ap[-hp->ns-1].v); |
190 |
> |
d2 = normf*(b - bright(ap[-hp->ns-1].v)); |
191 |
|
d2 *= d2; |
192 |
|
ep[0] += d2; |
193 |
|
ep[-hp->ns-1] += d2; |
231 |
|
goto done; /* nothing left to do */ |
232 |
|
nss = *ep/e2rem*cnt + frandom(); |
233 |
|
for (n = 1; n <= nss && ambsample(hp,i,j,n); n++) |
234 |
< |
--cnt; |
234 |
> |
if (!--cnt) goto done; |
235 |
|
e2rem -= *ep++; /* update remainder */ |
236 |
|
} |
237 |
|
done: |
249 |
|
AMBHEMI *hp; |
250 |
|
double d; |
251 |
|
int n, i, j; |
252 |
+ |
/* insignificance check */ |
253 |
+ |
if (bright(rcol) <= FTINY) |
254 |
+ |
return(NULL); |
255 |
|
/* set number of divisions */ |
256 |
|
if (ambacc <= FTINY && |
257 |
|
wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight))) |
674 |
|
for (a1 = ang-ang_res; a1 <= ang+ang_res; a1 += ang_step) |
675 |
|
flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); |
676 |
|
} |
669 |
– |
/* add low-angle incident (< 20deg) */ |
670 |
– |
if (fabs(hp->rp->rod) <= 0.342) { |
671 |
– |
u = -DOT(hp->rp->rdir, uv[0]); |
672 |
– |
v = -DOT(hp->rp->rdir, uv[1]); |
673 |
– |
if ((r0*r0*u*u + r1*r1*v*v) > hp->rp->rot*hp->rp->rot) { |
674 |
– |
ang = atan2a(v, u); |
675 |
– |
ang += 2.*PI*(ang < 0); |
676 |
– |
ang *= 16/PI; |
677 |
– |
if ((ang < .5) | (ang >= 31.5)) |
678 |
– |
flgs |= 0x80000001; |
679 |
– |
else |
680 |
– |
flgs |= 3L<<(int)(ang-.5); |
681 |
– |
} |
682 |
– |
} |
677 |
|
return(flgs); |
678 |
|
} |
679 |
|
|