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.29 by greg, Fri Jun 3 18:12:58 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines