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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines