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 |
|
|
238 |
|
/* domega constant */ |
239 |
|
return(source[sn].ss2); |
240 |
|
|
240 |
– |
else { |
241 |
|
/* check proximity */ |
242 |
< |
if (source[sn].sflags & SPROX && |
243 |
< |
d > source[sn].sl.prox) |
244 |
< |
return(0.0); |
245 |
< |
|
246 |
< |
if (norm != NULL) |
247 |
< |
ddot /= d; |
248 |
< |
else |
249 |
< |
ddot = 1.0; |
242 |
> |
if (source[sn].sflags & SPROX && |
243 |
> |
d > source[sn].sl.prox) |
244 |
> |
return(0.0); |
245 |
> |
/* compute dot product */ |
246 |
> |
if (norm != NULL) |
247 |
> |
ddot /= d; |
248 |
> |
else |
249 |
> |
ddot = 1.0; |
250 |
|
/* check angle */ |
251 |
< |
if (source[sn].sflags & SSPOT) { |
252 |
< |
if (source[sn].sl.s->siz < 2.0*PI * |
251 |
> |
if (source[sn].sflags & SSPOT) { |
252 |
> |
if (source[sn].sl.s->siz < 2.0*PI * |
253 |
|
(1.0 + DOT(source[sn].sl.s->aim,sr->rdir))) |
254 |
< |
return(0.0); |
255 |
< |
d += source[sn].sl.s->flen; |
256 |
< |
} |
257 |
< |
/* return domega */ |
258 |
< |
return(ddot*source[sn].ss2/(d*d)); |
254 |
> |
return(0.0); |
255 |
> |
d += source[sn].sl.s->flen; /* adjust length */ |
256 |
|
} |
257 |
+ |
/* compute domega */ |
258 |
+ |
return(ddot*source[sn].ss2/(d*d)); |
259 |
|
} |
260 |
|
|
261 |
|
|
314 |
|
extern double pow(); |
315 |
|
register int sn; |
316 |
|
int nshadcheck, ncnts; |
317 |
< |
double prob, ourthresh, hwt, test2, hit2; |
317 |
> |
int nhits; |
318 |
> |
double prob, ourthresh, hwt; |
319 |
|
RAY sr; |
320 |
|
/* NOTE: srccnt and cntord global so no recursion */ |
321 |
|
if (nsources <= 0) |
338 |
|
if (cntord[sn].brt <= 0.0) |
339 |
|
continue; |
340 |
|
/* compute intersection */ |
341 |
< |
if (!( source[sn].sflags & SDISTANT ? |
341 |
> |
if (source[sn].sflags & SDISTANT ? |
342 |
|
sourcehit(&sr) : |
343 |
|
(*ofun[source[sn].so->otype].funp) |
344 |
< |
(source[sn].so, &sr) )) { |
344 |
> |
(source[sn].so, &sr)) { |
345 |
> |
if (source[sn].aimsuccess >= 0) |
346 |
> |
source[sn].aimsuccess++; |
347 |
> |
} else { |
348 |
> |
cntord[sn].brt = 0.0; |
349 |
> |
if (source[sn].aimsuccess < 0) |
350 |
> |
continue; /* bitched already */ |
351 |
> |
source[sn].aimsuccess -= AIMREQT; |
352 |
> |
if (source[sn].aimsuccess >= 0) |
353 |
> |
continue; /* leniency */ |
354 |
|
sprintf(errmsg, |
355 |
|
"aiming failure for light source \"%s\"", |
356 |
|
source[sn].so->oname); |
379 |
|
/* accumulate tail */ |
380 |
|
for (sn = ncnts-1; sn > 0; sn--) |
381 |
|
cntord[sn-1].brt += cntord[sn].brt; |
373 |
– |
/* start with prob=.5 */ |
374 |
– |
hit2 = 0.5; test2 = 1.0; |
382 |
|
/* test for shadows */ |
383 |
+ |
nhits = 0; |
384 |
|
for (sn = 0; sn < ncnts; sn++) { |
385 |
|
/* check threshold */ |
386 |
|
if ((sn+nshadcheck>=ncnts ? cntord[sn].brt : |
387 |
< |
cntord[sn].brt-cntord[sn+nshadcheck].brt) < |
388 |
< |
ourthresh*bright(r->rcol)) |
387 |
> |
cntord[sn].brt-cntord[sn+nshadcheck].brt) |
388 |
> |
< ourthresh*bright(r->rcol)) |
389 |
|
break; |
390 |
|
/* get statistics */ |
383 |
– |
hwt = (double)source[cntord[sn].sno].nhits / |
384 |
– |
(double)source[cntord[sn].sno].ntests; |
385 |
– |
test2 += hwt; |
391 |
|
source[cntord[sn].sno].ntests++; |
392 |
|
/* test for hit */ |
393 |
|
rayorigin(&sr, r, SHADOW, 1.0); |
406 |
|
} |
407 |
|
/* add contribution if hit */ |
408 |
|
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
409 |
< |
hit2 += hwt; |
409 |
> |
nhits++; |
410 |
|
source[cntord[sn].sno].nhits++; |
411 |
|
} |
412 |
< |
/* weighted hit rate */ |
413 |
< |
hwt = hit2 / test2; |
412 |
> |
/* surface hit rate */ |
413 |
> |
if (sn > 0) |
414 |
> |
hwt = (double)nhits / (double)sn; |
415 |
> |
else |
416 |
> |
hwt = 0.5; |
417 |
|
#ifdef DEBUG |
418 |
|
sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", |
419 |
|
sn, ncnts-sn, hwt); |