20 |
|
#include "ray.h" |
21 |
|
#include "ambient.h" |
22 |
|
#include "random.h" |
23 |
+ |
#include "source.h" |
24 |
+ |
#include "otypes.h" |
25 |
+ |
#include "otspecial.h" |
26 |
|
|
27 |
|
#ifndef OLDAMB |
28 |
|
|
61 |
|
FVECT dv |
62 |
|
) |
63 |
|
{ |
64 |
< |
const double cos_thresh = 0.9999995; /* about 3.44 arcminutes */ |
65 |
< |
int ii, jj; |
66 |
< |
|
64 |
> |
double cos_thresh; |
65 |
> |
int ii, jj; |
66 |
> |
/* min. spacing = 1/4th division */ |
67 |
> |
cos_thresh = (PI/4.)/(double)hp->ns; |
68 |
> |
cos_thresh = 1. - .5*cos_thresh*cos_thresh; |
69 |
> |
/* check existing neighbors */ |
70 |
|
for (ii = i-1; ii <= i+1; ii++) { |
71 |
|
if (ii < 0) continue; |
72 |
|
if (ii >= hp->ns) break; |
78 |
|
if (jj >= hp->ns) break; |
79 |
|
if ((ii==i) & (jj==j)) continue; |
80 |
|
ap = &ambsam(hp,ii,jj); |
81 |
< |
if (ap->d <= .5/FHUGE) continue; |
81 |
> |
if (ap->d <= .5/FHUGE) |
82 |
> |
continue; /* no one home */ |
83 |
|
VSUB(avec, ap->p, hp->rp->rop); |
84 |
|
dprod = DOT(avec, dv); |
85 |
|
if (dprod >= cos_thresh*VLEN(avec)) |
86 |
|
return(1); /* collision */ |
87 |
|
} |
88 |
|
} |
89 |
< |
return(0); |
89 |
> |
return(0); /* nothing to worry about */ |
90 |
|
} |
91 |
|
|
92 |
|
|
129 |
|
/* avoid coincident samples */ |
130 |
|
if (!n && ambcollision(hp, i, j, ar.rdir)) { |
131 |
|
spt[0] = frandom(); spt[1] = frandom(); |
132 |
< |
goto resample; |
132 |
> |
goto resample; /* reject this sample */ |
133 |
|
} |
134 |
|
dimlist[ndims++] = AI(hp,i,j) + 90171; |
135 |
|
rayvalue(&ar); /* evaluate ray */ |
140 |
|
if (ar.rt*ap->d < 1.0) /* new/closer distance? */ |
141 |
|
ap->d = 1.0/ar.rt; |
142 |
|
if (!n) { /* record first vertex & value */ |
143 |
< |
if (ar.rt > 10.0*thescene.cusize) |
144 |
< |
ar.rt = 10.0*thescene.cusize; |
143 |
> |
if (ar.rt > 10.0*thescene.cusize + 1000.) |
144 |
> |
ar.rt = 10.0*thescene.cusize + 1000.; |
145 |
|
VSUM(ap->p, ar.rorg, ar.rdir, ar.rt); |
146 |
|
copycolor(ap->v, ar.rcol); |
147 |
|
} else { /* else update recorded value */ |
163 |
|
static float * |
164 |
|
getambdiffs(AMBHEMI *hp) |
165 |
|
{ |
166 |
+ |
const double normf = 1./bright(hp->acoef); |
167 |
|
float *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float)); |
168 |
|
float *ep; |
169 |
|
AMBSAMP *ap; |
177 |
|
for (j = 0; j < hp->ns; j++, ap++, ep++) { |
178 |
|
b = bright(ap[0].v); |
179 |
|
if (i) { /* from above */ |
180 |
< |
d2 = b - bright(ap[-hp->ns].v); |
180 |
> |
d2 = normf*(b - bright(ap[-hp->ns].v)); |
181 |
|
d2 *= d2; |
182 |
|
ep[0] += d2; |
183 |
|
ep[-hp->ns] += d2; |
184 |
|
} |
185 |
|
if (!j) continue; |
186 |
|
/* from behind */ |
187 |
< |
d2 = b - bright(ap[-1].v); |
187 |
> |
d2 = normf*(b - bright(ap[-1].v)); |
188 |
|
d2 *= d2; |
189 |
|
ep[0] += d2; |
190 |
|
ep[-1] += d2; |
191 |
|
if (!i) continue; |
192 |
|
/* diagonal */ |
193 |
< |
d2 = b - bright(ap[-hp->ns-1].v); |
193 |
> |
d2 = normf*(b - bright(ap[-hp->ns-1].v)); |
194 |
|
d2 *= d2; |
195 |
|
ep[0] += d2; |
196 |
|
ep[-hp->ns-1] += d2; |
234 |
|
goto done; /* nothing left to do */ |
235 |
|
nss = *ep/e2rem*cnt + frandom(); |
236 |
|
for (n = 1; n <= nss && ambsample(hp,i,j,n); n++) |
237 |
< |
--cnt; |
237 |
> |
if (!--cnt) goto done; |
238 |
|
e2rem -= *ep++; /* update remainder */ |
239 |
|
} |
240 |
|
done: |
252 |
|
AMBHEMI *hp; |
253 |
|
double d; |
254 |
|
int n, i, j; |
255 |
+ |
/* insignificance check */ |
256 |
+ |
if (bright(rcol) <= FTINY) |
257 |
+ |
return(NULL); |
258 |
|
/* set number of divisions */ |
259 |
|
if (ambacc <= FTINY && |
260 |
|
wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight))) |
649 |
|
FVECT vec; |
650 |
|
double u, v; |
651 |
|
double ang, a1; |
652 |
+ |
OBJREC *m; |
653 |
|
int i, j; |
654 |
|
/* don't bother for a few samples */ |
655 |
|
if (hp->ns < 8) |
679 |
|
flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); |
680 |
|
} |
681 |
|
/* add low-angle incident (< 20deg) */ |
682 |
< |
if (fabs(hp->rp->rod) <= 0.342) { |
682 |
> |
if (fabs(hp->rp->rod) <= 0.342 && hp->rp->parent != NULL && |
683 |
> |
(m = findmaterial(hp->rp->parent->ro)) != NULL && |
684 |
> |
isopaque(m->otype)) { |
685 |
|
u = -DOT(hp->rp->rdir, uv[0]); |
686 |
|
v = -DOT(hp->rp->rdir, uv[1]); |
687 |
|
if ((r0*r0*u*u + r1*r1*v*v) > hp->rp->rot*hp->rp->rot) { |