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; |
488 |
|
return SDEargument; |
489 |
|
/* get cumulative distribution */ |
490 |
|
VCOPY(inVec, ioVec); |
491 |
+ |
sv->cieY = 0; |
492 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
493 |
< |
if (cd == NULL) |
494 |
< |
return SDEmemory; |
495 |
< |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
493 |
> |
if (cd != NULL) |
494 |
> |
sv->cieY = cd->cTotal; |
495 |
> |
if (sv->cieY <= 1e-6) { /* nothing to sample? */ |
496 |
|
sv->spec = c_dfcolor; |
496 |
– |
sv->cieY = .0; |
497 |
|
memset(ioVec, 0, 3*sizeof(double)); |
498 |
|
return SDEnone; |
499 |
|
} |
500 |
– |
sv->cieY = cd->cTotal; |
500 |
|
/* compute sample direction */ |
501 |
|
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
502 |
|
if (ec) |
558 |
|
SDmultiSamp(outVec, 2, randX); |
559 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
560 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
561 |
< |
if (outVec[2] > 0) /* a bit of paranoia */ |
563 |
< |
outVec[2] = sqrt(outVec[2]); |
561 |
> |
outVec[2] = sqrt(outVec[2]*(outVec[2]>0)); |
562 |
|
if (!outFront) /* going out back? */ |
563 |
|
outVec[2] = -outVec[2]; |
564 |
|
} |
595 |
|
rdf = sd->rb; |
596 |
|
tdf = (sd->tb != NULL) ? sd->tb : sd->tf; |
597 |
|
} |
598 |
< |
if (v2 != NULL) /* bidirectional? */ |
598 |
> |
if (v2 != NULL) { /* bidirectional? */ |
599 |
|
if (v1[2] > 0 ^ v2[2] > 0) |
600 |
|
rdf = NULL; |
601 |
|
else |
602 |
|
tdf = NULL; |
603 |
+ |
} |
604 |
|
ec = SDEdata; /* run through components */ |
605 |
|
for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { |
606 |
|
ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, |
618 |
|
projSA[0] = M_PI; |
619 |
|
if (qflags == SDqueryMin+SDqueryMax) |
620 |
|
projSA[1] = M_PI; |
621 |
< |
} |
621 |
> |
} else if (qflags == SDqueryMin+SDqueryMax && projSA[0] > projSA[1]) |
622 |
> |
projSA[0] = projSA[1]; |
623 |
|
return SDEnone; |
624 |
|
} |
625 |
|
|
756 |
|
return SDEmemory; |
757 |
|
while (j-- > 0) { /* non-diffuse transmission */ |
758 |
|
cdarr[i+j] = (*tdf->comp[j].func->getCDist)(inVec, &tdf->comp[j]); |
759 |
< |
if (cdarr[i+j] == NULL) { |
760 |
< |
free(cdarr); |
761 |
< |
return SDEmemory; |
762 |
< |
} |
759 |
> |
if (cdarr[i+j] == NULL) |
760 |
> |
cdarr[i+j] = &SDemptyCD; |
761 |
|
sv->cieY += cdarr[i+j]->cTotal; |
762 |
|
} |
763 |
|
while (i-- > 0) { /* non-diffuse reflection */ |
764 |
|
cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]); |
765 |
< |
if (cdarr[i] == NULL) { |
766 |
< |
free(cdarr); |
769 |
< |
return SDEmemory; |
770 |
< |
} |
765 |
> |
if (cdarr[i] == NULL) |
766 |
> |
cdarr[i] = &SDemptyCD; |
767 |
|
sv->cieY += cdarr[i]->cTotal; |
768 |
|
} |
769 |
|
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
789 |
|
randX -= sd->tLamb.cieY; |
790 |
|
} |
791 |
|
/* else one of cumulative dist. */ |
792 |
< |
for (i = 0; i < n && randX < cdarr[i]->cTotal; i++) |
792 |
> |
for (i = 0; i < n && randX > cdarr[i]->cTotal; i++) |
793 |
|
randX -= cdarr[i]->cTotal; |
794 |
|
if (i >= n) |
795 |
|
return SDEinternal; |