| 287 |
|
sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int usepat) |
| 288 |
|
{ |
| 289 |
|
int nstarget = 1; |
| 290 |
< |
int nsent = 0; |
| 290 |
> |
int nsent; |
| 291 |
|
SDError ec; |
| 292 |
|
SDValue bsv; |
| 293 |
< |
double sthick; |
| 293 |
> |
double xrand; |
| 294 |
|
FVECT vsmp; |
| 295 |
|
RAY sr; |
| 296 |
– |
int ntrials; |
| 296 |
|
/* multiple samples? */ |
| 297 |
|
if (specjitter > 1.5) { |
| 298 |
|
nstarget = specjitter*ndp->pr->rweight + .5; |
| 299 |
|
if (nstarget < 1) |
| 300 |
|
nstarget = 1; |
| 301 |
|
} |
| 302 |
< |
/* run through our trials */ |
| 303 |
< |
for (ntrials = 0; nsent < nstarget && ntrials < 9*nstarget; ntrials++) { |
| 304 |
< |
SDerrorDetail[0] = '\0'; |
| 305 |
< |
/* sample direction & coef. */ |
| 302 |
> |
/* run through our samples */ |
| 303 |
> |
for (nsent = 0; nsent < nstarget; nsent++) { |
| 304 |
> |
if (nstarget == 1) /* stratify random variable */ |
| 305 |
> |
xrand = urand(ilhash(dimlist,ndims)+samplendx); |
| 306 |
> |
else |
| 307 |
> |
xrand = (nsent + frandom())/(double)nstarget; |
| 308 |
> |
SDerrorDetail[0] = '\0'; /* sample direction & coef. */ |
| 309 |
|
bsdf_jitter(vsmp, ndp, 0); |
| 310 |
< |
ec = SDsampComponent(&bsv, vsmp, ntrials ? frandom() |
| 309 |
< |
: urand(ilhash(dimlist,ndims)+samplendx), dcp); |
| 310 |
> |
ec = SDsampComponent(&bsv, vsmp, xrand, dcp); |
| 311 |
|
if (ec) |
| 312 |
|
objerror(ndp->mp, USER, transSDError(ec)); |
| 313 |
< |
/* zero component? */ |
| 313 |
< |
if (bsv.cieY <= FTINY) |
| 313 |
> |
if (bsv.cieY <= FTINY) /* zero component? */ |
| 314 |
|
break; |
| 315 |
|
/* map vector to world */ |
| 316 |
|
if (SDmapDir(sr.rdir, ndp->fromloc, vsmp) != SDEnone) |
| 317 |
|
break; |
| 318 |
– |
/* unintentional penetration? */ |
| 319 |
– |
if (DOT(sr.rdir, ndp->pr->ron) > 0 ^ vsmp[2] > 0) |
| 320 |
– |
continue; |
| 318 |
|
/* spawn a specular ray */ |
| 319 |
|
if (nstarget > 1) |
| 320 |
|
bsv.cieY /= (double)nstarget; |
| 321 |
< |
cvt_sdcolor(sr.rcoef, &bsv); /* use color */ |
| 322 |
< |
if (usepat) /* pattern on transmission */ |
| 321 |
> |
cvt_sdcolor(sr.rcoef, &bsv); /* use sample color */ |
| 322 |
> |
if (usepat) /* apply pattern? */ |
| 323 |
|
multcolor(sr.rcoef, ndp->pr->pcol); |
| 324 |
|
if (rayorigin(&sr, SPECULAR, ndp->pr, sr.rcoef) < 0) { |
| 325 |
< |
if (maxdepth > 0) |
| 325 |
> |
if (maxdepth > 0) |
| 326 |
|
break; |
| 327 |
< |
++nsent; /* Russian roulette victim */ |
| 331 |
< |
continue; |
| 327 |
> |
continue; /* Russian roulette victim */ |
| 328 |
|
} |
| 329 |
|
/* need to offset origin? */ |
| 330 |
|
if (ndp->thick != 0 && ndp->pr->rod > 0 ^ vsmp[2] > 0) |
| 332 |
|
rayvalue(&sr); /* send & evaluate sample */ |
| 333 |
|
multcolor(sr.rcol, sr.rcoef); |
| 334 |
|
addcolor(ndp->pr->rcol, sr.rcol); |
| 339 |
– |
++nsent; |
| 335 |
|
} |
| 336 |
|
return(nsent); |
| 337 |
|
} |