199 |
|
} |
200 |
|
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
201 |
|
if (wtl == NULL) { |
202 |
< |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'", |
202 |
> |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers", |
203 |
|
sd->name); |
204 |
|
ezxml_free(fl); |
205 |
|
return SDEformat; |
422 |
|
if (fname == NULL || !*fname) |
423 |
|
return NULL; |
424 |
|
SDerrorDetail[0] = '\0'; |
425 |
+ |
/* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */ |
426 |
|
if ((sd = SDgetCache(fname)) == NULL) { |
427 |
|
SDreportError(SDEmemory, stderr); |
428 |
|
return NULL; |
430 |
|
if (!SDisLoaded(sd) && (ec = SDloadFile(sd, fname))) { |
431 |
|
SDreportError(ec, stderr); |
432 |
|
SDfreeCache(sd); |
433 |
< |
return NULL; |
433 |
> |
sd = NULL; |
434 |
|
} |
435 |
+ |
/* END MUTEX LOCK */ |
436 |
|
return sd; |
437 |
|
} |
438 |
|
|
490 |
|
return SDEargument; |
491 |
|
/* get cumulative distribution */ |
492 |
|
VCOPY(inVec, ioVec); |
493 |
+ |
sv->cieY = 0; |
494 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
495 |
< |
if (cd == NULL) |
496 |
< |
return SDEmemory; |
497 |
< |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
495 |
> |
if (cd != NULL) |
496 |
> |
sv->cieY = cd->cTotal; |
497 |
> |
if (sv->cieY <= 1e-6) { /* nothing to sample? */ |
498 |
|
sv->spec = c_dfcolor; |
499 |
< |
sv->cieY = .0; |
497 |
< |
memset(ioVec, 0, 3*sizeof(double)); |
499 |
> |
memset(ioVec, 0, sizeof(FVECT)); |
500 |
|
return SDEnone; |
501 |
|
} |
500 |
– |
sv->cieY = cd->cTotal; |
502 |
|
/* compute sample direction */ |
503 |
|
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
504 |
|
if (ec) |
560 |
|
SDmultiSamp(outVec, 2, randX); |
561 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
562 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
563 |
< |
if (outVec[2] > 0) /* a bit of paranoia */ |
563 |
< |
outVec[2] = sqrt(outVec[2]); |
563 |
> |
outVec[2] = sqrt(outVec[2]*(outVec[2]>0)); |
564 |
|
if (!outFront) /* going out back? */ |
565 |
|
outVec[2] = -outVec[2]; |
566 |
|
} |
597 |
|
rdf = sd->rb; |
598 |
|
tdf = (sd->tb != NULL) ? sd->tb : sd->tf; |
599 |
|
} |
600 |
< |
if (v2 != NULL) /* bidirectional? */ |
600 |
> |
if (v2 != NULL) { /* bidirectional? */ |
601 |
|
if (v1[2] > 0 ^ v2[2] > 0) |
602 |
|
rdf = NULL; |
603 |
|
else |
604 |
|
tdf = NULL; |
605 |
+ |
} |
606 |
|
ec = SDEdata; /* run through components */ |
607 |
|
for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { |
608 |
|
ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
620 |
|
projSA[0] = M_PI; |
621 |
|
if (qflags == SDqueryMin+SDqueryMax) |
622 |
|
projSA[1] = M_PI; |
623 |
< |
} |
623 |
> |
} else if (qflags == SDqueryMin+SDqueryMax && projSA[0] > projSA[1]) |
624 |
> |
projSA[0] = projSA[1]; |
625 |
|
return SDEnone; |
626 |
|
} |
627 |
|
|
758 |
|
return SDEmemory; |
759 |
|
while (j-- > 0) { /* non-diffuse transmission */ |
760 |
|
cdarr[i+j] = (*tdf->comp[j].func->getCDist)(inVec, &tdf->comp[j]); |
761 |
< |
if (cdarr[i+j] == NULL) { |
762 |
< |
free(cdarr); |
761 |
< |
return SDEmemory; |
762 |
< |
} |
761 |
> |
if (cdarr[i+j] == NULL) |
762 |
> |
cdarr[i+j] = &SDemptyCD; |
763 |
|
sv->cieY += cdarr[i+j]->cTotal; |
764 |
|
} |
765 |
|
while (i-- > 0) { /* non-diffuse reflection */ |
766 |
|
cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]); |
767 |
< |
if (cdarr[i] == NULL) { |
768 |
< |
free(cdarr); |
769 |
< |
return SDEmemory; |
770 |
< |
} |
767 |
> |
if (cdarr[i] == NULL) |
768 |
> |
cdarr[i] = &SDemptyCD; |
769 |
|
sv->cieY += cdarr[i]->cTotal; |
770 |
|
} |
771 |
|
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
772 |
|
sv->cieY = .0; |
773 |
< |
memset(ioVec, 0, 3*sizeof(double)); |
773 |
> |
memset(ioVec, 0, sizeof(FVECT)); |
774 |
|
return SDEnone; |
775 |
|
} |
776 |
|
/* scale random variable */ |
791 |
|
randX -= sd->tLamb.cieY; |
792 |
|
} |
793 |
|
/* else one of cumulative dist. */ |
794 |
< |
for (i = 0; i < n && randX < cdarr[i]->cTotal; i++) |
794 |
> |
for (i = 0; i < n && randX > cdarr[i]->cTotal; i++) |
795 |
|
randX -= cdarr[i]->cTotal; |
796 |
|
if (i >= n) |
797 |
|
return SDEinternal; |