109 |
|
register int i; |
110 |
|
|
111 |
|
src->sflags = 0; |
112 |
+ |
src->aimsuccess = 2*AIMREQT-1; /* bitch on second failure */ |
113 |
|
src->nhits = 1; src->ntests = 2; /* start probability = 1/2 */ |
114 |
|
src->so = so; |
115 |
|
|
215 |
|
} |
216 |
|
if (dstrsrc > FTINY) { |
217 |
|
/* distribute source direction */ |
218 |
< |
for (i = 0; i < 3; i++) |
219 |
< |
vd[i] = dstrsrc * source[sn].ss * (1.0 - 2.0*frandom()); |
220 |
< |
|
218 |
> |
dimlist[ndims++] = sn; |
219 |
> |
for (i = 0; i < 3; i++) { |
220 |
> |
dimlist[ndims] = i + 8831; |
221 |
> |
vd[i] = dstrsrc * source[sn].ss * |
222 |
> |
(1.0 - 2.0*urand(ilhash(dimlist,ndims+1)+samplendx)); |
223 |
> |
} |
224 |
> |
ndims--; |
225 |
|
if (norm != NULL) { /* project offset */ |
226 |
|
d = DOT(vd, norm); |
227 |
|
for (i = 0; i < 3; i++) |
242 |
|
/* domega constant */ |
243 |
|
return(source[sn].ss2); |
244 |
|
|
240 |
– |
else { |
245 |
|
/* check proximity */ |
246 |
< |
if (source[sn].sflags & SPROX && |
247 |
< |
d > source[sn].sl.prox) |
248 |
< |
return(0.0); |
249 |
< |
|
250 |
< |
if (norm != NULL) |
251 |
< |
ddot /= d; |
252 |
< |
else |
253 |
< |
ddot = 1.0; |
246 |
> |
if (source[sn].sflags & SPROX && |
247 |
> |
d > source[sn].sl.prox) |
248 |
> |
return(0.0); |
249 |
> |
/* compute dot product */ |
250 |
> |
if (norm != NULL) |
251 |
> |
ddot /= d; |
252 |
> |
else |
253 |
> |
ddot = 1.0; |
254 |
|
/* check angle */ |
255 |
< |
if (source[sn].sflags & SSPOT) { |
256 |
< |
if (source[sn].sl.s->siz < 2.0*PI * |
255 |
> |
if (source[sn].sflags & SSPOT) { |
256 |
> |
if (source[sn].sl.s->siz < 2.0*PI * |
257 |
|
(1.0 + DOT(source[sn].sl.s->aim,sr->rdir))) |
258 |
< |
return(0.0); |
259 |
< |
d += source[sn].sl.s->flen; |
256 |
< |
} |
257 |
< |
/* return domega */ |
258 |
< |
return(ddot*source[sn].ss2/(d*d)); |
258 |
> |
return(0.0); |
259 |
> |
d += source[sn].sl.s->flen; /* adjust length */ |
260 |
|
} |
261 |
+ |
/* compute domega */ |
262 |
+ |
return(ddot*source[sn].ss2/(d*d)); |
263 |
|
} |
264 |
|
|
265 |
|
|
291 |
|
for (i = 0; i < 3; i++) |
292 |
|
r->ron[i] = -r->rdir[i]; |
293 |
|
r->rod = 1.0; |
294 |
< |
r->rofs = 1.0; setident4(r->rofx); |
292 |
< |
r->robs = 1.0; setident4(r->robx); |
294 |
> |
r->rox = NULL; |
295 |
|
return(1); |
296 |
|
} |
297 |
|
return(0); |
318 |
|
extern double pow(); |
319 |
|
register int sn; |
320 |
|
int nshadcheck, ncnts; |
321 |
< |
double prob, ourthresh, hwt, test2, hit2; |
321 |
> |
int nhits; |
322 |
> |
double prob, ourthresh, hwt; |
323 |
|
RAY sr; |
324 |
|
/* NOTE: srccnt and cntord global so no recursion */ |
325 |
|
if (nsources <= 0) |
342 |
|
if (cntord[sn].brt <= 0.0) |
343 |
|
continue; |
344 |
|
/* compute intersection */ |
345 |
< |
if (!( source[sn].sflags & SDISTANT ? |
345 |
> |
if (source[sn].sflags & SDISTANT ? |
346 |
|
sourcehit(&sr) : |
347 |
|
(*ofun[source[sn].so->otype].funp) |
348 |
< |
(source[sn].so, &sr) )) { |
348 |
> |
(source[sn].so, &sr)) { |
349 |
> |
if (source[sn].aimsuccess >= 0) |
350 |
> |
source[sn].aimsuccess++; |
351 |
> |
} else { |
352 |
> |
cntord[sn].brt = 0.0; |
353 |
> |
if (source[sn].aimsuccess < 0) |
354 |
> |
continue; /* bitched already */ |
355 |
> |
source[sn].aimsuccess -= AIMREQT; |
356 |
> |
if (source[sn].aimsuccess >= 0) |
357 |
> |
continue; /* leniency */ |
358 |
|
sprintf(errmsg, |
359 |
|
"aiming failure for light source \"%s\"", |
360 |
|
source[sn].so->oname); |
383 |
|
/* accumulate tail */ |
384 |
|
for (sn = ncnts-1; sn > 0; sn--) |
385 |
|
cntord[sn-1].brt += cntord[sn].brt; |
374 |
– |
/* start with prob=.5 */ |
375 |
– |
hit2 = 0.5; test2 = 1.0; |
386 |
|
/* test for shadows */ |
387 |
+ |
nhits = 0; |
388 |
|
for (sn = 0; sn < ncnts; sn++) { |
389 |
|
/* check threshold */ |
390 |
|
if ((sn+nshadcheck>=ncnts ? cntord[sn].brt : |
391 |
< |
cntord[sn].brt-cntord[sn+nshadcheck].brt) < |
392 |
< |
ourthresh*bright(r->rcol)) |
391 |
> |
cntord[sn].brt-cntord[sn+nshadcheck].brt) |
392 |
> |
< ourthresh*bright(r->rcol)) |
393 |
|
break; |
394 |
|
/* get statistics */ |
384 |
– |
hwt = (double)source[cntord[sn].sno].nhits / |
385 |
– |
(double)source[cntord[sn].sno].ntests; |
386 |
– |
test2 += hwt; |
395 |
|
source[cntord[sn].sno].ntests++; |
396 |
|
/* test for hit */ |
397 |
|
rayorigin(&sr, r, SHADOW, 1.0); |
410 |
|
} |
411 |
|
/* add contribution if hit */ |
412 |
|
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
413 |
< |
hit2 += hwt; |
413 |
> |
nhits++; |
414 |
|
source[cntord[sn].sno].nhits++; |
415 |
|
} |
416 |
< |
/* weighted hit rate */ |
417 |
< |
hwt = hit2 / test2; |
416 |
> |
/* surface hit rate */ |
417 |
> |
if (sn > 0) |
418 |
> |
hwt = (double)nhits / (double)sn; |
419 |
> |
else |
420 |
> |
hwt = 0.5; |
421 |
|
#ifdef DEBUG |
422 |
|
sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", |
423 |
|
sn, ncnts-sn, hwt); |
473 |
|
m->oargs.farg[2]); |
474 |
|
/* modify value */ |
475 |
|
multcolor(r->rcol, r->pcol); |
465 |
– |
/* assign distance */ |
466 |
– |
r->rt = r->rot; |
476 |
|
} |
477 |
|
} |