ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_bsdf.c
(Generate patch)

Comparing ray/src/rt/m_bsdf.c (file contents):
Revision 2.26 by greg, Sat Jan 25 18:27:39 2014 UTC vs.
Revision 2.31 by greg, Fri Feb 17 23:24:56 2017 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include  "func.h"
14   #include  "bsdf.h"
15   #include  "random.h"
16 + #include  "pmapmat.h"
17  
18   /*
19   *      Arguments to this material include optional diffuse colors.
# Line 72 | Line 73 | typedef struct {
73          RREAL   fromloc[3][3];  /* local BSDF coords to world */
74          double  thick;          /* surface thickness */
75          SDData  *sd;            /* loaded BSDF data */
76 <        COLOR   runsamp;        /* BSDF hemispherical reflection */
77 <        COLOR   rdiff;          /* added diffuse reflection */
77 <        COLOR   tunsamp;        /* BSDF hemispherical transmission */
78 <        COLOR   tdiff;          /* added diffuse transmission */
76 >        COLOR   rdiff;          /* diffuse reflection */
77 >        COLOR   tdiff;          /* diffuse transmission */
78   }  BSDFDAT;             /* BSDF material data */
79  
80   #define cvt_sdcolor(cv, svp)    ccy2rgb(&(svp)->spec, (svp)->cieY, cv)
# Line 200 | Line 199 | dir_bsdf(
199                  scalecolor(ctmp, dtmp);
200                  addcolor(cval, ctmp);
201          }
202 +        if (ambRayInPmap(np->pr))
203 +                return;         /* specular already in photon map */
204          /*
205           *  Compute scattering coefficient using BSDF.
206           */
207          if (!direct_bsdf_OK(ctmp, ldir, omega, np))
208                  return;
209 <        if (ldot > 0) {         /* pattern only diffuse reflection */
209 <                COLOR   ctmp1, ctmp2;
210 <                dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY
211 <                                        : np->sd->rLambBack.cieY;
212 <                                        /* diffuse fraction */
213 <                dtmp /= PI * bright(ctmp);
214 <                copycolor(ctmp2, np->pr->pcol);
215 <                scalecolor(ctmp2, dtmp);
216 <                setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp);
217 <                addcolor(ctmp1, ctmp2);
218 <                multcolor(ctmp, ctmp1); /* apply derated pattern */
219 <                dtmp = ldot * omega;
220 <        } else {                        /* full pattern on transmission */
209 >        if (ldot < 0) {         /* pattern for specular transmission */
210                  multcolor(ctmp, np->pr->pcol);
211                  dtmp = -ldot * omega;
212 <        }
212 >        } else
213 >                dtmp = ldot * omega;
214          scalecolor(ctmp, dtmp);
215          addcolor(cval, ctmp);
216   }
# Line 255 | Line 245 | dir_brdf(
245                  scalecolor(ctmp, dtmp);
246                  addcolor(cval, ctmp);
247          }
248 +        if (ambRayInPmap(np->pr))
249 +                return;         /* specular already in photon map */
250          /*
251           *  Compute reflection coefficient using BSDF.
252           */
253          if (!direct_bsdf_OK(ctmp, ldir, omega, np))
254                  return;
263                                        /* pattern only diffuse reflection */
264        dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY
265                                : np->sd->rLambBack.cieY;
266        dtmp /= PI * bright(ctmp);      /* diffuse fraction */
267        copycolor(ctmp2, np->pr->pcol);
268        scalecolor(ctmp2, dtmp);
269        setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp);
270        addcolor(ctmp1, ctmp2);
271        multcolor(ctmp, ctmp1);         /* apply derated pattern */
255          dtmp = ldot * omega;
256          scalecolor(ctmp, dtmp);
257          addcolor(cval, ctmp);
# Line 304 | Line 287 | dir_btdf(
287                  scalecolor(ctmp, dtmp);
288                  addcolor(cval, ctmp);
289          }
290 +        if (ambRayInPmap(np->pr))
291 +                return;         /* specular already in photon map */
292          /*
293           *  Compute scattering coefficient using BSDF.
294           */
# Line 381 | Line 366 | sample_sdf(BSDFDAT *ndp, int sflags)
366          COLORV          *unsc;
367  
368          if (sflags == SDsampSpT) {
369 <                unsc = ndp->tunsamp;
369 >                unsc = ndp->tdiff;
370                  if (ndp->pr->rod > 0)
371                          dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb;
372                  else
373                          dfp = (ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf;
389                cvt_sdcolor(unsc, &ndp->sd->tLamb);
374          } else /* sflags == SDsampSpR */ {
375 <                unsc = ndp->runsamp;
376 <                if (ndp->pr->rod > 0) {
375 >                unsc = ndp->rdiff;
376 >                if (ndp->pr->rod > 0)
377                          dfp = ndp->sd->rf;
378 <                        cvt_sdcolor(unsc, &ndp->sd->rLambFront);
395 <                } else {
378 >                else
379                          dfp = ndp->sd->rb;
397                        cvt_sdcolor(unsc, &ndp->sd->rLambBack);
398                }
380          }
400        multcolor(unsc, ndp->pr->pcol);
381          if (dfp == NULL)                        /* no specular component? */
382                  return(0);
383                                                  /* below sampling threshold? */
# Line 464 | Line 444 | m_bsdf(OBJREC *m, RAY *r)
444          }
445                                                  /* check other rays to pass */
446          if (nd.thick != 0 && (!(r->crtype & (SPECULAR|AMBIENT)) ||
447 <                                nd.thick > 0 ^ hitfront)) {
447 >                                (nd.thick > 0) ^ hitfront)) {
448                  raytrans(r);                    /* hide our proxy */
449                  return(1);
450          }
451 +        nd.mp = m;
452 +        nd.pr = r;
453                                                  /* get BSDF data */
454          nd.sd = loadBSDF(m->oargs.sarg[1]);
455                                                  /* diffuse reflectance */
456          if (hitfront) {
457 <                if (m->oargs.nfargs < 3)
458 <                        setcolor(nd.rdiff, .0, .0, .0);
459 <                else
478 <                        setcolor(nd.rdiff, m->oargs.farg[0],
457 >                cvt_sdcolor(nd.rdiff, &nd.sd->rLambFront);
458 >                if (m->oargs.nfargs >= 3) {
459 >                        setcolor(ctmp, m->oargs.farg[0],
460                                          m->oargs.farg[1],
461                                          m->oargs.farg[2]);
462 +                        addcolor(nd.rdiff, ctmp);
463 +                }
464          } else {
465 <                if (m->oargs.nfargs < 6)
466 <                        setcolor(nd.rdiff, .0, .0, .0);
467 <                else
485 <                        setcolor(nd.rdiff, m->oargs.farg[3],
465 >                cvt_sdcolor(nd.rdiff, &nd.sd->rLambBack);
466 >                if (m->oargs.nfargs >= 6) {
467 >                        setcolor(ctmp, m->oargs.farg[3],
468                                          m->oargs.farg[4],
469                                          m->oargs.farg[5]);
470 +                        addcolor(nd.rdiff, ctmp);
471 +                }
472          }
473                                                  /* diffuse transmittance */
474 <        if (m->oargs.nfargs < 9)
475 <                setcolor(nd.tdiff, .0, .0, .0);
476 <        else
493 <                setcolor(nd.tdiff, m->oargs.farg[6],
474 >        cvt_sdcolor(nd.tdiff, &nd.sd->tLamb);
475 >        if (m->oargs.nfargs >= 9) {
476 >                setcolor(ctmp, m->oargs.farg[6],
477                                  m->oargs.farg[7],
478                                  m->oargs.farg[8]);
479 <        nd.mp = m;
480 <        nd.pr = r;
479 >                addcolor(nd.tdiff, ctmp);
480 >        }
481                                                  /* get modifiers */
482          raytexture(r, m->omod);
483                                                  /* modify diffuse values */
# Line 545 | Line 528 | m_bsdf(OBJREC *m, RAY *r)
528                                                  /* sample transmission */
529          sample_sdf(&nd, SDsampSpT);
530                                                  /* compute indirect diffuse */
531 <        copycolor(ctmp, nd.rdiff);
549 <        addcolor(ctmp, nd.runsamp);
550 <        if (bright(ctmp) > FTINY) {             /* ambient from reflection */
531 >        if (bright(nd.rdiff) > FTINY) {         /* ambient from reflection */
532                  if (!hitfront)
533                          flipsurface(r);
534 +                copycolor(ctmp, nd.rdiff);
535                  multambient(ctmp, r, nd.pnorm);
536                  addcolor(r->rcol, ctmp);
537                  if (!hitfront)
538                          flipsurface(r);
539          }
540 <        copycolor(ctmp, nd.tdiff);
559 <        addcolor(ctmp, nd.tunsamp);
560 <        if (bright(ctmp) > FTINY) {             /* ambient from other side */
540 >        if (bright(nd.tdiff) > FTINY) {         /* ambient from other side */
541                  FVECT  bnorm;
542                  if (hitfront)
543                          flipsurface(r);
544                  bnorm[0] = -nd.pnorm[0];
545                  bnorm[1] = -nd.pnorm[1];
546                  bnorm[2] = -nd.pnorm[2];
547 +                copycolor(ctmp, nd.tdiff);
548                  if (nd.thick != 0) {            /* proxy with offset? */
549                          VCOPY(vtmp, r->rop);
550                          VSUM(r->rop, vtmp, r->ron, nd.thick);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines