ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/bsdf.c
(Generate patch)

Comparing ray/src/common/bsdf.c (file contents):
Revision 2.44 by greg, Sun Apr 21 21:36:23 2013 UTC vs.
Revision 2.51 by greg, Sat Aug 1 23:27:04 2015 UTC

# Line 199 | Line 199 | SDloadFile(SDData *sd, const char *fname)
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;
# Line 488 | Line 488 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
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)
# Line 559 | Line 558 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
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   }
# Line 597 | Line 595 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
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,
# Line 619 | Line 618 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
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  
# Line 756 | Line 756 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
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? */
# Line 793 | Line 789 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines