22 |
|
|
23 |
|
extern double ssampdist; /* scatter sampling distance */ |
24 |
|
|
25 |
+ |
#ifndef MAXSSAMP |
26 |
+ |
#define MAXSSAMP 16 /* maximum samples per ray */ |
27 |
+ |
#endif |
28 |
+ |
|
29 |
|
/* |
30 |
|
* Structures used by direct() |
31 |
|
*/ |
386 |
|
COLOR cumval, ctmp; |
387 |
|
int i, j; |
388 |
|
|
389 |
< |
if (r->slights == NULL || r->slights[0] == 0 || r->gecc >= 1.-FTINY) |
389 |
> |
if (r->slights == NULL || r->slights[0] == 0 |
390 |
> |
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
391 |
|
return; |
392 |
|
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
393 |
|
nsamps = 1; |
394 |
+ |
#if MAXSSAMP |
395 |
+ |
else if (nsamps > MAXSSAMP) |
396 |
+ |
nsamps = MAXSSAMP; |
397 |
+ |
#endif |
398 |
|
oldsampndx = samplendx; |
399 |
|
samplendx = random()&0x7fff; /* randomize */ |
391 |
– |
initsrcindex(&si); |
400 |
|
for (i = r->slights[0]; i > 0; i--) { /* for each source */ |
401 |
|
setcolor(cumval, 0., 0., 0.); |
402 |
|
lastt = r->rot; |
407 |
|
sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; |
408 |
|
sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; |
409 |
|
sr.rmax = 0.; |
410 |
< |
/* sample ray to this source */ |
411 |
< |
if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) || |
412 |
< |
sr.rsrc != r->slights[i]) { |
413 |
< |
si.sn = r->slights[i]-1; /* reset */ |
414 |
< |
si.np = 0; |
415 |
< |
if (!srcray(&sr, NULL, &si) || |
408 |
< |
sr.rsrc != r->slights[i]) |
409 |
< |
continue; /* no path */ |
410 |
< |
} |
410 |
> |
initsrcindex(&si); /* sample ray to this source */ |
411 |
> |
si.sn = r->slights[i]; |
412 |
> |
nopart(&si, &sr); |
413 |
> |
if (!srcray(&sr, NULL, &si) || |
414 |
> |
sr.rsrc != r->slights[i]) |
415 |
> |
continue; /* no path */ |
416 |
|
copycolor(sr.cext, r->cext); |
417 |
|
sr.albedo = r->albedo; |
418 |
|
sr.gecc = r->gecc; |