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.67 by rschregle, Tue Feb 23 12:42:41 2016 UTC vs.
Revision 2.68 by greg, Mon Jun 11 15:10:49 2018 UTC

# Line 543 | Line 543 | srcscatter(                    /* compute source scattering into ray */
543          SRCINDEX  si;
544          double  t, d;
545          double  re, ge, be;
546 <        COLOR  cvext, pmapInscatter;
546 >        COLOR  cvext;
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)
549 >        if (r->rot >= FHUGE || r->gecc >= 1.-FTINY)
550 >                return;         /* this can never work */
551 >        /* PMAP: do unconditional inscattering for volume photons */
552 >        if (!volumePhotonMapping && (r->slights == NULL || r->slights[0] == 0))
553                  return;
554                  
555          if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
# Line 560 | Line 560 | srcscatter(                    /* compute source scattering into ray */
560   #endif
561          oldsampndx = samplendx;
562          samplendx = random()&0x7fff;            /* randomize */
563 <        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
563 >        for (i = volumePhotonMapping ? 1 : r->slights[0]; i > 0; i--) {
564 >                /* for each source OR once if volume photon map enabled */
565                  for (j = 0; j < nsamps; j++) {  /* for each sample position */
566                          samplendx++;
567                          t = r->rot * (j+frandom())/nsamps;
# Line 576 | Line 577 | srcscatter(                    /* compute source scattering into ray */
577                          sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
578                          sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
579                          sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
580 <                        initsrcindex(&si);      /* sample ray to this source */
581 <                        si.sn = r->slights[i];
582 <                        nopart(&si, &sr);
583 <                        if (!srcray(&sr, NULL, &si) ||
584 <                                        sr.rsrc != r->slights[i])
585 <                                continue;               /* no path */
580 >                        
581 >                        if (!volumePhotonMapping) {
582 >                                initsrcindex(&si);      /* sample ray to this source */
583 >                                si.sn = r->slights[i];
584 >                                nopart(&si, &sr);
585 >                                if (!srcray(&sr, NULL, &si) ||
586 >                                                sr.rsrc != r->slights[i])
587 >                                        continue;       /* no path */
588   #if SHADCACHE
589 <                        if (srcblocked(&sr))            /* check shadow cache */
590 <                                continue;
589 >                                if (srcblocked(&sr))    /* check shadow cache */
590 >                                        continue;
591   #endif
592 <                        copycolor(sr.cext, r->cext);
593 <                        copycolor(sr.albedo, r->albedo);
594 <                        sr.gecc = r->gecc;
595 <                        sr.slights = r->slights;
596 <                        rayvalue(&sr);                  /* eval. source ray */
597 <                        if (bright(sr.rcol) <= FTINY) {
592 >                                copycolor(sr.cext, r->cext);
593 >                                copycolor(sr.albedo, r->albedo);
594 >                                sr.gecc = r->gecc;
595 >                                sr.slights = r->slights;
596 >                                rayvalue(&sr);          /* eval. source ray */
597 >                                if (bright(sr.rcol) <= FTINY) {
598   #if SHADCACHE
599 <                                srcblocker(&sr);        /* add blocker to cache */
599 >                                        srcblocker(&sr); /* add blocker to cache */
600   #endif
601 <                                continue;
602 <                        }
603 <                        if (r->gecc <= FTINY)           /* compute P(theta) */
604 <                                d = 1.;
605 <                        else {
606 <                                d = DOT(r->rdir, sr.rdir);
607 <                                d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
608 <                                d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
609 <                        }
601 >                                        continue;
602 >                                }
603 >                                if (r->gecc <= FTINY)   /* compute P(theta) */
604 >                                        d = 1.;
605 >                                else {
606 >                                        d = DOT(r->rdir, sr.rdir);
607 >                                        d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
608 >                                        d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
609 >                                }
610                                                          /* other factors */
611 <                        d *= si.dom * r->rot / (4.*PI*nsamps);
612 <                        scalecolor(sr.rcol, d);
613 <                        
614 <                        /* PMAP: Add ambient inscattering from volume photons once only */
615 <                        if (volumePhotonMapping && i == 1) {
616 <                           inscatterVolumePmap(&sr, pmapInscatter);
617 <            scalecolor(pmapInscatter, r -> rot / nsamps);
618 <            addcolor(sr.rcol, pmapInscatter);
619 <         }
620 <                        
611 >                                d *= si.dom * r->rot / (4.*PI*nsamps);
612 >                                scalecolor(sr.rcol, d);
613 >                        } else {
614 >                                /* PMAP: Add ambient inscattering from
615 >                                 * volume photons; note we reverse the
616 >                                 * incident ray direction since we're
617 >                                 * now in *backward* raytracing mode! */
618 >                                sr.rdir [0] = -r -> rdir [0];
619 >                                sr.rdir [1] = -r -> rdir [1];
620 >                                sr.rdir [2] = -r -> rdir [2];
621 >                                sr.gecc = r -> gecc;
622 >                                inscatterVolumePmap(&sr, sr.rcol);
623 >                                scalecolor(sr.rcol, r -> rot / nsamps);
624 >                        }
625                          multcolor(sr.rcol, r->cext);
626                          multcolor(sr.rcol, r->albedo);
627                          multcolor(sr.rcol, cvext);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines