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.12 by greg, Fri Jun 28 10:04:02 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;
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 258 | Line 258 | register RAY  *r;
258                          loadfunc(m->oargs.sarg[1]);
259          }
260                                                  /* set special variables */
261 <        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));
261 >        setbrdfunc(&nd);
262                                                  /* compute transmitted ray */
263          if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
264                  RAY  sr;
265                  errno = 0;
266 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
267 <                                varvalue(m->oargs.sarg[1]),
268 <                                varvalue(m->oargs.sarg[2]));
266 >                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
267 >                                varvalue(m->oargs.sarg[4]),
268 >                                varvalue(m->oargs.sarg[5]));
269                  scalecolor(ctmp, nd.tspec);
270                  if (errno)
271                          objerror(m, WARNING, "compute error");
272                  else if ((dtmp = bright(ctmp)) > FTINY &&
273                                  rayorigin(&sr, r, TRANS, dtmp) == 0) {
274 <                        VCOPY(sr.rdir, r->rdir);
274 >                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
275 >                                for (i = 0; i < 3; i++) /* perturb direction */
276 >                                        sr.rdir[i] = r->rdir[i] -
277 >                                                        .75*r->pert[i];
278 >                                normalize(sr.rdir);
279 >                        } else {
280 >                                VCOPY(sr.rdir, r->rdir);
281 >                                transtest = 2;
282 >                        }
283                          rayvalue(&sr);
284                          multcolor(sr.rcol, ctmp);
285                          addcolor(r->rcol, sr.rcol);
286 <                        if (dtmp > .5)
287 <                                r->rt = r->rot + sr.rt;
286 >                        transtest *= bright(sr.rcol);
287 >                        transdist = r->rot + sr.rt;
288                  }
289          }
290          if (r->crtype & SHADOW)                 /* the rest is shadow */
# Line 293 | Line 293 | register RAY  *r;
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]));
296 >                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
297 >                                varvalue(m->oargs.sarg[1]),
298 >                                varvalue(m->oargs.sarg[2]));
299                  scalecolor(ctmp, nd.rspec);
300                  if (errno)
301                          objerror(m, WARNING, "compute error");
# Line 332 | Line 332 | register RAY  *r;
332          }
333                                                  /* add direct component */
334          direct(r, dirbrdf, &nd);
335 +                                                /* check distance */
336 +        if (transtest > bright(r->rcol))
337 +                r->rt = transdist;
338 + }
339 +
340 +
341 + setbrdfunc(np)                  /* set up brdf function and variables */
342 + register BRDFDAT  *np;
343 + {
344 +        FVECT  vec;
345 +
346 +        if (setfunc(np->mp, np->pr) == 0)
347 +                return(0);      /* it's OK, setfunc says we're done */
348 +                                /* else (re)assign special variables */
349 +        multv3(vec, np->pnorm, funcxf.xfm);
350 +        varset("NxP", '=', vec[0]/funcxf.sca);
351 +        varset("NyP", '=', vec[1]/funcxf.sca);
352 +        varset("NzP", '=', vec[2]/funcxf.sca);
353 +        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
354 +                        np->pdot >= 1.0 ? 1.0 : np->pdot);
355 +        varset("CrP", '=', colval(np->mcolor,RED));
356 +        varset("CgP", '=', colval(np->mcolor,GRN));
357 +        varset("CbP", '=', colval(np->mcolor,BLU));
358 +        return(1);
359   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines