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

Comparing ray/src/rt/m_brdf.c (file contents):
Revision 1.15 by greg, Thu Aug 8 11:30:01 1991 UTC vs.
Revision 2.4 by greg, Wed Oct 14 12:30:54 1992 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "otypes.h"
16  
17 + #include  "func.h"
18 +
19   /*
20   *      Arguments to this material include the color and specularity.
21   *  String arguments include the reflection function and files.
# Line 58 | Line 60 | static char SCCSid[] = "$SunId$ LBL";
60   *              CrP, CgP, CbP -         perturbed material color
61   */
62  
61 extern double   funvalue(), varvalue();
62 extern XF  funcxf;
63
63   typedef struct {
64          OBJREC  *mp;            /* material pointer */
65          RAY  *pr;               /* intersected ray */
# Line 86 | Line 85 | double  omega;                 /* light source size */
85          double  dtmp;
86          COLOR  ctmp;
87          FVECT  ldx;
88 <        double  pt[MAXDIM];
88 >        double  lddx[3], pt[MAXDIM];
89          register char   **sa;
90          register int    i;
91  
# Line 128 | Line 127 | double  omega;                 /* light source size */
127                                          /* transform light vector */
128          multv3(ldx, ldir, funcxf.xfm);
129          for (i = 0; i < 3; i++)
130 <                ldx[i] /= funcxf.sca;
130 >                lddx[i] = ldx[i]/funcxf.sca;
131                                          /* compute BRTDF */
132          if (np->mp->otype == MAT_BRTDF) {
133 <                colval(ctmp,RED) = funvalue(sa[6], 3, ldx);
133 >                colval(ctmp,RED) = funvalue(sa[6], 3, lddx);
134                  if (!strcmp(sa[7],sa[6]))
135                          colval(ctmp,GRN) = colval(ctmp,RED);
136                  else
137 <                        colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
137 >                        colval(ctmp,GRN) = funvalue(sa[7], 3, lddx);
138                  if (!strcmp(sa[8],sa[6]))
139                          colval(ctmp,BLU) = colval(ctmp,RED);
140                  else if (!strcmp(sa[8],sa[7]))
141                          colval(ctmp,BLU) = colval(ctmp,GRN);
142                  else
143 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
143 >                        colval(ctmp,BLU) = funvalue(sa[8], 3, lddx);
144                  dtmp = bright(ctmp);
145          } else if (np->dp == NULL) {
146 <                dtmp = funvalue(sa[0], 3, ldx);
146 >                dtmp = funvalue(sa[0], 3, lddx);
147                  setcolor(ctmp, dtmp, dtmp, dtmp);
148          } else {
149                  for (i = 0; i < np->dp->nd; i++)
150 <                        pt[i] = funvalue(sa[3+i], 3, ldx);
150 >                        pt[i] = funvalue(sa[3+i], 3, lddx);
151                  dtmp = datavalue(np->dp, pt);
152                  dtmp = funvalue(sa[0], 1, &dtmp);
153                  setcolor(ctmp, dtmp, dtmp, dtmp);
154          }
155 <        if (errno)
156 <                goto computerr;
155 >        if (errno) {
156 >                objerror(np->mp, WARNING, "compute error");
157 >                return;
158 >        }
159          if (dtmp <= FTINY)
160                  return;
161          if (ldot > 0.0) {
# Line 176 | Line 177 | double  omega;                 /* light source size */
177                  scalecolor(ctmp, dtmp);
178                  addcolor(cval, ctmp);
179          }
179        return;
180 computerr:
181        objerror(np->mp, WARNING, "compute error");
182        return;
180   }
181  
182  
# Line 192 | Line 189 | register RAY  *r;
189          double  transtest, transdist;
190          COLOR  ctmp;
191          double  dtmp, tspect, rspecr;
192 +        MFUNC  *mf;
193          register int  i;
194                                                  /* check arguments */
195          switch (m->otype) {
# Line 238 | Line 236 | register RAY  *r;
236          multcolor(nd.mcolor, r->pcol);          /* modify material color */
237          transtest = 0;
238                                                  /* load auxiliary files */
239 <        if (m->otype == MAT_PDATA || m->otype == MAT_MDATA
242 <                        || m->otype == MAT_TDATA) {
239 >        if (hasdata(m->otype)) {
240                  nd.dp = getdata(m->oargs.sarg[1]);
241 <                for (i = 3; i < m->oargs.nsargs; i++)
242 <                        if (m->oargs.sarg[i][0] == '-')
246 <                                break;
247 <                if (i-3 != nd.dp->nd)
248 <                        objerror(m, USER, "dimension error");
249 <                funcfile(m->oargs.sarg[2]);
241 >                i = (1 << nd.dp->nd) - 1;
242 >                mf = getfunc(m, 2, i<<3, 0);
243          } else if (m->otype == MAT_BRTDF) {
244                  nd.dp = NULL;
245 <                funcfile(m->oargs.sarg[9]);
245 >                mf = getfunc(m, 9, 0x3f, 0);
246          } else {
247                  nd.dp = NULL;
248 <                funcfile(m->oargs.sarg[1]);
248 >                mf = getfunc(m, 1, 0, 0);
249          }
250                                                  /* set special variables */
251          setbrdfunc(&nd);
# Line 261 | Line 254 | register RAY  *r;
254          if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
255                  RAY  sr;
256                  errno = 0;
257 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
258 <                                varvalue(m->oargs.sarg[4]),
259 <                                varvalue(m->oargs.sarg[5]));
257 >                setcolor(ctmp, evalue(mf->ep[3]),
258 >                                evalue(mf->ep[4]),
259 >                                evalue(mf->ep[5]));
260                  scalecolor(ctmp, nd.trans);
261                  if (errno)
262                          objerror(m, WARNING, "compute error");
263                  else if ((tspect = bright(ctmp)) > FTINY &&
264                                  rayorigin(&sr, r, TRANS, tspect) == 0) {
265 <                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
265 >                        if (!(r->crtype & SHADOW) &&
266 >                                        DOT(r->pert,r->pert) > FTINY*FTINY) {
267                                  for (i = 0; i < 3; i++) /* perturb direction */
268                                          sr.rdir[i] = r->rdir[i] -
269                                                          .75*r->pert[i];
270 <                                normalize(sr.rdir);
270 >                                if (normalize(sr.rdir) == 0.0) {
271 >                                        objerror(m, WARNING, "illegal perturbation");
272 >                                        VCOPY(sr.rdir, r->rdir);
273 >                                }
274                          } else {
275                                  VCOPY(sr.rdir, r->rdir);
276                                  transtest = 2;
# Line 292 | Line 289 | register RAY  *r;
289          if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
290                  RAY  sr;
291                  errno = 0;
292 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
293 <                                varvalue(m->oargs.sarg[1]),
294 <                                varvalue(m->oargs.sarg[2]));
292 >                setcolor(ctmp, evalue(mf->ep[0]),
293 >                                evalue(mf->ep[1]),
294 >                                evalue(mf->ep[2]));
295                  if (errno)
296                          objerror(m, WARNING, "compute error");
297                  else if ((rspecr = bright(ctmp)) > FTINY &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines