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.31 by greg, Tue Mar 11 17:08:55 2003 UTC vs.
Revision 2.65 by greg, Thu May 28 09:03:54 2015 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"
13
11   #include  "otypes.h"
12 <
12 > #include  "rtotypes.h"
13   #include  "source.h"
17
14   #include  "random.h"
15 + #include  "pmap.h"
16 + #include  "pmapsrc.h"
17  
20 extern double  ssampdist;               /* scatter sampling distance */
21
18   #ifndef MAXSSAMP
19   #define MAXSSAMP        16              /* maximum samples per ray */
20   #endif
# Line 43 | Line 39 | static CONTRIB  *srccnt;               /* source contributions in d
39   static CNTPTR  *cntord;                 /* source ordering in direct() */
40   static int  maxcntr = 0;                /* size of contribution arrays */
41  
42 + static int cntcmp(const void *p1, const void *p2);
43  
44 +
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) {
50 +                        OBJECT  aobj;
51 +                        OBJREC  *ao;
52 +                        aobj = lastmod(objndx(o), o->oargs.sarg[0]);
53 +                        if (aobj < 0)
54 +                                objerror(o, USER, "bad reference");
55 +                        ao = objptr(aobj);
56 +                        if (ismaterial(ao->otype))
57 +                                return(ao);
58 +                        if (ao->otype == MOD_ALIAS) {
59 +                                o = ao;
60 +                                continue;
61 +                        }
62 +                }
63 +                if (o->omod == OVOID)
64 +                        return(NULL);
65 +                o = objptr(o->omod);
66 +        }
67 +        return(o);              /* mixtures will return NULL */
68 + }
69 +
70 +
71   void
72 < marksources()                   /* find and mark source objects */
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 */
81 <        for (i = 0; i < nobjects; i++) {
81 >        for (i = 0; i < nsceneobjs; i++) {
82          
83                  o = objptr(i);
84  
85                  if (!issurface(o->otype) || o->omod == OVOID)
86                          continue;
87 <
88 <                m = objptr(o->omod);
89 <
66 <                if (!islight(m->otype))
87 >                                        /* find material */
88 >                m = findmaterial(objptr(o->omod));
89 >                if (m == NULL)
90                          continue;
91 +                if (m->otype == MAT_CLIP) {
92 +                        markclip(m);    /* special case for antimatter */
93 +                        continue;
94 +                }
95 +                if (!islight(m->otype))
96 +                        continue;       /* not source modifier */
97          
98                  if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 :
99                                  m->otype == MAT_SPOT ? 7 : 3))
100                          objerror(m, USER, "bad # arguments");
101  
73                if (m->otype == MAT_GLOW &&
74                                o->otype != OBJ_SOURCE &&
75                                m->oargs.farg[3] <= FTINY)
76                        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 90 | Line 120 | marksources()                  /* 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 103 | Line 135 | marksources()                  /* find and mark source objects */
135                                  source[ns].sflags |= SSKIP;
136                          }
137                  }
138 <                if (!(source[ns].sflags & SSKIP))
107 <                        foundsource++;
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 >        initobscache(ns);
146 > #endif
147 >        /* PMAP: disable virtual sources */
148 >        if (!photonMapping)
149 >                markvirtuals();                 /* find and add virtual sources */
150 >                
151                                  /* allocate our contribution arrays */
152          maxcntr = nsources + MAXSPART;  /* start with this many */
153          srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB));
154          cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR));
155 <        if (srccnt == NULL | cntord == NULL)
155 >        if ((srccnt == NULL) | (cntord == NULL))
156                  goto memerr;
157          return;
158   memerr:
# Line 124 | Line 161 | memerr:
161  
162  
163   void
164 < freesources()                   /* free all source structures */
164 > freesources(void)                       /* free all source structures */
165   {
166          if (nsources > 0) {
167 + #if SHADCACHE
168 +                while (nsources--)
169 +                        freeobscache(&source[nsources]);
170 + #endif
171                  free((void *)source);
172                  source = NULL;
173                  nsources = 0;
174          }
175 +        markclip(NULL);
176          if (maxcntr <= 0)
177                  return;
178          free((void *)srccnt);
# Line 142 | Line 184 | freesources()                  /* free all source structures */
184  
185  
186   int
187 < srcray(sr, r, si)               /* send a ray to a source, return domega */
188 < register RAY  *sr;              /* returned source ray */
189 < RAY  *r;                        /* ray which hit object */
190 < SRCINDEX  *si;                  /* source sample index */
187 > srcray(                         /* send a ray to a source, return domega */
188 >        RAY  *sr,               /* returned source ray */
189 >        RAY  *r,                        /* ray which hit object */
190 >        SRCINDEX  *si                   /* source sample index */
191 > )
192   {
193 <    double  d;                          /* distance to source */
194 <    register SRCREC  *srcp;
193 >        double  d;                              /* distance to source */
194 >        SRCREC  *srcp;
195  
196 <    rayorigin(sr, r, SHADOW, 1.0);              /* ignore limits */
196 >        rayorigin(sr, SHADOW, r, NULL);         /* ignore limits */
197  
198 <    while ((d = nextssamp(sr, si)) != 0.0) {
199 <        sr->rsrc = si->sn;                      /* remember source */
200 <        srcp = source + si->sn;
201 <        if (srcp->sflags & SDISTANT) {
202 <                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s))
203 <                        continue;
204 <                return(1);              /* sample OK */
205 <        }
198 >        if (r == NULL)
199 >                sr->rmax = 0.0;
200 >
201 >        while ((d = nextssamp(sr, si)) != 0.0) {
202 >                sr->rsrc = si->sn;                      /* remember source */
203 >                srcp = source + si->sn;
204 >                if (srcp->sflags & SDISTANT) {
205 >                        if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s))
206 >                                continue;
207 >                        return(1);              /* sample OK */
208 >                }
209                                  /* local source */
210                                                  /* check proximity */
211 <        if (srcp->sflags & SPROX && d > srcp->sl.prox)
166 <                continue;
167 <                                                /* check angle */
168 <        if (srcp->sflags & SSPOT) {
169 <                if (spotout(sr, srcp->sl.s))
211 >                if (srcp->sflags & SPROX && d > srcp->sl.prox)
212                          continue;
213 +                                                /* check angle */
214 +                if (srcp->sflags & SSPOT) {
215 +                        if (spotout(sr, srcp->sl.s))
216 +                                continue;
217                                          /* adjust solid angle */
218 <                si->dom *= d*d;
219 <                d += srcp->sl.s->flen;
220 <                si->dom /= d*d;
218 >                        si->dom *= d*d;
219 >                        d += srcp->sl.s->flen;
220 >                        si->dom /= d*d;
221 >                }
222 >                return(1);                      /* sample OK */
223          }
224 <        return(1);                      /* sample OK */
177 <    }
178 <    return(0);                  /* no more samples */
224 >        return(0);                      /* no more samples */
225   }
226  
227  
228   void
229 < srcvalue(r)                     /* punch ray to source and compute value */
230 < register RAY  *r;
229 > srcvalue(                       /* punch ray to source and compute value */
230 >        RAY  *r
231 > )
232   {
233 <        register SRCREC  *sp;
233 >        SRCREC  *sp;
234  
235          sp = &source[r->rsrc];
236          if (sp->sflags & SVIRTUAL) {    /* virtual source */
# Line 220 | Line 267 | nomat:
267   }
268  
269  
270 + static int
271 + transillum(                     /* check if material is transparent illum */
272 +        OBJECT  obj
273 + )
274 + {
275 +        OBJREC *m = findmaterial(objptr(obj));
276 +        
277 +        if (m == NULL)
278 +                return(1);
279 +        if (m->otype != MAT_ILLUM)
280 +                return(0);
281 +        return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID));
282 + }
283 +
284 +
285   int
286 < sourcehit(r)                    /* check to see if ray hit distant source */
287 < register RAY  *r;
286 > sourcehit(                      /* check to see if ray hit distant source */
287 >        RAY  *r
288 > )
289   {
290 +        int  glowsrc = -1;
291 +        int  transrc = -1;
292          int  first, last;
293 <        register int  i;
293 >        int  i;
294  
295          if (r->rsrc >= 0) {             /* check only one if aimed */
296                  first = last = r->rsrc;
297          } else {                        /* otherwise check all */
298                  first = 0; last = nsources-1;
299          }
300 <        for (i = first; i <= last; i++)
301 <                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT)
302 <                        /*
303 <                         * Check to see if ray is within
304 <                         * solid angle of source.
305 <                         */
306 <                        if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir))
307 <                                        <= source[i].ss2) {
308 <                                r->ro = source[i].so;
309 <                                if (!(source[i].sflags & SSKIP))
310 <                                        break;
311 <                        }
312 <
313 <        if (r->ro != NULL) {
314 <                r->robj = objndx(r->ro);
315 <                for (i = 0; i < 3; i++)
316 <                        r->ron[i] = -r->rdir[i];
317 <                r->rod = 1.0;
318 <                r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
319 <                r->uv[0] = r->uv[1] = 0.0;
320 <                r->rox = NULL;
321 <                return(1);
300 >        for (i = first; i <= last; i++) {
301 >                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT)
302 >                        continue;
303 >                /*
304 >                 * Check to see if ray is within
305 >                 * solid angle of source.
306 >                 */
307 >                if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2)
308 >                        continue;
309 >                                        /* is it the only possibility? */
310 >                if (first == last) {
311 >                        r->ro = source[i].so;
312 >                        break;
313 >                }
314 >                /*
315 >                 * If it's a glow or transparent illum, just remember it.
316 >                 */
317 >                if (source[i].sflags & SSKIP) {
318 >                        if (glowsrc < 0)
319 >                                glowsrc = i;
320 >                        continue;
321 >                }
322 >                if (transillum(source[i].so->omod)) {
323 >                        if (transrc < 0)
324 >                                transrc = i;
325 >                        continue;
326 >                }
327 >                r->ro = source[i].so;   /* otherwise, use first hit */
328 >                break;
329          }
330 <        return(0);
330 >        /*
331 >         * Do we need fallback?
332 >         */
333 >        if (r->ro == NULL) {
334 >                if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR))
335 >                        return(0);      /* avoid overcounting */
336 >                if (glowsrc >= 0)
337 >                        r->ro = source[glowsrc].so;
338 >                else
339 >                        return(0);      /* nothing usable */
340 >        }
341 >        /*
342 >         * Make assignments.
343 >         */
344 >        r->robj = objndx(r->ro);
345 >        for (i = 0; i < 3; i++)
346 >                r->ron[i] = -r->rdir[i];
347 >        r->rod = 1.0;
348 >        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
349 >        r->uv[0] = r->uv[1] = 0.0;
350 >        r->rox = NULL;
351 >        return(1);
352   }
353  
354  
355   static int
356 < cntcmp(sc1, sc2)                        /* contribution compare (descending) */
357 < register CNTPTR  *sc1, *sc2;
356 > cntcmp(                         /* contribution compare (descending) */
357 >        const void *p1,
358 >        const void *p2
359 > )
360   {
361 +        const CNTPTR  *sc1 = (const CNTPTR *)p1;
362 +        const CNTPTR  *sc2 = (const CNTPTR *)p2;
363 +
364          if (sc1->brt > sc2->brt)
365                  return(-1);
366          if (sc1->brt < sc2->brt)
# Line 272 | Line 370 | register CNTPTR  *sc1, *sc2;
370  
371  
372   void
373 < direct(r, f, p)                         /* add direct component */
374 < RAY  *r;                        /* ray that hit surface */
375 < void  (*f)();                   /* direct component coefficient function */
376 < char  *p;                       /* data for f */
373 > direct(                                 /* add direct component */
374 >        RAY  *r,                        /* ray that hit surface */
375 >        srcdirf_t *f,                   /* direct component coefficient function */
376 >        void  *p                        /* data for f */
377 > )
378   {
379 <        extern void  (*trace)();
380 <        register int  sn;
282 <        register CONTRIB  *scp;
379 >        int  sn;
380 >        CONTRIB  *scp;
381          SRCINDEX  si;
382          int  nshadcheck, ncnts;
383          int  nhits;
384          double  prob, ourthresh, hwt;
385          RAY  sr;
386 +        
387 +        /* PMAP: Factor in direct photons (primarily for debugging/validation) */
388 +        if (directPhotonMapping) {
389 +                (*f)(r -> rcol, p, r -> ron, PI);              
390 +                multDirectPmap(r);
391 +                return;
392 +        }
393 +        
394                          /* NOTE: srccnt and cntord global so no recursion */
395          if (nsources <= 0)
396                  return;         /* no sources?! */
# Line 293 | Line 399 | char  *p;                      /* data for f */
399          for (sn = 0; srcray(&sr, r, &si); sn++) {
400                  if (sn >= maxcntr) {
401                          maxcntr = sn + MAXSPART;
402 <                        srccnt = (CONTRIB *)realloc((char *)srccnt,
402 >                        srccnt = (CONTRIB *)realloc((void *)srccnt,
403                                          maxcntr*sizeof(CONTRIB));
404 <                        cntord = (CNTPTR *)realloc((char *)cntord,
404 >                        cntord = (CNTPTR *)realloc((void *)cntord,
405                                          maxcntr*sizeof(CNTPTR));
406 <                        if (srccnt == NULL | cntord == NULL)
406 >                        if ((srccnt == NULL) | (cntord == NULL))
407                                  error(SYSTEM, "out of memory in direct");
408                  }
409                  cntord[sn].sndx = sn;
# Line 305 | Line 411 | char  *p;                      /* data for f */
411                  scp->sno = sr.rsrc;
412                                                  /* compute coefficient */
413                  (*f)(scp->coef, p, sr.rdir, si.dom);
414 <                cntord[sn].brt = bright(scp->coef);
414 >                cntord[sn].brt = intens(scp->coef);
415                  if (cntord[sn].brt <= 0.0)
416                          continue;
417 + #if SHADCACHE
418 +                                                /* check shadow cache */
419 +                if (si.np == 1 && srcblocked(&sr)) {
420 +                        cntord[sn].brt = 0.0;
421 +                        continue;
422 +                }
423 + #endif
424                  VCOPY(scp->dir, sr.rdir);
425 +                copycolor(sr.rcoef, scp->coef);
426                                                  /* compute potential */
427                  sr.revf = srcvalue;
428                  rayvalue(&sr);
429 +                multcolor(sr.rcol, sr.rcoef);
430                  copycolor(scp->val, sr.rcol);
431 <                multcolor(scp->val, scp->coef);
317 <                cntord[sn].brt = bright(scp->val);
431 >                cntord[sn].brt = bright(sr.rcol);
432          }
433                                                  /* sort contributions */
434          qsort(cntord, sn, sizeof(CNTPTR), cntcmp);
435          {                                       /* find last */
436 <                register int  l, m;
436 >                int  l, m;
437  
438                  ncnts = l = sn;
439                  sn = 0;
# Line 339 | Line 453 | char  *p;                      /* data for f */
453                                                  /* compute number to check */
454          nshadcheck = pow((double)ncnts, shadcert) + .5;
455                                                  /* modify threshold */
456 <        ourthresh = shadthresh / r->rweight;
456 >        if (ncnts > MINSHADCNT)
457 >                ourthresh = shadthresh / r->rweight;
458 >        else
459 >                ourthresh = 0;
460                                                  /* test for shadows */
461          for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts;
462                          hwt += (double)source[scp->sno].nhits /
# Line 352 | Line 469 | char  *p;                      /* data for f */
469                          break;
470                  scp = srccnt + cntord[sn].sndx;
471                                                  /* test for hit */
472 <                rayorigin(&sr, r, SHADOW, 1.0);
472 >                rayorigin(&sr, SHADOW, r, NULL);
473 >                copycolor(sr.rcoef, scp->coef);
474                  VCOPY(sr.rdir, scp->dir);
475                  sr.rsrc = scp->sno;
476 <                source[scp->sno].ntests++;      /* keep statistics */
476 >                                                /* keep statistics */
477 >                if (source[scp->sno].ntests++ > 0xfffffff0) {
478 >                        source[scp->sno].ntests >>= 1;
479 >                        source[scp->sno].nhits >>= 1;
480 >                }
481                  if (localhit(&sr, &thescene) &&
482                                  ( sr.ro != source[scp->sno].so ||
483                                  source[scp->sno].sflags & SFOLLOW )) {
484                                                  /* follow entire path */
485                          raycont(&sr);
364                        rayparticipate(&sr);
486                          if (trace != NULL)
487                                  (*trace)(&sr);  /* trace execution */
488 <                        if (bright(sr.rcol) <= FTINY)
488 >                        if (bright(sr.rcol) <= FTINY) {
489 > #if SHADCACHE
490 >                                if ((scp <= srccnt || scp[-1].sno != scp->sno)
491 >                                                && (scp >= srccnt+ncnts-1 ||
492 >                                                    scp[1].sno != scp->sno))
493 >                                        srcblocker(&sr);
494 > #endif
495                                  continue;       /* missed! */
496 +                        }
497 +                        rayparticipate(&sr);
498 +                        multcolor(sr.rcol, sr.rcoef);
499                          copycolor(scp->val, sr.rcol);
500 <                        multcolor(scp->val, scp->coef);
500 >                } else if (trace != NULL &&
501 >                        (source[scp->sno].sflags & (SDISTANT|SVIRTUAL|SFOLLOW))
502 >                                                == (SDISTANT|SFOLLOW) &&
503 >                                sourcehit(&sr) && rayshade(&sr, sr.ro->omod)) {
504 >                        (*trace)(&sr);          /* trace execution */
505 >                        /* skip call to rayparticipate() & scp->val update */
506                  }
507                                                  /* add contribution if hit */
508                  addcolor(r->rcol, scp->val);
# Line 389 | Line 524 | char  *p;                      /* data for f */
524                  scp = srccnt + cntord[sn].sndx;
525                  prob = hwt * (double)source[scp->sno].nhits /
526                                  (double)source[scp->sno].ntests;
527 <                if (prob > 1.0)
528 <                        prob = 1.0;
394 <                scalecolor(scp->val, prob);
527 >                if (prob < 1.0)
528 >                        scalecolor(scp->val, prob);
529                  addcolor(r->rcol, scp->val);
530          }
531   }
532  
533  
534   void
535 < srcscatter(r)                   /* compute source scattering into ray */
536 < register RAY  *r;
535 > srcscatter(                     /* compute source scattering into ray */
536 >        RAY  *r
537 > )
538   {
539          int  oldsampndx;
540          int  nsamps;
# Line 407 | Line 542 | register RAY  *r;
542          SRCINDEX  si;
543          double  t, d;
544          double  re, ge, be;
545 <        COLOR  cvext;
545 >        COLOR  cvext, pmapInscatter;
546          int  i, j;
547  
548 +        /* PMAP: do unconditional inscattering for volume photons ? */
549 +        /* if (!volumePhotonMapping) */
550          if (r->slights == NULL || r->slights[0] == 0
551                          || r->gecc >= 1.-FTINY || r->rot >= FHUGE)
552                  return;
553 +                
554          if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
555                  nsamps = 1;
556   #if MAXSSAMP
# Line 437 | Line 575 | register RAY  *r;
575                          sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
576                          sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
577                          sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
440                        sr.rmax = 0.;
578                          initsrcindex(&si);      /* sample ray to this source */
579                          si.sn = r->slights[i];
580                          nopart(&si, &sr);
581                          if (!srcray(&sr, NULL, &si) ||
582                                          sr.rsrc != r->slights[i])
583                                  continue;               /* no path */
584 + #if SHADCACHE
585 +                        if (srcblocked(&sr))            /* check shadow cache */
586 +                                continue;
587 + #endif
588                          copycolor(sr.cext, r->cext);
589                          copycolor(sr.albedo, r->albedo);
590                          sr.gecc = r->gecc;
591                          sr.slights = r->slights;
592                          rayvalue(&sr);                  /* eval. source ray */
593 <                        if (bright(sr.rcol) <= FTINY)
593 >                        if (bright(sr.rcol) <= FTINY) {
594 > #if SHADCACHE
595 >                                srcblocker(&sr);        /* add blocker to cache */
596 > #endif
597                                  continue;
598 +                        }
599                          if (r->gecc <= FTINY)           /* compute P(theta) */
600                                  d = 1.;
601                          else {
# Line 460 | Line 605 | register RAY  *r;
605                          }
606                                                          /* other factors */
607                          d *= si.dom * r->rot / (4.*PI*nsamps);
608 +                        scalecolor(sr.rcol, d);
609 +                        
610 +                        /* PMAP: Add ambient inscattering from volume photons once only */
611 +                        if (volumePhotonMapping && i == 1) {
612 +                           inscatterVolumePmap(&sr, pmapInscatter);
613 +            scalecolor(pmapInscatter, r -> rot / nsamps);
614 +            addcolor(sr.rcol, pmapInscatter);
615 +         }
616 +                        
617                          multcolor(sr.rcol, r->cext);
618                          multcolor(sr.rcol, r->albedo);
465                        scalecolor(sr.rcol, d);
619                          multcolor(sr.rcol, cvext);
620                          addcolor(r->rcol, sr.rcol);     /* add it in */
621                  }
# Line 487 | Line 640 | register RAY  *r;
640   * geometry behind (or inside) an effective radiator.
641   */
642  
643 < static int weaksrcmod(obj) int obj;     /* efficiency booster function */
644 < {register OBJREC *o = objptr(obj);
645 < return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
643 > static int
644 > weaksrcmat(OBJECT obj)          /* identify material */
645 > {
646 >        OBJREC *m = findmaterial(objptr(obj));
647 >        
648 >        if (m == NULL) return(0);
649 >        return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW));
650 > }
651  
652   #define  illumblock(m, r)       (!(source[r->rsrc].sflags&SVIRTUAL) && \
653                                  r->rod > 0.0 && \
654 <                                weaksrcmod(source[r->rsrc].so->omod))
654 >                                weaksrcmat(source[r->rsrc].so->omod))
655  
656   /* wrongsource *
657   *
# Line 550 | Line 708 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
708  
709  
710   int
711 < m_light(m, r)                   /* ray hit a light source */
712 < register OBJREC  *m;
713 < register RAY  *r;
711 > m_light(                                /* ray hit a light source */
712 >        OBJREC  *m,
713 >        RAY  *r
714 > )
715   {
716                                                  /* check for over-counting */
717 <        if (badcomponent(m, r))
717 >        if (badcomponent(m, r)) {
718 >                setcolor(r->rcoef, 0.0, 0.0, 0.0);
719                  return(1);
720 <        if (wrongsource(m, r))
720 >        }
721 >        if (wrongsource(m, r)) {
722 >                setcolor(r->rcoef, 0.0, 0.0, 0.0);
723                  return(1);
724 +        }
725                                                  /* check for passed illum */
726          if (passillum(m, r)) {
727                  if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID))
# Line 566 | Line 729 | register RAY  *r;
729                  raytrans(r);
730                  return(1);
731          }
732 +                                                /* check for invisibility */
733 +        if (srcignore(m, r)) {
734 +                setcolor(r->rcoef, 0.0, 0.0, 0.0);
735 +                return(1);
736 +        }
737                                          /* otherwise treat as source */
738                                                  /* check for behind */
739          if (r->rod < 0.0)
572                return(1);
573                                                /* check for invisibility */
574        if (srcignore(m, r))
740                  return(1);
741                                                  /* check for outside spot */
742          if (m->otype==MAT_SPOT && spotout(r, makespot(m)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines