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.30 by greg, Thu Jun 9 17:09:39 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   *
11   */
12  
13 + #define _USE_MATH_DEFINES
14   #include <stdio.h>
15   #include <stdlib.h>
16   #include <math.h>
# Line 169 | Line 170 | SDloadFile(SDData *sd, const char *fname)
170                                  /* try loading variable resolution data */
171          lastErr = SDloadTre(sd, wtl);
172                                  /* check our result */
173 <        switch (lastErr) {
173 <        case SDEformat:
174 <        case SDEdata:
175 <        case SDEsupport:        /* possibly we just tried the wrong format */
173 >        if (lastErr == SDEsupport)      /* try matrix BSDF if not tree data */
174                  lastErr = SDloadMtx(sd, wtl);
175 <                break;
178 <        default:                /* variable res. OK else serious error */
179 <                break;
180 <        }
175 >                
176                                  /* done with XML file */
177          ezxml_free(fl);
178          
# Line 405 | Line 400 | SDfreeCache(const SDData *sd)
400  
401   /* Sample an individual BSDF component */
402   SDError
403 < SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec,
409 <                        double randX, SDComponent *sdc)
403 > SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc)
404   {
405          float           coef[SDmaxCh];
406          SDError         ec;
407 +        FVECT           inVec;
408          const SDCDst    *cd;
409          double          d;
410          int             n;
411                                          /* check arguments */
412 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL))
412 >        if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL))
413                  return SDEargument;
414                                          /* get cumulative distribution */
415 +        VCOPY(inVec, ioVec);
416          cd = (*sdc->func->getCDist)(inVec, sdc);
417          if (cd == NULL)
418                  return SDEmemory;
419          if (cd->cTotal <= 1e-7) {       /* anything to sample? */
420                  sv->spec = c_dfcolor;
421                  sv->cieY = .0;
422 <                memset(outVec, 0, 3*sizeof(double));
422 >                memset(ioVec, 0, 3*sizeof(double));
423                  return SDEnone;
424          }
425          sv->cieY = cd->cTotal;
426                                          /* compute sample direction */
427 <        ec = (*sdc->func->sampCDist)(outVec, randX, cd);
427 >        ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
428          if (ec)
429                  return ec;
430                                          /* get BSDF color */
431 <        n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
431 >        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
432          if (n <= 0) {
433                  strcpy(SDerrorDetail, "BSDF sample value error");
434                  return SDEinternal;
# Line 495 | Line 491 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
491          SDError         ec;
492          int             i;
493                                          /* check arguments */
494 <        if ((projSA == NULL) | (v1 == NULL))
494 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
495                  return SDEargument;
496                                          /* initialize extrema */
497          switch (qflags) {
# Line 515 | Line 511 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
511                  rdf = sd->rf;
512          else
513                  rdf = sd->rb;
514 <        tdf = NULL;                     /* transmitted component? */
515 <        if (v2 != NULL && v1[2] > 0 ^ v2[2] > 0) {
516 <                rdf = NULL;
517 <                tdf = sd->tf;
518 <        }
514 >        tdf = sd->tf;
515 >        if (v2 != NULL)                 /* bidirectional? */
516 >                if (v1[2] > 0 ^ v2[2] > 0)
517 >                        rdf = NULL;
518 >                else
519 >                        tdf = NULL;
520          ec = SDEdata;                   /* run through components */
521          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
522                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
523 <                                                qflags, rdf->comp[i].dist);
523 >                                                qflags, &rdf->comp[i]);
524                  if (ec)
525                          return ec;
526          }
527          for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) {
528                  ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2,
529 <                                                qflags, tdf->comp[i].dist);
529 >                                                qflags, &tdf->comp[i]);
530                  if (ec)
531                          return ec;
532          }
# Line 571 | Line 568 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
568          i = (sdf != NULL) ? sdf->ncomp : 0;
569          while (i-- > 0) {
570                  nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
571 <                                                        sdf->comp[i].dist);
571 >                                                        &sdf->comp[i]);
572                  while (nch-- > 0) {
573                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
574                                          coef[nch], &sdf->comp[i].cspec[nch]);
# Line 626 | Line 623 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
623  
624   /* Sample BSDF direction based on the given random variable */
625   SDError
626 < SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec,
630 <                        double randX, int sflags, const SDData *sd)
626 > SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd)
627   {
628          SDError         ec;
629 +        FVECT           inVec;
630          int             inFront;
631          SDSpectralDF    *rdf;
632          double          rdiff;
# Line 638 | Line 635 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
635          SDComponent     *sdc;
636          const SDCDst    **cdarr = NULL;
637                                          /* check arguments */
638 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) |
638 >        if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) |
639                          (randX < 0) | (randX >= 1.))
640                  return SDEargument;
641                                          /* whose side are we on? */
642 +        VCOPY(inVec, ioVec);
643          inFront = (inVec[2] > 0);
644                                          /* remember diffuse portions */
645          if (inFront) {
# Line 682 | Line 680 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
680          }
681          if (sv->cieY <= 1e-7) {         /* anything to sample? */
682                  sv->cieY = .0;
683 <                memset(outVec, 0, 3*sizeof(double));
683 >                memset(ioVec, 0, 3*sizeof(double));
684                  return SDEnone;
685          }
686                                          /* scale random variable */
687          randX *= sv->cieY;
688                                          /* diffuse reflection? */
689          if (randX < rdiff) {
690 <                SDdiffuseSamp(outVec, inFront, randX/rdiff);
690 >                SDdiffuseSamp(ioVec, inFront, randX/rdiff);
691                  goto done;
692          }
693          randX -= rdiff;
# Line 697 | Line 695 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
695          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
696                  if (randX < sd->tLamb.cieY) {
697                          sv->spec = sd->tLamb.spec;
698 <                        SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY);
698 >                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
699                          goto done;
700                  }
701                  randX -= sd->tLamb.cieY;
# Line 709 | Line 707 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
707                  return SDEinternal;
708                                          /* compute sample direction */
709          sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr];
710 <        ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]);
710 >        ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]);
711          if (ec)
712                  return ec;
713                                          /* compute color */
714 <        j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
714 >        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
715          if (j <= 0) {
716                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
717                                  sd->name);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines