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.7 by greg, Wed May 8 08:27:50 1991 UTC vs.
Revision 1.14 by greg, Tue Jul 16 16:45:55 1991 UTC

# 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 191 | Line 191 | register RAY  *r;
191          BRDFDAT  nd;
192          double  transtest, transdist;
193          COLOR  ctmp;
194 <        double  dtmp;
195 <        FVECT  vec;
194 >        double  dtmp, tspect, rspecr;
195          register int  i;
196                                                  /* check arguments */
197          switch (m->otype) {
# Line 237 | 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 */
240        r->rt = r->rot;                         /* default ray length */
239          transtest = 0;
240                                                  /* load auxiliary files */
241          if (m->otype == MAT_PDATA || m->otype == MAT_MDATA
# Line 260 | Line 258 | register RAY  *r;
258                          loadfunc(m->oargs.sarg[1]);
259          }
260                                                  /* set special variables */
261 <        setfunc(m, r);
264 <        multv3(vec, nd.pnorm, funcxf.xfm);
265 <        varset("NxP", '=', vec[0]/funcxf.sca);
266 <        varset("NyP", '=', vec[1]/funcxf.sca);
267 <        varset("NzP", '=', vec[2]/funcxf.sca);
268 <        varset("RdotP", '=', nd.pdot);
269 <        varset("CrP", '=', colval(nd.mcolor,RED));
270 <        varset("CgP", '=', colval(nd.mcolor,GRN));
271 <        varset("CbP", '=', colval(nd.mcolor,BLU));
261 >        setbrdfunc(&nd);
262                                                  /* compute transmitted ray */
263 +        tspect = 0.;
264          if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
265                  RAY  sr;
266                  errno = 0;
267 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
268 <                                varvalue(m->oargs.sarg[1]),
269 <                                varvalue(m->oargs.sarg[2]));
270 <                scalecolor(ctmp, nd.tspec);
267 >                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
268 >                                varvalue(m->oargs.sarg[4]),
269 >                                varvalue(m->oargs.sarg[5]));
270 >                scalecolor(ctmp, nd.trans);
271                  if (errno)
272                          objerror(m, WARNING, "compute error");
273 <                else if ((dtmp = bright(ctmp)) > FTINY &&
274 <                                rayorigin(&sr, r, TRANS, dtmp) == 0) {
273 >                else if ((tspect = bright(ctmp)) > FTINY &&
274 >                                rayorigin(&sr, r, TRANS, tspect) == 0) {
275                          if (DOT(r->pert,r->pert) > FTINY*FTINY) {
276                                  for (i = 0; i < 3; i++) /* perturb direction */
277                                          sr.rdir[i] = r->rdir[i] -
278                                                          .75*r->pert[i];
279                                  normalize(sr.rdir);
280 <                        } else
280 >                        } else {
281 >                                VCOPY(sr.rdir, r->rdir);
282                                  transtest = 2;
283 +                        }
284                          rayvalue(&sr);
285                          multcolor(sr.rcol, ctmp);
286                          addcolor(r->rcol, sr.rcol);
# Line 298 | Line 291 | register RAY  *r;
291          if (r->crtype & SHADOW)                 /* the rest is shadow */
292                  return;
293                                                  /* compute reflected ray */
294 +        rspecr = 0.;
295          if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
296                  RAY  sr;
297                  errno = 0;
298 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
299 <                                varvalue(m->oargs.sarg[4]),
300 <                                varvalue(m->oargs.sarg[5]));
307 <                scalecolor(ctmp, nd.rspec);
298 >                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
299 >                                varvalue(m->oargs.sarg[1]),
300 >                                varvalue(m->oargs.sarg[2]));
301                  if (errno)
302                          objerror(m, WARNING, "compute error");
303 <                else if ((dtmp = bright(ctmp)) > FTINY &&
304 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
303 >                else if ((rspecr = bright(ctmp)) > FTINY &&
304 >                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
305                          for (i = 0; i < 3; i++)
306                                  sr.rdir[i] = r->rdir[i] +
307                                                  2.0*nd.pdot*nd.pnorm[i];
# Line 318 | Line 311 | register RAY  *r;
311                  }
312          }
313                                                  /* compute ambient */
314 <        if (nd.rdiff > FTINY) {
314 >        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
315                  ambient(ctmp, r);
316 <                if (m->otype == MAT_BRTDF)
324 <                        scalecolor(ctmp, nd.rdiff);
325 <                else
326 <                        scalecolor(ctmp, 1.0-nd.trans);
316 >                scalecolor(ctmp, dtmp);
317                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
318                  addcolor(r->rcol, ctmp);        /* add to returned color */
319          }
320 <        if (nd.tdiff > FTINY) {                 /* from other side */
320 >        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
321                  flipsurface(r);
322                  ambient(ctmp, r);
323 <                if (m->otype == MAT_BRTDF)
334 <                        scalecolor(ctmp, nd.tdiff);
335 <                else
336 <                        scalecolor(ctmp, nd.trans);
323 >                scalecolor(ctmp, dtmp);
324                  multcolor(ctmp, nd.mcolor);
325                  addcolor(r->rcol, ctmp);
326                  flipsurface(r);
# Line 343 | Line 330 | register RAY  *r;
330                                                  /* check distance */
331          if (transtest > bright(r->rcol))
332                  r->rt = transdist;
333 + }
334 +
335 +
336 + setbrdfunc(np)                  /* set up brdf function and variables */
337 + register BRDFDAT  *np;
338 + {
339 +        FVECT  vec;
340 +
341 +        if (setfunc(np->mp, np->pr) == 0)
342 +                return(0);      /* it's OK, setfunc says we're done */
343 +                                /* else (re)assign special variables */
344 +        multv3(vec, np->pnorm, funcxf.xfm);
345 +        varset("NxP", '=', vec[0]/funcxf.sca);
346 +        varset("NyP", '=', vec[1]/funcxf.sca);
347 +        varset("NzP", '=', vec[2]/funcxf.sca);
348 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
349 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
350 +        varset("CrP", '=', colval(np->mcolor,RED));
351 +        varset("CgP", '=', colval(np->mcolor,GRN));
352 +        varset("CbP", '=', colval(np->mcolor,BLU));
353 +        return(1);
354   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines