51 |
|
|
52 |
|
|
53 |
|
static int |
54 |
+ |
ambcollision( /* proposed direciton collides? */ |
55 |
+ |
AMBHEMI *hp, |
56 |
+ |
int i, |
57 |
+ |
int j, |
58 |
+ |
FVECT dv |
59 |
+ |
) |
60 |
+ |
{ |
61 |
+ |
double cos_thresh; |
62 |
+ |
int ii, jj; |
63 |
+ |
/* min. spacing = 1/10th division */ |
64 |
+ |
cos_thresh = (PI/10.)/(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; |
70 |
+ |
for (jj = j-1; jj <= j+1; jj++) { |
71 |
+ |
AMBSAMP *ap; |
72 |
+ |
FVECT avec; |
73 |
+ |
double dprod; |
74 |
+ |
if (jj < 0) continue; |
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) |
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); /* nothing to worry about */ |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
|
90 |
+ |
static int |
91 |
|
ambsample( /* initial ambient division sample */ |
92 |
|
AMBHEMI *hp, |
93 |
|
int i, |
115 |
|
hlist[1] = j; |
116 |
|
hlist[2] = i; |
117 |
|
multisamp(spt, 2, urand(ilhash(hlist,3)+n)); |
118 |
< |
/* 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)) |
87 |
< |
spt[1] = 0.1 + 0.8*frandom(); |
88 |
< |
} |
118 |
> |
resample: |
119 |
|
SDsquare2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); |
120 |
|
zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]); |
121 |
|
for (ii = 3; ii--; ) |
123 |
|
spt[1]*hp->uy[ii] + |
124 |
|
zd*hp->rp->ron[ii]; |
125 |
|
checknorm(ar.rdir); |
126 |
+ |
/* avoid coincident samples */ |
127 |
+ |
if (!n && ambcollision(hp, i, j, ar.rdir)) { |
128 |
+ |
spt[0] = frandom(); spt[1] = frandom(); |
129 |
+ |
goto resample; |
130 |
+ |
} |
131 |
|
dimlist[ndims++] = AI(hp,i,j) + 90171; |
132 |
|
rayvalue(&ar); /* evaluate ray */ |
133 |
|
ndims--; |