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

Comparing ray/src/rt/source.c (file contents):
Revision 2.65 by greg, Thu May 28 09:03:54 2015 UTC vs.
Revision 2.71 by greg, Thu Mar 12 17:19:18 2020 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9  
10   #include  "ray.h"
11   #include  "otypes.h"
12 + #include  "otspecial.h"
13   #include  "rtotypes.h"
14   #include  "source.h"
15   #include  "random.h"
15 #include  "pmap.h"
16   #include  "pmapsrc.h"
17 + #include  "pmapmat.h"
18  
19   #ifndef MAXSSAMP
20   #define MAXSSAMP        16              /* maximum samples per ray */
# Line 42 | Line 43 | static int  maxcntr = 0;               /* size of contribution arra
43   static int cntcmp(const void *p1, const void *p2);
44  
45  
45 OBJREC *                        /* find an object's actual material */
46 findmaterial(OBJREC *o)
47 {
48        while (!ismaterial(o->otype)) {
49                if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
50                        OBJECT  aobj;
51                        OBJREC  *ao;
52                        aobj = lastmod(objndx(o), o->oargs.sarg[0]);
53                        if (aobj < 0)
54                                objerror(o, USER, "bad reference");
55                        ao = objptr(aobj);
56                        if (ismaterial(ao->otype))
57                                return(ao);
58                        if (ao->otype == MOD_ALIAS) {
59                                o = ao;
60                                continue;
61                        }
62                }
63                if (o->omod == OVOID)
64                        return(NULL);
65                o = objptr(o->omod);
66        }
67        return(o);              /* mixtures will return NULL */
68 }
69
70
46   void
47   marksources(void)                       /* find and mark source objects */
48   {
# Line 142 | Line 117 | marksources(void)                      /* find and mark source objects */
117                  return;
118          }
119   #if  SHADCACHE
120 <        initobscache(ns);
120 >        for (ns = 0; ns < nsources; ns++)       /* initialize obstructor cache */
121 >                initobscache(ns);
122   #endif
123          /* PMAP: disable virtual sources */
124          if (!photonMapping)
# Line 542 | Line 518 | srcscatter(                    /* compute source scattering into ray */
518          SRCINDEX  si;
519          double  t, d;
520          double  re, ge, be;
521 <        COLOR  cvext, pmapInscatter;
521 >        COLOR  cvext;
522          int  i, j;
523  
524 <        /* PMAP: do unconditional inscattering for volume photons ? */
525 <        /* if (!volumePhotonMapping) */
526 <        if (r->slights == NULL || r->slights[0] == 0
527 <                        || r->gecc >= 1.-FTINY || r->rot >= FHUGE)
524 >        if (r->rot >= FHUGE*.99 || r->gecc >= 1.-FTINY)
525 >                return;         /* this can never work */
526 >        /* PMAP: do unconditional inscattering for volume photons */
527 >        if (!volumePhotonMapping && (r->slights == NULL || r->slights[0] == 0))
528                  return;
529                  
530          if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
# Line 559 | Line 535 | srcscatter(                    /* compute source scattering into ray */
535   #endif
536          oldsampndx = samplendx;
537          samplendx = random()&0x7fff;            /* randomize */
538 <        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
538 >        for (i = volumePhotonMapping ? 1 : r->slights[0]; i > 0; i--) {
539 >                /* for each source OR once if volume photon map enabled */
540                  for (j = 0; j < nsamps; j++) {  /* for each sample position */
541                          samplendx++;
542                          t = r->rot * (j+frandom())/nsamps;
# Line 575 | Line 552 | srcscatter(                    /* compute source scattering into ray */
552                          sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
553                          sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
554                          sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
555 <                        initsrcindex(&si);      /* sample ray to this source */
556 <                        si.sn = r->slights[i];
557 <                        nopart(&si, &sr);
558 <                        if (!srcray(&sr, NULL, &si) ||
559 <                                        sr.rsrc != r->slights[i])
560 <                                continue;               /* no path */
555 >                        
556 >                        if (!volumePhotonMapping) {
557 >                                initsrcindex(&si);      /* sample ray to this source */
558 >                                si.sn = r->slights[i];
559 >                                nopart(&si, &sr);
560 >                                if (!srcray(&sr, NULL, &si) ||
561 >                                                sr.rsrc != r->slights[i])
562 >                                        continue;       /* no path */
563   #if SHADCACHE
564 <                        if (srcblocked(&sr))            /* check shadow cache */
565 <                                continue;
564 >                                if (srcblocked(&sr))    /* check shadow cache */
565 >                                        continue;
566   #endif
567 <                        copycolor(sr.cext, r->cext);
568 <                        copycolor(sr.albedo, r->albedo);
569 <                        sr.gecc = r->gecc;
570 <                        sr.slights = r->slights;
571 <                        rayvalue(&sr);                  /* eval. source ray */
572 <                        if (bright(sr.rcol) <= FTINY) {
567 >                                copycolor(sr.cext, r->cext);
568 >                                copycolor(sr.albedo, r->albedo);
569 >                                sr.gecc = r->gecc;
570 >                                sr.slights = r->slights;
571 >                                rayvalue(&sr);          /* eval. source ray */
572 >                                if (bright(sr.rcol) <= FTINY) {
573   #if SHADCACHE
574 <                                srcblocker(&sr);        /* add blocker to cache */
574 >                                        srcblocker(&sr); /* add blocker to cache */
575   #endif
576 <                                continue;
577 <                        }
578 <                        if (r->gecc <= FTINY)           /* compute P(theta) */
579 <                                d = 1.;
580 <                        else {
581 <                                d = DOT(r->rdir, sr.rdir);
582 <                                d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
583 <                                d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
584 <                        }
576 >                                        continue;
577 >                                }
578 >                                if (r->gecc <= FTINY)   /* compute P(theta) */
579 >                                        d = 1.;
580 >                                else {
581 >                                        d = DOT(r->rdir, sr.rdir);
582 >                                        d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
583 >                                        d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
584 >                                }
585                                                          /* other factors */
586 <                        d *= si.dom * r->rot / (4.*PI*nsamps);
587 <                        scalecolor(sr.rcol, d);
588 <                        
589 <                        /* PMAP: Add ambient inscattering from volume photons once only */
590 <                        if (volumePhotonMapping && i == 1) {
591 <                           inscatterVolumePmap(&sr, pmapInscatter);
592 <            scalecolor(pmapInscatter, r -> rot / nsamps);
593 <            addcolor(sr.rcol, pmapInscatter);
594 <         }
595 <                        
586 >                                d *= si.dom * r->rot / (4.*PI*nsamps);
587 >                                scalecolor(sr.rcol, d);
588 >                        } else {
589 >                                /* PMAP: Add ambient inscattering from
590 >                                 * volume photons; note we reverse the
591 >                                 * incident ray direction since we're
592 >                                 * now in *backward* raytracing mode! */
593 >                                sr.rdir [0] = -r -> rdir [0];
594 >                                sr.rdir [1] = -r -> rdir [1];
595 >                                sr.rdir [2] = -r -> rdir [2];
596 >                                sr.gecc = r -> gecc;
597 >                                inscatterVolumePmap(&sr, sr.rcol);
598 >                                scalecolor(sr.rcol, r -> rot / nsamps);
599 >                        }
600                          multcolor(sr.rcol, r->cext);
601                          multcolor(sr.rcol, r->albedo);
602                          multcolor(sr.rcol, cvext);
# Line 682 | Line 665 | weaksrcmat(OBJECT obj)         /* identify material */
665   * The same is true for stray specular samples, since the specular
666   * contribution from light sources is calculated separately.
667   */
668 <
669 < #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
668 > /* PMAP: Also avoid counting sources via transferred ambient rays (e.g.
669 > * through glass) when photon mapping is enabled, as these indirect
670 > * components are already accounted for.
671 > */
672 > #define  badcomponent(m, r)   (srcRayInPmap(r) || \
673 >                                (r->crtype&(AMBIENT|SPECULAR) && \
674                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
675 <                /* not 100% correct */  distglow(m, r, r->rot)))
675 >                /* not 100% correct */  distglow(m, r, r->rot))))
676  
677   /* passillum *
678   *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines