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.23 by greg, Wed Apr 20 14:44:05 2011 UTC vs.
Revision 2.27 by greg, Wed Apr 27 23:05:51 2011 UTC

# Line 168 | Line 168 | SDloadFile(SDData *sd, const char *fname)
168                  return lastErr;
169                                  /* try loading variable resolution data */
170          lastErr = SDloadTre(sd, wtl);
171 + #if 0
172                                  /* check our result */
173          switch (lastErr) {
174          case SDEformat:
# Line 178 | Line 179 | SDloadFile(SDData *sd, const char *fname)
179          default:                /* variable res. OK else serious error */
180                  break;
181          }
182 + #endif
183                                  /* done with XML file */
184          ezxml_free(fl);
185          
# Line 405 | Line 407 | SDfreeCache(const SDData *sd)
407  
408   /* Sample an individual BSDF component */
409   SDError
410 < SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec,
409 <                        double randX, SDComponent *sdc)
410 > SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc)
411   {
412          float           coef[SDmaxCh];
413          SDError         ec;
414 +        FVECT           inVec;
415          const SDCDst    *cd;
416          double          d;
417          int             n;
418                                          /* check arguments */
419 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL))
419 >        if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL))
420                  return SDEargument;
421                                          /* get cumulative distribution */
422 +        VCOPY(inVec, ioVec);
423          cd = (*sdc->func->getCDist)(inVec, sdc);
424          if (cd == NULL)
425                  return SDEmemory;
426          if (cd->cTotal <= 1e-7) {       /* anything to sample? */
427                  sv->spec = c_dfcolor;
428                  sv->cieY = .0;
429 <                memset(outVec, 0, 3*sizeof(double));
429 >                memset(ioVec, 0, 3*sizeof(double));
430                  return SDEnone;
431          }
432          sv->cieY = cd->cTotal;
433                                          /* compute sample direction */
434 <        ec = (*sdc->func->sampCDist)(outVec, randX, cd);
434 >        ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
435          if (ec)
436                  return ec;
437                                          /* get BSDF color */
438 <        n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
438 >        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
439          if (n <= 0) {
440                  strcpy(SDerrorDetail, "BSDF sample value error");
441                  return SDEinternal;
# Line 495 | Line 498 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
498          SDError         ec;
499          int             i;
500                                          /* check arguments */
501 <        if ((projSA == NULL) | (v1 == NULL))
501 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
502                  return SDEargument;
503                                          /* initialize extrema */
504          switch (qflags) {
# Line 515 | Line 518 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
518                  rdf = sd->rf;
519          else
520                  rdf = sd->rb;
521 <        tdf = NULL;                     /* transmitted component? */
522 <        if (v2 != NULL && v1[2] > 0 ^ v2[2] > 0) {
523 <                rdf = NULL;
524 <                tdf = sd->tf;
525 <        }
521 >        tdf = sd->tf;
522 >        if (v2 != NULL)                 /* bidirectional? */
523 >                if (v1[2] > 0 ^ v2[2] > 0)
524 >                        rdf = NULL;
525 >                else
526 >                        tdf = NULL;
527          ec = SDEdata;                   /* run through components */
528          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
529                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
530 <                                                qflags, rdf->comp[i].dist);
530 >                                                qflags, &rdf->comp[i]);
531                  if (ec)
532                          return ec;
533          }
534          for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) {
535                  ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2,
536 <                                                qflags, tdf->comp[i].dist);
536 >                                                qflags, &tdf->comp[i]);
537                  if (ec)
538                          return ec;
539          }
# Line 571 | Line 575 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
575          i = (sdf != NULL) ? sdf->ncomp : 0;
576          while (i-- > 0) {
577                  nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
578 <                                                        sdf->comp[i].dist);
578 >                                                        &sdf->comp[i]);
579                  while (nch-- > 0) {
580                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
581                                          coef[nch], &sdf->comp[i].cspec[nch]);
# Line 626 | Line 630 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
630  
631   /* Sample BSDF direction based on the given random variable */
632   SDError
633 < SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec,
630 <                        double randX, int sflags, const SDData *sd)
633 > SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd)
634   {
635          SDError         ec;
636 +        FVECT           inVec;
637          int             inFront;
638          SDSpectralDF    *rdf;
639          double          rdiff;
# Line 638 | Line 642 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
642          SDComponent     *sdc;
643          const SDCDst    **cdarr = NULL;
644                                          /* check arguments */
645 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) |
645 >        if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) |
646                          (randX < 0) | (randX >= 1.))
647                  return SDEargument;
648                                          /* whose side are we on? */
649 +        VCOPY(inVec, ioVec);
650          inFront = (inVec[2] > 0);
651                                          /* remember diffuse portions */
652          if (inFront) {
# Line 682 | Line 687 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
687          }
688          if (sv->cieY <= 1e-7) {         /* anything to sample? */
689                  sv->cieY = .0;
690 <                memset(outVec, 0, 3*sizeof(double));
690 >                memset(ioVec, 0, 3*sizeof(double));
691                  return SDEnone;
692          }
693                                          /* scale random variable */
694          randX *= sv->cieY;
695                                          /* diffuse reflection? */
696          if (randX < rdiff) {
697 <                SDdiffuseSamp(outVec, inFront, randX/rdiff);
697 >                SDdiffuseSamp(ioVec, inFront, randX/rdiff);
698                  goto done;
699          }
700          randX -= rdiff;
# Line 697 | Line 702 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
702          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
703                  if (randX < sd->tLamb.cieY) {
704                          sv->spec = sd->tLamb.spec;
705 <                        SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY);
705 >                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
706                          goto done;
707                  }
708                  randX -= sd->tLamb.cieY;
# Line 709 | Line 714 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
714                  return SDEinternal;
715                                          /* compute sample direction */
716          sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr];
717 <        ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]);
717 >        ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]);
718          if (ec)
719                  return ec;
720                                          /* compute color */
721 <        j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
721 >        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
722          if (j <= 0) {
723                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
724                                  sd->name);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines