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.63 by greg, Mon Sep 15 00:54:39 2014 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"
16 + #include  "pmapsrc.h"
17 + #include  "pmapmat.h"
18  
19   #ifndef MAXSSAMP
20   #define MAXSSAMP        16              /* maximum samples per ray */
# Line 40 | Line 43 | static int  maxcntr = 0;               /* size of contribution arra
43   static int cntcmp(const void *p1, const void *p2);
44  
45  
43 OBJREC *                        /* find an object's actual material */
44 findmaterial(OBJREC *o)
45 {
46        while (!ismaterial(o->otype)) {
47                if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
48                        OBJECT  aobj;
49                        OBJREC  *ao;
50                        aobj = lastmod(objndx(o), o->oargs.sarg[0]);
51                        if (aobj < 0)
52                                objerror(o, USER, "bad reference");
53                        ao = objptr(aobj);
54                        if (ismaterial(ao->otype))
55                                return(ao);
56                        if (ao->otype == MOD_ALIAS) {
57                                o = ao;
58                                continue;
59                        }
60                }
61                if (o->omod == OVOID)
62                        return(NULL);
63                o = objptr(o->omod);
64        }
65        return(o);              /* mixtures will return NULL */
66 }
67
68
46   void
47   marksources(void)                       /* find and mark source objects */
48   {
# Line 133 | Line 110 | marksources(void)                      /* find and mark source objects */
110                                  source[ns].sflags |= SSKIP;
111                          }
112                  }
136 #if  SHADCACHE
137                initobscache(ns);
138 #endif
113                  foundsource += !(source[ns].sflags & SSKIP);
114          }
115          if (!foundsource) {
116                  error(WARNING, "no light sources found");
117                  return;
118          }
119 <        markvirtuals();                 /* find and add virtual sources */
119 > #if  SHADCACHE
120 >        for (ns = 0; ns < nsources; ns++)       /* initialize obstructor cache */
121 >                initobscache(ns);
122 > #endif
123 >        /* PMAP: disable virtual sources */
124 >        if (!photonMapping)
125 >                markvirtuals();                 /* find and add virtual sources */
126 >                
127                                  /* allocate our contribution arrays */
128          maxcntr = nsources + MAXSPART;  /* start with this many */
129          srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB));
# Line 378 | Line 359 | direct(                                        /* add direct component */
359          int  nhits;
360          double  prob, ourthresh, hwt;
361          RAY  sr;
362 +        
363 +        /* PMAP: Factor in direct photons (primarily for debugging/validation) */
364 +        if (directPhotonMapping) {
365 +                (*f)(r -> rcol, p, r -> ron, PI);              
366 +                multDirectPmap(r);
367 +                return;
368 +        }
369 +        
370                          /* NOTE: srccnt and cntord global so no recursion */
371          if (nsources <= 0)
372                  return;         /* no sources?! */
# Line 532 | Line 521 | srcscatter(                    /* compute source scattering into ray */
521          COLOR  cvext;
522          int  i, j;
523  
524 <        if (r->slights == NULL || r->slights[0] == 0
525 <                        || 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)
531                  nsamps = 1;
532   #if MAXSSAMP
# Line 543 | 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 559 | 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);
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);
594                        scalecolor(sr.rcol, d);
602                          multcolor(sr.rcol, cvext);
603                          addcolor(r->rcol, sr.rcol);     /* add it in */
604                  }
# Line 658 | 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