20 |
|
#include "random.h" |
21 |
|
|
22 |
|
|
23 |
– |
#define DISKTFRAC 0.25 /* disk area pretest fraction */ |
24 |
– |
|
23 |
|
double getdisk(); |
24 |
|
|
25 |
|
static OBJECT *vobject; /* virtual source objects */ |
233 |
|
FVECT onorm; |
234 |
|
FVECT offsdir; |
235 |
|
double or, d; |
236 |
+ |
int infront; |
237 |
+ |
int ssn; |
238 |
|
int nok, nhit; |
239 |
|
register int i, n; |
240 |
|
/* return if pretesting disabled */ |
243 |
|
/* get surface normal */ |
244 |
|
(*sfun[o->otype].of->getpleq)(onorm, o); |
245 |
|
/* set number of rays to sample */ |
246 |
< |
if (source[sn].sflags & SDISTANT) |
246 |
> |
if (source[sn].sflags & SDISTANT) { |
247 |
|
n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)* |
248 |
|
vspretest + .5; |
249 |
< |
else |
249 |
> |
infront = DOT(onorm, source[sn].sloc) > 0.; |
250 |
> |
} else { |
251 |
|
n = or2/dist2(oc,source[sn].sloc)*vspretest + .5; |
252 |
+ |
for (i = 0; i < 3; i++) |
253 |
+ |
offsdir[i] = source[sn].sloc[i] - oc[i]; |
254 |
+ |
infront = DOT(onorm, offsdir) > 0.; |
255 |
+ |
} |
256 |
|
if (n < 1) n = 1; |
252 |
– |
/* limit tests to central region */ |
253 |
– |
or = DISKTFRAC*sqrt(or2); |
257 |
|
/* sample */ |
258 |
+ |
or = sqrt(or2); |
259 |
+ |
ssn = 7*n; |
260 |
|
nhit = nok = 0; |
261 |
|
while (n-- > 0) { |
262 |
< |
samplendx++; |
263 |
< |
/* |
264 |
< |
* We're being real sloppy with our sample locations here. |
265 |
< |
*/ |
266 |
< |
for (i = 0; i < 3; i++) |
267 |
< |
offsdir[i] = or*(1. - 2.*urand(931*i+5821+n)); |
268 |
< |
d = DOT(offsdir,onorm); |
269 |
< |
for (i = 0; i < 3; i++) |
270 |
< |
sr.rorg[i] = oc[i] + (1.-d)*offsdir[i]; |
262 |
> |
/* get sample point */ |
263 |
> |
do { |
264 |
> |
if (--ssn < 0) |
265 |
> |
return(f); /* too small a target! */ |
266 |
> |
for (i = 0; i < 3; i++) |
267 |
> |
offsdir[i] = or*(1. - |
268 |
> |
2.*urand(931*i+5827+ssn)); |
269 |
> |
for (i = 0; i < 3; i++) |
270 |
> |
sr.rorg[i] = oc[i] + offsdir[i]; |
271 |
> |
d = DOT(offsdir,onorm); |
272 |
> |
if (infront) |
273 |
> |
for (i = 0; i < 3; i++) { |
274 |
> |
sr.rorg[i] -= (d-.0001)*onorm[i]; |
275 |
> |
sr.rdir[i] = -onorm[i]; |
276 |
> |
} |
277 |
> |
else |
278 |
> |
for (i = 0; i < 3; i++) { |
279 |
> |
sr.rorg[i] -= (d+.0001)*onorm[i]; |
280 |
> |
sr.rdir[i] = onorm[i]; |
281 |
> |
} |
282 |
> |
rayorigin(&sr, NULL, PRIMARY, 1.0); |
283 |
> |
} while (!(*ofun[o->otype].funp)(o, &sr)); |
284 |
|
/* check against source */ |
285 |
+ |
samplendx++; |
286 |
|
if (srcray(&sr, NULL, sn) == 0.0) |
287 |
|
continue; |
288 |
|
sr.revf = srcvalue; |