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.9 by greg, Thu Jun 13 13:58:16 1991 UTC vs.
Revision 1.16 by greg, Mon Aug 12 08:20:53 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 247 | 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]))
251 <                        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]))
255 <                        loadfunc(m->oargs.sarg[9]);
252 >                funcfile(m->oargs.sarg[9]);
253          } else {
254                  nd.dp = NULL;
255 <                if (!fundefined(m->oargs.sarg[0]))
259 <                        loadfunc(m->oargs.sarg[1]);
255 >                funcfile(m->oargs.sarg[1]);
256          }
257                                                  /* set special variables */
258 <        setfunc(m, r);
263 <        multv3(vec, nd.pnorm, funcxf.xfm);
264 <        varset("NxP", '=', vec[0]/funcxf.sca);
265 <        varset("NyP", '=', vec[1]/funcxf.sca);
266 <        varset("NzP", '=', vec[2]/funcxf.sca);
267 <        varset("RdotP", '=', nd.pdot);
268 <        varset("CrP", '=', colval(nd.mcolor,RED));
269 <        varset("CgP", '=', colval(nd.mcolor,GRN));
270 <        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 <                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
270 >                else if ((tspect = bright(ctmp)) > FTINY &&
271 >                                rayorigin(&sr, r, TRANS, tspect) == 0) {
272 >                        if (!(r->crtype & SHADOW) &&
273 >                                        DOT(r->pert,r->pert) > FTINY*FTINY) {
274                                  for (i = 0; i < 3; i++) /* perturb direction */
275                                          sr.rdir[i] = r->rdir[i] -
276                                                          .75*r->pert[i];
# Line 299 | Line 289 | register RAY  *r;
289          if (r->crtype & SHADOW)                 /* the rest is shadow */
290                  return;
291                                                  /* compute reflected ray */
292 +        rspecr = 0.;
293          if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
294                  RAY  sr;
295                  errno = 0;
296 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
297 <                                varvalue(m->oargs.sarg[4]),
298 <                                varvalue(m->oargs.sarg[5]));
308 <                scalecolor(ctmp, nd.rspec);
296 >                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
297 >                                varvalue(m->oargs.sarg[1]),
298 >                                varvalue(m->oargs.sarg[2]));
299                  if (errno)
300                          objerror(m, WARNING, "compute error");
301 <                else if ((dtmp = bright(ctmp)) > FTINY &&
302 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
301 >                else if ((rspecr = bright(ctmp)) > FTINY &&
302 >                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
303                          for (i = 0; i < 3; i++)
304                                  sr.rdir[i] = r->rdir[i] +
305                                                  2.0*nd.pdot*nd.pnorm[i];
# Line 319 | Line 309 | register RAY  *r;
309                  }
310          }
311                                                  /* compute ambient */
312 <        if (nd.rdiff > FTINY) {
312 >        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
313                  ambient(ctmp, r);
314 <                if (m->otype == MAT_BRTDF)
325 <                        scalecolor(ctmp, nd.rdiff);
326 <                else
327 <                        scalecolor(ctmp, 1.0-nd.trans);
314 >                scalecolor(ctmp, dtmp);
315                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
316                  addcolor(r->rcol, ctmp);        /* add to returned color */
317          }
318 <        if (nd.tdiff > FTINY) {                 /* from other side */
318 >        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
319                  flipsurface(r);
320                  ambient(ctmp, r);
321 <                if (m->otype == MAT_BRTDF)
335 <                        scalecolor(ctmp, nd.tdiff);
336 <                else
337 <                        scalecolor(ctmp, nd.trans);
321 >                scalecolor(ctmp, dtmp);
322                  multcolor(ctmp, nd.mcolor);
323                  addcolor(r->rcol, ctmp);
324                  flipsurface(r);
# Line 344 | Line 328 | register RAY  *r;
328                                                  /* check distance */
329          if (transtest > bright(r->rcol))
330                  r->rt = transdist;
331 + }
332 +
333 +
334 + setbrdfunc(np)                  /* set up brdf function and variables */
335 + register BRDFDAT  *np;
336 + {
337 +        FVECT  vec;
338 +
339 +        if (setfunc(np->mp, np->pr) == 0)
340 +                return(0);      /* it's OK, setfunc says we're done */
341 +                                /* else (re)assign special variables */
342 +        multv3(vec, np->pnorm, funcxf.xfm);
343 +        varset("NxP", '=', vec[0]/funcxf.sca);
344 +        varset("NyP", '=', vec[1]/funcxf.sca);
345 +        varset("NzP", '=', vec[2]/funcxf.sca);
346 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
347 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
348 +        varset("CrP", '=', colval(np->mcolor,RED));
349 +        varset("CgP", '=', colval(np->mcolor,GRN));
350 +        varset("CbP", '=', colval(np->mcolor,BLU));
351 +        return(1);
352   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines