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.62 by greg, Wed May 7 02:08:12 2014 UTC vs.
Revision 2.67 by rschregle, Tue Feb 23 12:42:41 2016 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include  "rtotypes.h"
13   #include  "source.h"
14   #include  "random.h"
15 + #include  "pmapsrc.h"
16 + #include  "pmapmat.h"
17  
18   #ifndef MAXSSAMP
19   #define MAXSSAMP        16              /* maximum samples per ray */
# Line 133 | Line 135 | marksources(void)                      /* find and mark source objects */
135                                  source[ns].sflags |= SSKIP;
136                          }
137                  }
136 #if  SHADCACHE
137                initobscache(ns);
138 #endif
138                  foundsource += !(source[ns].sflags & SSKIP);
139          }
140          if (!foundsource) {
141                  error(WARNING, "no light sources found");
142                  return;
143          }
144 <        markvirtuals();                 /* find and add virtual sources */
144 > #if  SHADCACHE
145 >        for (ns = 0; ns < nsources; ns++)       /* initialize obstructor cache */
146 >                initobscache(ns);
147 > #endif
148 >        /* PMAP: disable virtual sources */
149 >        if (!photonMapping)
150 >                markvirtuals();                 /* find and add virtual sources */
151 >                
152                                  /* allocate our contribution arrays */
153          maxcntr = nsources + MAXSPART;  /* start with this many */
154          srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB));
# Line 378 | Line 384 | direct(                                        /* add direct component */
384          int  nhits;
385          double  prob, ourthresh, hwt;
386          RAY  sr;
387 +        
388 +        /* PMAP: Factor in direct photons (primarily for debugging/validation) */
389 +        if (directPhotonMapping) {
390 +                (*f)(r -> rcol, p, r -> ron, PI);              
391 +                multDirectPmap(r);
392 +                return;
393 +        }
394 +        
395                          /* NOTE: srccnt and cntord global so no recursion */
396          if (nsources <= 0)
397                  return;         /* no sources?! */
# Line 440 | Line 454 | direct(                                        /* add direct component */
454                                                  /* compute number to check */
455          nshadcheck = pow((double)ncnts, shadcert) + .5;
456                                                  /* modify threshold */
457 <        ourthresh = shadthresh / r->rweight;
457 >        if (ncnts > MINSHADCNT)
458 >                ourthresh = shadthresh / r->rweight;
459 >        else
460 >                ourthresh = 0;
461                                                  /* test for shadows */
462          for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts;
463                          hwt += (double)source[scp->sno].nhits /
# Line 526 | Line 543 | srcscatter(                    /* compute source scattering into ray */
543          SRCINDEX  si;
544          double  t, d;
545          double  re, ge, be;
546 <        COLOR  cvext;
546 >        COLOR  cvext, pmapInscatter;
547          int  i, j;
548  
549 +        /* PMAP: do unconditional inscattering for volume photons ? */
550 +        /* if (!volumePhotonMapping) */
551          if (r->slights == NULL || r->slights[0] == 0
552                          || r->gecc >= 1.-FTINY || r->rot >= FHUGE)
553                  return;
554 +                
555          if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
556                  nsamps = 1;
557   #if MAXSSAMP
# Line 586 | Line 606 | srcscatter(                    /* compute source scattering into ray */
606                          }
607                                                          /* other factors */
608                          d *= si.dom * r->rot / (4.*PI*nsamps);
609 +                        scalecolor(sr.rcol, d);
610 +                        
611 +                        /* PMAP: Add ambient inscattering from volume photons once only */
612 +                        if (volumePhotonMapping && i == 1) {
613 +                           inscatterVolumePmap(&sr, pmapInscatter);
614 +            scalecolor(pmapInscatter, r -> rot / nsamps);
615 +            addcolor(sr.rcol, pmapInscatter);
616 +         }
617 +                        
618                          multcolor(sr.rcol, r->cext);
619                          multcolor(sr.rcol, r->albedo);
591                        scalecolor(sr.rcol, d);
620                          multcolor(sr.rcol, cvext);
621                          addcolor(r->rcol, sr.rcol);     /* add it in */
622                  }
# Line 655 | Line 683 | weaksrcmat(OBJECT obj)         /* identify material */
683   * The same is true for stray specular samples, since the specular
684   * contribution from light sources is calculated separately.
685   */
686 <
687 < #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
686 > /* PMAP: Also avoid counting sources via transferred ambient rays (e.g.
687 > * through glass) when photon mapping is enabled, as these indirect
688 > * components are already accounted for.
689 > */
690 > #define  badcomponent(m, r)   (srcRayInPmap(r) || \
691 >                                (r->crtype&(AMBIENT|SPECULAR) && \
692                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
693 <                /* not 100% correct */  distglow(m, r, r->rot)))
693 >                /* not 100% correct */  distglow(m, r, r->rot))))
694  
695   /* passillum *
696   *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines