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 2.33 by greg, Wed Sep 2 18:59:01 2015 UTC vs.
Revision 2.38 by greg, Wed Feb 13 02:38:26 2019 UTC

# Line 209 | Line 209 | m_brdf(                        /* color a ray that hit a BRDTfunc material
209          int  hitfront = 1;
210          BRDFDAT  nd;
211          RAY  sr;
212        double  mirtest=0, mirdist=0;
213        double  transtest=0, transdist=0;
212          int  hasrefl, hastrans;
213          int  hastexture;
214          COLOR  ctmp;
# Line 241 | Line 239 | m_brdf(                        /* color a ray that hit a BRDTfunc material
239                          m->oargs.farg[8]);
240                                                  /* get modifiers */
241          raytexture(r, m->omod);
242 <        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
242 >        hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY);
243          if (hastexture) {                       /* perturb normal */
244                  nd.pdot = raynormal(nd.pnorm, r);
245          } else {
# Line 259 | Line 257 | m_brdf(                        /* color a ray that hit a BRDTfunc material
257          copycolor(nd.mcolor, r->pcol);          /* get pattern color */
258          multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
259          multcolor(nd.tdiff, nd.mcolor);
260 <        hasrefl = bright(nd.rdiff) > FTINY;
261 <        hastrans = bright(nd.tdiff) > FTINY;
260 >        hasrefl = (bright(nd.rdiff) > FTINY);
261 >        hastrans = (bright(nd.tdiff) > FTINY);
262                                                  /* load cal file */
263          nd.dp = NULL;
264          mf = getfunc(m, 9, 0x3f, 0);
# Line 273 | Line 271 | m_brdf(                        /* color a ray that hit a BRDTfunc material
271          if ((errno == EDOM) | (errno == ERANGE))
272                  objerror(m, WARNING, "compute error");
273          else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
274 <                if (!(r->crtype & SHADOW) && hastexture) {
274 >                if (hastexture && !(r->crtype & (SHADOW|AMBIENT))) {
275                                                  /* perturb direction */
276 <                        VSUM(sr.rdir, r->rdir, r->pert, -.75);
276 >                        VSUB(sr.rdir, r->rdir, r->pert);
277                          if (normalize(sr.rdir) == 0.0) {
278                                  objerror(m, WARNING, "illegal perturbation");
279                                  VCOPY(sr.rdir, r->rdir);
# Line 286 | Line 284 | m_brdf(                        /* color a ray that hit a BRDTfunc material
284                  rayvalue(&sr);
285                  multcolor(sr.rcol, sr.rcoef);
286                  addcolor(r->rcol, sr.rcol);
287 <                if (!hastexture) {
288 <                        transtest = 2.0*bright(sr.rcol);
289 <                        transdist = r->rot + sr.rt;
292 <                }
287 >                if ((!hastexture || r->crtype & (SHADOW|AMBIENT)) &&
288 >                                nd.tspec > bright(nd.tdiff) + bright(nd.rdiff))
289 >                        r->rxt = r->rot + raydistance(&sr);
290          }
291          if (r->crtype & SHADOW)                 /* the rest is shadow */
292                  return(1);
293 +
294                                                  /* compute reflected ray */
295          setbrdfunc(&nd);
296          errno = 0;
# Line 306 | Line 304 | m_brdf(                        /* color a ray that hit a BRDTfunc material
304                  checknorm(sr.rdir);
305                  rayvalue(&sr);
306                  multcolor(sr.rcol, sr.rcoef);
307 +                copycolor(r->mcol, sr.rcol);
308                  addcolor(r->rcol, sr.rcol);
309 <                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
310 <                        mirtest = 2.0*bright(sr.rcol);
311 <                        mirdist = r->rot + sr.rt;
313 <                }
309 >                if (r->ro != NULL && isflat(r->ro->otype) &&
310 >                                !hastexture | (r->crtype & AMBIENT))
311 >                        r->rmt = r->rot + raydistance(&sr);
312          }
313                                                  /* compute ambient */
314          if (hasrefl) {
# Line 337 | Line 335 | m_brdf(                        /* color a ray that hit a BRDTfunc material
335          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
336                  direct(r, dirbrdf, &nd);        /* add direct component */
337  
340        d = bright(r->rcol);                    /* set effective distance */
341        if (transtest > d)
342                r->rt = transdist;
343        else if (mirtest > d)
344                r->rt = mirdist;
345
338          return(1);
339   }
340  
# Line 416 | Line 408 | m_brdf2(                       /* color a ray that hit a BRDF material */
408                  multambient(ctmp, r, nd.pnorm);
409                  addcolor(r->rcol, ctmp);        /* add to returned color */
410          }
411 <        if (nd.trans > FTINY) {         /* from other side */
411 >        if (nd.trans > FTINY) {                 /* from other side */
412                  flipsurface(r);
413                  vtmp[0] = -nd.pnorm[0];
414                  vtmp[1] = -nd.pnorm[1];
# Line 445 | Line 437 | setbrdfunc(                    /* set up brdf function and variables */
437                  return(0);      /* it's OK, setfunc says we're done */
438                                  /* else (re)assign special variables */
439          multv3(vec, np->pnorm, funcxf.xfm);
440 <        varset("NxP", '=', vec[0]/funcxf.sca);
441 <        varset("NyP", '=', vec[1]/funcxf.sca);
442 <        varset("NzP", '=', vec[2]/funcxf.sca);
443 <        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
440 >        varset("NxP`", '=', vec[0]/funcxf.sca);
441 >        varset("NyP`", '=', vec[1]/funcxf.sca);
442 >        varset("NzP`", '=', vec[2]/funcxf.sca);
443 >        varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 :
444                          np->pdot >= 1.0 ? 1.0 : np->pdot);
445          varset("CrP", '=', colval(np->mcolor,RED));
446          varset("CgP", '=', colval(np->mcolor,GRN));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines