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.34 by greg, Tue Jun 24 15:37:01 2003 UTC vs.
Revision 2.40 by greg, Wed Dec 31 19:38:27 2003 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *  External symbols declared in source.h
8   */
9  
10 #include "copyright.h"
11
10   #include  "ray.h"
11  
12   #include  "otypes.h"
# Line 44 | Line 42 | static CNTPTR  *cntord;                        /* source ordering in direct
42   static int  maxcntr = 0;                /* size of contribution arrays */
43  
44  
45 + OBJREC *                        /* find an object's actual material */
46 + findmaterial(register OBJREC *o)
47 + {
48 +        while (!ismaterial(o->otype)) {
49 +                if (ismixture(o->otype))
50 +                        return(NULL);   /* reject mixed materials */
51 +                if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
52 +                        OBJECT  aobj;
53 +                        OBJREC  *ao;
54 +                        aobj = lastmod(objndx(o), o->oargs.sarg[0]);
55 +                        if (aobj < 0)
56 +                                objerror(o, USER, "bad reference");
57 +                        ao = objptr(aobj);
58 +                        if (ismaterial(ao->otype))
59 +                                return(ao);
60 +                }
61 +                if (o->omod == OVOID)
62 +                        return(NULL);
63 +                o = objptr(o->omod);
64 +        }
65 +        return(o);
66 + }
67 +
68 +
69   void
70   marksources()                   /* find and mark source objects */
71   {
# Line 60 | Line 82 | marksources()                  /* find and mark source objects */
82  
83                  if (!issurface(o->otype) || o->omod == OVOID)
84                          continue;
85 <
86 <                m = objptr(o->omod);
87 <
88 <                if (!islight(m->otype))
67 <                        continue;
85 >                                        /* find material */
86 >                m = findmaterial(o);
87 >                if (m == NULL || !islight(m->otype))
88 >                        continue;       /* not source modifier */
89          
90                  if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 :
91                                  m->otype == MAT_SPOT ? 7 : 3))
# Line 103 | Line 124 | marksources()                  /* find and mark source objects */
124                                  source[ns].sflags |= SSKIP;
125                          }
126                  }
127 + #if  SHADCACHE
128 +                source[ns].obscache = NULL;
129 + #endif
130                  if (!(source[ns].sflags & SSKIP))
131                          foundsource++;
132          }
# Line 115 | Line 139 | marksources()                  /* find and mark source objects */
139          maxcntr = nsources + MAXSPART;  /* start with this many */
140          srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB));
141          cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR));
142 <        if (srccnt == NULL | cntord == NULL)
142 >        if ((srccnt == NULL) | (cntord == NULL))
143                  goto memerr;
144          return;
145   memerr:
# Line 127 | Line 151 | void
151   freesources()                   /* free all source structures */
152   {
153          if (nsources > 0) {
154 + #if SHADCACHE
155 +                while (nsources--)
156 +                        freeobscache(&source[nsources]);
157 + #endif
158                  free((void *)source);
159                  source = NULL;
160                  nsources = 0;
# Line 142 | Line 170 | freesources()                  /* free all source structures */
170  
171  
172   int
173 < srcray(sr, r, si)               /* send a ray to a source, return domega */
174 < register RAY  *sr;              /* returned source ray */
175 < RAY  *r;                        /* ray which hit object */
176 < SRCINDEX  *si;                  /* source sample index */
173 > srcray(                         /* send a ray to a source, return domega */
174 > register RAY  *sr,              /* returned source ray */
175 > RAY  *r,                        /* ray which hit object */
176 > SRCINDEX  *si                   /* source sample index */
177 > )
178   {
179      double  d;                          /* distance to source */
180      register SRCREC  *srcp;
# Line 180 | Line 209 | SRCINDEX  *si;                 /* source sample index */
209  
210  
211   void
212 < srcvalue(r)                     /* punch ray to source and compute value */
213 < register RAY  *r;
212 > srcvalue(                       /* punch ray to source and compute value */
213 > register RAY  *r
214 > )
215   {
216          register SRCREC  *sp;
217  
# Line 221 | Line 251 | nomat:
251  
252  
253   int
254 < sourcehit(r)                    /* check to see if ray hit distant source */
255 < register RAY  *r;
254 > sourcehit(                      /* check to see if ray hit distant source */
255 > register RAY  *r
256 > )
257   {
258          int  first, last;
259          register int  i;
# Line 260 | Line 291 | register RAY  *r;
291  
292  
293   static int
294 < cntcmp(sc1, sc2)                        /* contribution compare (descending) */
295 < register CNTPTR  *sc1, *sc2;
294 > cntcmp(                         /* contribution compare (descending) */
295 > const void *p1,
296 > const void *p2
297 > )
298   {
299 +        register const CNTPTR  *sc1 = (const CNTPTR *)p1;
300 +        register const CNTPTR  *sc2 = (const CNTPTR *)p2;
301 +
302          if (sc1->brt > sc2->brt)
303                  return(-1);
304          if (sc1->brt < sc2->brt)
# Line 272 | Line 308 | register CNTPTR  *sc1, *sc2;
308  
309  
310   void
311 < direct(r, f, p)                         /* add direct component */
312 < RAY  *r;                        /* ray that hit surface */
313 < void  (*f)();                   /* direct component coefficient function */
314 < char  *p;                       /* data for f */
311 > direct(                                 /* add direct component */
312 > RAY  *r,                        /* ray that hit surface */
313 > void  (*f)(),                   /* direct component coefficient function */
314 > char  *p                        /* data for f */
315 > )
316   {
317          extern void  (*trace)();
318          register int  sn;
# Line 297 | Line 334 | char  *p;                      /* data for f */
334                                          maxcntr*sizeof(CONTRIB));
335                          cntord = (CNTPTR *)realloc((void *)cntord,
336                                          maxcntr*sizeof(CNTPTR));
337 <                        if (srccnt == NULL | cntord == NULL)
337 >                        if ((srccnt == NULL) | (cntord == NULL))
338                                  error(SYSTEM, "out of memory in direct");
339                  }
340                  cntord[sn].sndx = sn;
# Line 308 | Line 345 | char  *p;                      /* data for f */
345                  cntord[sn].brt = bright(scp->coef);
346                  if (cntord[sn].brt <= 0.0)
347                          continue;
348 + #if SHADCACHE
349 +                                                /* check shadow cache */
350 +                if (si.np == 1 && srcblocked(&sr)) {
351 +                        cntord[sn].brt = 0.0;
352 +                        continue;
353 +                }
354 + #endif
355                  VCOPY(scp->dir, sr.rdir);
356                                                  /* compute potential */
357                  sr.revf = srcvalue;
# Line 368 | Line 412 | char  *p;                      /* data for f */
412                          rayparticipate(&sr);
413                          if (trace != NULL)
414                                  (*trace)(&sr);  /* trace execution */
415 <                        if (bright(sr.rcol) <= FTINY)
415 >                        if (bright(sr.rcol) <= FTINY) {
416 > #if SHADCACHE
417 >                                if ((scp <= srccnt || scp[-1].sno != scp->sno)
418 >                                                && (scp >= srccnt+ncnts ||
419 >                                                    scp[1].sno != scp->sno))
420 >                                        srcblocker(&sr);
421 > #endif
422                                  continue;       /* missed! */
423 +                        }
424                          copycolor(scp->val, sr.rcol);
425                          multcolor(scp->val, scp->coef);
426                  }
# Line 402 | Line 453 | char  *p;                      /* data for f */
453  
454  
455   void
456 < srcscatter(r)                   /* compute source scattering into ray */
457 < register RAY  *r;
456 > srcscatter(                     /* compute source scattering into ray */
457 > register RAY  *r
458 > )
459   {
460          int  oldsampndx;
461          int  nsamps;
# Line 491 | Line 543 | register RAY  *r;
543   * geometry behind (or inside) an effective radiator.
544   */
545  
546 < static int weaksrcmod(obj) int obj;     /* efficiency booster function */
547 < {register OBJREC *o = objptr(obj);
548 < return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
546 > static int
547 > weaksrcmat(int obj)             /* identify material */
548 > {
549 >        register OBJREC *o = objptr(obj);
550 >        
551 >        while (!ismaterial(o->otype))   /* find material */
552 >                o = objptr(o->omod);
553 >        return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW));
554 > }
555  
556   #define  illumblock(m, r)       (!(source[r->rsrc].sflags&SVIRTUAL) && \
557                                  r->rod > 0.0 && \
558 <                                weaksrcmod(source[r->rsrc].so->omod))
558 >                                weaksrcmat(source[r->rsrc].so->omod))
559  
560   /* wrongsource *
561   *
# Line 554 | Line 612 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
612  
613  
614   int
615 < m_light(m, r)                   /* ray hit a light source */
616 < register OBJREC  *m;
617 < register RAY  *r;
615 > m_light(                                /* ray hit a light source */
616 > register OBJREC  *m,
617 > register RAY  *r
618 > )
619   {
620                                                  /* check for over-counting */
621          if (badcomponent(m, r))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines