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.6 by greg, Tue May 7 17:45:47 1991 UTC vs.
Revision 1.15 by greg, Thu Aug 8 11:30:01 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 122 | Line 122 | double  omega;                 /* light source size */
122          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
123                  return;         /* no specular component */
124                                          /* set up function */
125 <        setfunc(np->mp, np->pr);
125 >        setbrdfunc(np);
126          sa = np->mp->oargs.sarg;
127          errno = 0;
128                                          /* transform light vector */
# Line 132 | Line 132 | double  omega;                 /* light source size */
132                                          /* compute BRTDF */
133          if (np->mp->otype == MAT_BRTDF) {
134                  colval(ctmp,RED) = funvalue(sa[6], 3, ldx);
135 <                if (sa[7] == sa[6])
135 >                if (!strcmp(sa[7],sa[6]))
136                          colval(ctmp,GRN) = colval(ctmp,RED);
137                  else
138                          colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
139 <                if (sa[8] == sa[6])
139 >                if (!strcmp(sa[8],sa[6]))
140                          colval(ctmp,BLU) = colval(ctmp,RED);
141 <                else if (sa[8] == sa[7])
141 >                else if (!strcmp(sa[8],sa[7]))
142                          colval(ctmp,BLU) = colval(ctmp,GRN);
143                  else
144                          colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
# Line 189 | Line 189 | register RAY  *r;
189   {
190          int  minsa, minfa;
191          BRDFDAT  nd;
192 +        double  transtest, transdist;
193          COLOR  ctmp;
194 <        double  dtmp;
194 <        FVECT  vec;
194 >        double  dtmp, tspect, rspecr;
195          register int  i;
196                                                  /* check arguments */
197          switch (m->otype) {
# Line 236 | Line 236 | register RAY  *r;
236          raytexture(r, m->omod);
237          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
238          multcolor(nd.mcolor, r->pcol);          /* modify material color */
239 <        r->rt = r->rot;                         /* default ray length */
239 >        transtest = 0;
240                                                  /* load auxiliary files */
241          if (m->otype == MAT_PDATA || m->otype == MAT_MDATA
242                          || m->otype == MAT_TDATA) {
# Line 246 | Line 246 | register RAY  *r;
246                                  break;
247                  if (i-3 != nd.dp->nd)
248                          objerror(m, USER, "dimension error");
249 <                if (!fundefined(m->oargs.sarg[3]))
250 <                        loadfunc(m->oargs.sarg[2]);
249 >                funcfile(m->oargs.sarg[2]);
250          } else if (m->otype == MAT_BRTDF) {
251                  nd.dp = NULL;
252 <                if (!fundefined(m->oargs.sarg[7]))
254 <                        loadfunc(m->oargs.sarg[9]);
252 >                funcfile(m->oargs.sarg[9]);
253          } else {
254                  nd.dp = NULL;
255 <                if (!fundefined(m->oargs.sarg[0]))
258 <                        loadfunc(m->oargs.sarg[1]);
255 >                funcfile(m->oargs.sarg[1]);
256          }
257                                                  /* set special variables */
258 <        setfunc(m, r);
262 <        multv3(vec, nd.pnorm, funcxf.xfm);
263 <        varset("NxP", '=', vec[0]/funcxf.sca);
264 <        varset("NyP", '=', vec[1]/funcxf.sca);
265 <        varset("NzP", '=', vec[2]/funcxf.sca);
266 <        varset("RdotP", '=', nd.pdot);
267 <        varset("CrP", '=', colval(nd.mcolor,RED));
268 <        varset("CgP", '=', colval(nd.mcolor,GRN));
269 <        varset("CbP", '=', colval(nd.mcolor,BLU));
258 >        setbrdfunc(&nd);
259                                                  /* compute transmitted ray */
260 +        tspect = 0.;
261          if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
262                  RAY  sr;
263                  errno = 0;
264 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
265 <                                varvalue(m->oargs.sarg[1]),
266 <                                varvalue(m->oargs.sarg[2]));
267 <                scalecolor(ctmp, nd.tspec);
264 >                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
265 >                                varvalue(m->oargs.sarg[4]),
266 >                                varvalue(m->oargs.sarg[5]));
267 >                scalecolor(ctmp, nd.trans);
268                  if (errno)
269                          objerror(m, WARNING, "compute error");
270 <                else if ((dtmp = bright(ctmp)) > FTINY &&
271 <                                rayorigin(&sr, r, TRANS, dtmp) == 0) {
272 <                        VCOPY(sr.rdir, r->rdir);
270 >                else if ((tspect = bright(ctmp)) > FTINY &&
271 >                                rayorigin(&sr, r, TRANS, tspect) == 0) {
272 >                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
273 >                                for (i = 0; i < 3; i++) /* perturb direction */
274 >                                        sr.rdir[i] = r->rdir[i] -
275 >                                                        .75*r->pert[i];
276 >                                normalize(sr.rdir);
277 >                        } else {
278 >                                VCOPY(sr.rdir, r->rdir);
279 >                                transtest = 2;
280 >                        }
281                          rayvalue(&sr);
282                          multcolor(sr.rcol, ctmp);
283                          addcolor(r->rcol, sr.rcol);
284 <                        if (dtmp > .5)
285 <                                r->rt = r->rot + sr.rt;
284 >                        transtest *= bright(sr.rcol);
285 >                        transdist = r->rot + sr.rt;
286                  }
287          }
288          if (r->crtype & SHADOW)                 /* the rest is shadow */
289                  return;
290                                                  /* compute reflected ray */
291 +        rspecr = 0.;
292          if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
293                  RAY  sr;
294                  errno = 0;
295 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
296 <                                varvalue(m->oargs.sarg[4]),
297 <                                varvalue(m->oargs.sarg[5]));
299 <                scalecolor(ctmp, nd.rspec);
295 >                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
296 >                                varvalue(m->oargs.sarg[1]),
297 >                                varvalue(m->oargs.sarg[2]));
298                  if (errno)
299                          objerror(m, WARNING, "compute error");
300 <                else if ((dtmp = bright(ctmp)) > FTINY &&
301 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
300 >                else if ((rspecr = bright(ctmp)) > FTINY &&
301 >                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
302                          for (i = 0; i < 3; i++)
303                                  sr.rdir[i] = r->rdir[i] +
304                                                  2.0*nd.pdot*nd.pnorm[i];
# Line 310 | Line 308 | register RAY  *r;
308                  }
309          }
310                                                  /* compute ambient */
311 <        if (nd.rdiff > FTINY) {
311 >        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
312                  ambient(ctmp, r);
313 <                if (m->otype == MAT_BRTDF)
316 <                        scalecolor(ctmp, nd.rdiff);
317 <                else
318 <                        scalecolor(ctmp, 1.0-nd.trans);
313 >                scalecolor(ctmp, dtmp);
314                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
315                  addcolor(r->rcol, ctmp);        /* add to returned color */
316          }
317 <        if (nd.tdiff > FTINY) {                 /* from other side */
317 >        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
318                  flipsurface(r);
319                  ambient(ctmp, r);
320 <                if (m->otype == MAT_BRTDF)
326 <                        scalecolor(ctmp, nd.tdiff);
327 <                else
328 <                        scalecolor(ctmp, nd.trans);
320 >                scalecolor(ctmp, dtmp);
321                  multcolor(ctmp, nd.mcolor);
322                  addcolor(r->rcol, ctmp);
323                  flipsurface(r);
324          }
325                                                  /* add direct component */
326          direct(r, dirbrdf, &nd);
327 +                                                /* check distance */
328 +        if (transtest > bright(r->rcol))
329 +                r->rt = transdist;
330 + }
331 +
332 +
333 + setbrdfunc(np)                  /* set up brdf function and variables */
334 + register BRDFDAT  *np;
335 + {
336 +        FVECT  vec;
337 +
338 +        if (setfunc(np->mp, np->pr) == 0)
339 +                return(0);      /* it's OK, setfunc says we're done */
340 +                                /* else (re)assign special variables */
341 +        multv3(vec, np->pnorm, funcxf.xfm);
342 +        varset("NxP", '=', vec[0]/funcxf.sca);
343 +        varset("NyP", '=', vec[1]/funcxf.sca);
344 +        varset("NzP", '=', vec[2]/funcxf.sca);
345 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
346 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
347 +        varset("CrP", '=', colval(np->mcolor,RED));
348 +        varset("CgP", '=', colval(np->mcolor,GRN));
349 +        varset("CbP", '=', colval(np->mcolor,BLU));
350 +        return(1);
351   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines