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.13 by greg, Wed Jul 10 09:35:26 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]));
267 >                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
268 >                                varvalue(m->oargs.sarg[4]),
269 >                                varvalue(m->oargs.sarg[5]));
270                  scalecolor(ctmp, nd.tspec);
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]));
298 >                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
299 >                                varvalue(m->oargs.sarg[1]),
300 >                                varvalue(m->oargs.sarg[2]));
301                  scalecolor(ctmp, nd.rspec);
302                  if (errno)
303                          objerror(m, WARNING, "compute error");
304 <                else if ((dtmp = bright(ctmp)) > FTINY &&
305 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
304 >                else if ((rspecr = bright(ctmp)) > FTINY &&
305 >                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
306                          for (i = 0; i < 3; i++)
307                                  sr.rdir[i] = r->rdir[i] +
308                                                  2.0*nd.pdot*nd.pnorm[i];
# Line 318 | Line 312 | register RAY  *r;
312                  }
313          }
314                                                  /* compute ambient */
315 <        if (nd.rdiff > FTINY) {
315 >        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
316                  ambient(ctmp, r);
317 <                if (m->otype == MAT_BRTDF)
324 <                        scalecolor(ctmp, nd.rdiff);
325 <                else
326 <                        scalecolor(ctmp, 1.0-nd.trans);
317 >                scalecolor(ctmp, dtmp);
318                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
319                  addcolor(r->rcol, ctmp);        /* add to returned color */
320          }
321 <        if (nd.tdiff > FTINY) {                 /* from other side */
321 >        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
322                  flipsurface(r);
323                  ambient(ctmp, r);
324 <                if (m->otype == MAT_BRTDF)
334 <                        scalecolor(ctmp, nd.tdiff);
335 <                else
336 <                        scalecolor(ctmp, nd.trans);
324 >                scalecolor(ctmp, dtmp);
325                  multcolor(ctmp, nd.mcolor);
326                  addcolor(r->rcol, ctmp);
327                  flipsurface(r);
# Line 343 | Line 331 | register RAY  *r;
331                                                  /* check distance */
332          if (transtest > bright(r->rcol))
333                  r->rt = transdist;
334 + }
335 +
336 +
337 + setbrdfunc(np)                  /* set up brdf function and variables */
338 + register BRDFDAT  *np;
339 + {
340 +        FVECT  vec;
341 +
342 +        if (setfunc(np->mp, np->pr) == 0)
343 +                return(0);      /* it's OK, setfunc says we're done */
344 +                                /* else (re)assign special variables */
345 +        multv3(vec, np->pnorm, funcxf.xfm);
346 +        varset("NxP", '=', vec[0]/funcxf.sca);
347 +        varset("NyP", '=', vec[1]/funcxf.sca);
348 +        varset("NzP", '=', vec[2]/funcxf.sca);
349 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
350 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
351 +        varset("CrP", '=', colval(np->mcolor,RED));
352 +        varset("CgP", '=', colval(np->mcolor,GRN));
353 +        varset("CbP", '=', colval(np->mcolor,BLU));
354 +        return(1);
355   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines