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

Comparing ray/src/util/cmbsdf.c (file contents):
Revision 2.1 by greg, Mon Jan 20 21:29:04 2014 UTC vs.
Revision 2.4 by greg, Thu Aug 27 04:33:31 2015 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15  
16   /* Convert a BSDF to our matrix representation */
17   static CMATRIX *
18 < cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
18 > cm_bsdf(const COLOR diffBSDF, const SDMat *bsdf)
19   {
20          CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
21          int     nbadohm = 0;
# Line 33 | Line 33 | cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, con
33                                          /* check BSDF value */
34                          if ((f <= 0) | (dom <= 0)) {
35                                  nneg += (f < -FTINY);
36 <                                f = .0f;
37 <                        }
38 <                        copycolor(mp, specCol);
39 <                        scalecolor(mp, f);
40 <                        addcolor(mp, bsdfLamb);
36 >                                setcolor(mp, .0f, .0f, .0f);
37 >                        } else if (bsdf->chroma != NULL) {
38 >                                C_COLOR cxy;
39 >                                c_decodeChroma(&cxy, mBSDF_chroma(bsdf,c,r));
40 >                                ccy2rgb(&cxy, f, mp);
41 >                        } else
42 >                                setcolor(mp, f, f, f);
43 >                        addcolor(mp, diffBSDF);
44                          scalecolor(mp, dom);
45                  }
46          }
# Line 76 | Line 79 | recip_in_from_out(const SDMat *bsdf, int out_recip)
79  
80   /* Convert a BSDF to our matrix representation, applying reciprocity */
81   static CMATRIX *
82 < cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
82 > cm_bsdf_recip(const COLOR diffBSDF, const SDMat *bsdf)
83   {
84          CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout);
85          int     nbadohm = 0;
# Line 96 | Line 99 | cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCo
99                                          /* check BSDF value */
100                          if ((f <= 0) | (dom <= 0)) {
101                                  nneg += (f < -FTINY);
102 <                                f = .0f;
103 <                        }
104 <                        copycolor(mp, specCol);
105 <                        scalecolor(mp, f);
106 <                        addcolor(mp, bsdfLamb);
102 >                                setcolor(mp, .0f, .0f, .0f);
103 >                        } else if (bsdf->chroma != NULL) {
104 >                                C_COLOR cxy;
105 >                                c_decodeChroma(&cxy, mBSDF_chroma(bsdf,ri,ro));
106 >                                ccy2rgb(&cxy, f, mp);
107 >                        } else
108 >                                setcolor(mp, f, f, f);
109 >                        addcolor(mp, diffBSDF);
110                          scalecolor(mp, dom);
111                  }
112          }
# Line 113 | Line 119 | cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCo
119          return(cm);
120   }
121  
122 < /* Load and convert a matrix BSDF from the given XML file */
122 > /* Return a Lambertian (diffuse) matrix */
123 > static CMATRIX *
124 > cm_bsdf_Lamb(const COLOR diffBSDF)
125 > {
126 >        CMATRIX *cm = cm_alloc(145, 145);       /* this is a hack */
127 >        int     r, c;
128 >
129 >        for (c = 0; c < cm->ncols; c++)
130 >                for (r = 0; r < cm->nrows; r++) {
131 >                        COLORV  *mp = cm_lval(cm,r,c);
132 >                        copycolor(mp, diffBSDF);
133 >                }
134 >        return(cm);
135 > }
136 >
137 > /* Load and convert a matrix BTDF from the given XML file */
138   CMATRIX *
139 < cm_loadBSDF(char *fname, COLOR cLamb)
139 > cm_loadBTDF(char *fname)
140   {
141          CMATRIX         *Tmat;
142          char            *fpath;
# Line 123 | Line 144 | cm_loadBSDF(char *fname, COLOR cLamb)
144          SDError         ec;
145          SDData          myBSDF;
146          SDSpectralDF    *tdf;
147 <        COLOR           bsdfLamb, specCol;
147 >        COLOR           diffBSDF;
148                                          /* find path to BSDF file */
149          fpath = getpath(fname, getrlibpath(), R_OK);
150          if (fpath == NULL) {
# Line 134 | Line 155 | cm_loadBSDF(char *fname, COLOR cLamb)
155          ec = SDloadFile(&myBSDF, fpath);
156          if (ec)
157                  error(USER, transSDError(ec));
158 <        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb);
158 >        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, diffBSDF);
159          recip = (myBSDF.tb == NULL);
160          tdf = recip ? myBSDF.tf : myBSDF.tb;
161          if (tdf == NULL) {              /* no non-Lambertian transmission? */
141                if (cLamb != NULL)
142                        copycolor(cLamb, bsdfLamb);
162                  SDfreeBSDF(&myBSDF);
163 <                return(NULL);
163 >                return(cm_bsdf_Lamb(diffBSDF));
164          }
165          if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) {
166                  sprintf(errmsg, "unsupported BSDF '%s'", fpath);
167                  error(USER, errmsg);
168          }
169                                          /* convert BTDF to matrix */
170 <        ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol);
171 <        Tmat = recip ? cm_bsdf_recip(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist)
153 <                        : cm_bsdf(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist);
154 <        if (cLamb != NULL)              /* Lambertian is included */
155 <                setcolor(cLamb, .0, .0, .0);
170 >        Tmat = recip ? cm_bsdf_recip(diffBSDF, (SDMat *)tdf->comp[0].dist)
171 >                        : cm_bsdf(diffBSDF, (SDMat *)tdf->comp[0].dist);
172                                          /* free BSDF and return */
173          SDfreeBSDF(&myBSDF);
174          return(Tmat);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines