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.60 by greg, Mon Feb 14 20:13:38 2011 UTC vs.
Revision 2.64 by greg, Tue Feb 24 19:39:27 2015 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include  "rtotypes.h"
13   #include  "source.h"
14   #include  "random.h"
15 + #include  "pmap.h"
16 + #include  "pmapsrc.h"
17  
16 extern double  ssampdist;               /* scatter sampling distance */
17
18   #ifndef MAXSSAMP
19   #define MAXSSAMP        16              /* maximum samples per ray */
20   #endif
# Line 42 | Line 42 | static int  maxcntr = 0;               /* size of contribution arra
42   static int cntcmp(const void *p1, const void *p2);
43  
44  
45 < extern OBJREC *                 /* find an object's actual material */
46 < findmaterial(register OBJREC *o)
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) {
# Line 68 | Line 68 | findmaterial(register OBJREC *o)
68   }
69  
70  
71 < extern void
71 > void
72   marksources(void)                       /* find and mark source objects */
73   {
74          int  foundsource = 0;
75          int  i;
76 <        register OBJREC  *o, *m;
77 <        register int  ns;
76 >        OBJREC  *o, *m;
77 >        int  ns;
78                                          /* initialize dispatch table */
79          initstypes();
80                                          /* find direct sources */
# Line 99 | Line 99 | marksources(void)                      /* find and mark source objects */
99                                  m->otype == MAT_SPOT ? 7 : 3))
100                          objerror(m, USER, "bad # arguments");
101  
102                if (m->otype == MAT_GLOW &&
103                                o->otype != OBJ_SOURCE &&
104                                m->oargs.farg[3] <= FTINY)
105                        continue;                       /* don't bother */
102                  if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY &&
103                                  m->oargs.farg[2] <= FTINY)
104                          continue;                       /* don't bother */
105 <
105 >                if (m->otype == MAT_GLOW &&
106 >                                o->otype != OBJ_SOURCE &&
107 >                                m->oargs.farg[3] <= FTINY) {
108 >                        foundsource += (ambounce > 0);
109 >                        continue;                       /* don't track these */
110 >                }
111                  if (sfun[o->otype].of == NULL ||
112                                  sfun[o->otype].of->setsrc == NULL)
113                          objerror(o, USER, "illegal material");
# Line 119 | Line 120 | marksources(void)                      /* find and mark source objects */
120                  if (m->otype == MAT_GLOW) {
121                          source[ns].sflags |= SPROX;
122                          source[ns].sl.prox = m->oargs.farg[3];
123 <                        if (source[ns].sflags & SDISTANT)
123 >                        if (source[ns].sflags & SDISTANT) {
124                                  source[ns].sflags |= SSKIP;
125 +                                foundsource += (ambounce > 0);
126 +                        }
127                  } else if (m->otype == MAT_SPOT) {
128                          source[ns].sflags |= SSPOT;
129                          if ((source[ns].sl.s = makespot(m)) == NULL)
# Line 135 | Line 138 | marksources(void)                      /* find and mark source objects */
138   #if  SHADCACHE
139                  initobscache(ns);
140   #endif
141 <                if (!(source[ns].sflags & SSKIP))
139 <                        foundsource++;
141 >                foundsource += !(source[ns].sflags & SSKIP);
142          }
143          if (!foundsource) {
144                  error(WARNING, "no light sources found");
145                  return;
146          }
147 <        markvirtuals();                 /* find and add virtual sources */
147 >        
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 155 | Line 161 | memerr:
161   }
162  
163  
164 < extern void
164 > void
165   freesources(void)                       /* free all source structures */
166   {
167          if (nsources > 0) {
# Line 178 | Line 184 | freesources(void)                      /* free all source structures */
184   }
185  
186  
187 < extern int
187 > int
188   srcray(                         /* send a ray to a source, return domega */
189 <        register RAY  *sr,              /* returned source ray */
189 >        RAY  *sr,               /* returned source ray */
190          RAY  *r,                        /* ray which hit object */
191          SRCINDEX  *si                   /* source sample index */
192   )
193   {
194          double  d;                              /* distance to source */
195 <        register SRCREC  *srcp;
195 >        SRCREC  *srcp;
196  
197          rayorigin(sr, SHADOW, r, NULL);         /* ignore limits */
198  
# Line 220 | Line 226 | srcray(                                /* send a ray to a source, return domega */
226   }
227  
228  
229 < extern void
229 > void
230   srcvalue(                       /* punch ray to source and compute value */
231 <        register RAY  *r
231 >        RAY  *r
232   )
233   {
234 <        register SRCREC  *sp;
234 >        SRCREC  *sp;
235  
236          sp = &source[r->rsrc];
237          if (sp->sflags & SVIRTUAL) {    /* virtual source */
# Line 277 | Line 283 | transillum(                    /* check if material is transparent illu
283   }
284  
285  
286 < extern int
286 > int
287   sourcehit(                      /* check to see if ray hit distant source */
288 <        register RAY  *r
288 >        RAY  *r
289   )
290   {
291          int  glowsrc = -1;
292          int  transrc = -1;
293          int  first, last;
294 <        register int  i;
294 >        int  i;
295  
296          if (r->rsrc >= 0) {             /* check only one if aimed */
297                  first = last = r->rsrc;
# Line 353 | Line 359 | cntcmp(                                /* contribution compare (descending) */
359          const void *p2
360   )
361   {
362 <        register const CNTPTR  *sc1 = (const CNTPTR *)p1;
363 <        register const CNTPTR  *sc2 = (const CNTPTR *)p2;
362 >        const CNTPTR  *sc1 = (const CNTPTR *)p1;
363 >        const CNTPTR  *sc2 = (const CNTPTR *)p2;
364  
365          if (sc1->brt > sc2->brt)
366                  return(-1);
# Line 364 | Line 370 | cntcmp(                                /* contribution compare (descending) */
370   }
371  
372  
373 < extern void
373 > void
374   direct(                                 /* add direct component */
375          RAY  *r,                        /* ray that hit surface */
376          srcdirf_t *f,                   /* direct component coefficient function */
377          void  *p                        /* data for f */
378   )
379   {
380 <        register int  sn;
381 <        register CONTRIB  *scp;
380 >        int  sn;
381 >        CONTRIB  *scp;
382          SRCINDEX  si;
383          int  nshadcheck, ncnts;
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 420 | Line 434 | direct(                                        /* add direct component */
434                                                  /* sort contributions */
435          qsort(cntord, sn, sizeof(CNTPTR), cntcmp);
436          {                                       /* find last */
437 <                register int  l, m;
437 >                int  l, m;
438  
439                  ncnts = l = sn;
440                  sn = 0;
# 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 515 | Line 532 | direct(                                        /* add direct component */
532   }
533  
534  
535 < extern void
535 > void
536   srcscatter(                     /* compute source scattering into ray */
537 <        register RAY  *r
537 >        RAY  *r
538   )
539   {
540          int  oldsampndx;
# 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 680 | Line 708 | weaksrcmat(OBJECT obj)         /* identify material */
708                                  distglow(m, r, raydist(r,PRIMARY)))
709  
710  
711 < extern int
711 > int
712   m_light(                                /* ray hit a light source */
713 <        register OBJREC  *m,
714 <        register RAY  *r
713 >        OBJREC  *m,
714 >        RAY  *r
715   )
716   {
717                                                  /* check for over-counting */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines