| 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 |
|
*/ |
| 337 |
|
( sr.ro != source[scp->sno].so || |
| 338 |
|
source[scp->sno].sflags & SFOLLOW )) { |
| 339 |
|
/* follow entire path */ |
| 340 |
< |
if (!raycont(&sr)) |
| 337 |
< |
objerror(sr.ro, USER, "material not found"); |
| 340 |
> |
raycont(&sr); |
| 341 |
|
rayparticipate(&sr); |
| 342 |
|
if (trace != NULL) |
| 343 |
|
(*trace)(&sr); /* trace execution */ |
| 377 |
|
srcscatter(r) /* compute source scattering into ray */ |
| 378 |
|
register RAY *r; |
| 379 |
|
{ |
| 380 |
+ |
int oldsampndx; |
| 381 |
|
int nsamps; |
| 382 |
|
RAY sr; |
| 383 |
|
SRCINDEX si; |
| 385 |
|
COLOR cumval, ctmp; |
| 386 |
|
int i, j; |
| 387 |
|
|
| 388 |
< |
if (r->slights == NULL || r->slights[0] == 0 || r->gecc >= 1.-FTINY) |
| 388 |
> |
if (r->slights == NULL || r->slights[0] == 0 |
| 389 |
> |
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
| 390 |
|
return; |
| 391 |
|
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
| 392 |
|
nsamps = 1; |
| 393 |
< |
initsrcindex(&si); |
| 393 |
> |
#if MAXSSAMP |
| 394 |
> |
else if (nsamps > MAXSSAMP) |
| 395 |
> |
nsamps = MAXSSAMP; |
| 396 |
> |
#endif |
| 397 |
> |
oldsampndx = samplendx; |
| 398 |
> |
samplendx = random()&0x7fff; /* randomize */ |
| 399 |
|
for (i = r->slights[0]; i > 0; i--) { /* for each source */ |
| 400 |
|
setcolor(cumval, 0., 0., 0.); |
| 401 |
|
lastt = r->rot; |
| 406 |
|
sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; |
| 407 |
|
sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; |
| 408 |
|
sr.rmax = 0.; |
| 409 |
< |
/* sample ray to this source */ |
| 410 |
< |
if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) || |
| 411 |
< |
sr.rsrc != r->slights[i]) { |
| 412 |
< |
si.sn = r->slights[i]-1; /* reset */ |
| 413 |
< |
si.np = 0; |
| 414 |
< |
if (!srcray(&sr, NULL, &si) || |
| 405 |
< |
sr.rsrc != r->slights[i]) |
| 406 |
< |
continue; /* no path */ |
| 407 |
< |
} |
| 409 |
> |
initsrcindex(&si); /* sample ray to this source */ |
| 410 |
> |
si.sn = r->slights[i]; |
| 411 |
> |
nopart(&si, &sr); |
| 412 |
> |
if (!srcray(&sr, NULL, &si) || |
| 413 |
> |
sr.rsrc != r->slights[i]) |
| 414 |
> |
continue; /* no path */ |
| 415 |
|
copycolor(sr.cext, r->cext); |
| 416 |
|
sr.albedo = r->albedo; |
| 417 |
|
sr.gecc = r->gecc; |
| 445 |
|
multcolor(cumval, ctmp); |
| 446 |
|
addcolor(r->rcol, cumval); /* sum into ray result */ |
| 447 |
|
} |
| 448 |
+ |
samplendx = oldsampndx; |
| 449 |
|
} |
| 450 |
|
|
| 451 |
|
|