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.46 by greg, Wed Sep 8 17:10:16 2004 UTC vs.
Revision 2.55 by greg, Thu Sep 7 05:20:54 2006 UTC

# Line 46 | Line 46 | extern 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 */
49                  if (o->otype == MOD_ALIAS && o->oargs.nsargs) {
50                          OBJECT  aobj;
51                          OBJREC  *ao;
# Line 57 | Line 55 | findmaterial(register OBJREC *o)
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);
67 >        return(o);              /* mixtures will return NULL */
68   }
69  
70  
# Line 179 | Line 181 | srcray(                                /* send a ray to a source, return domega */
181      double  d;                          /* distance to source */
182      register SRCREC  *srcp;
183  
184 <    rayorigin(sr, r, SHADOW, 1.0);              /* ignore limits */
184 >    rayorigin(sr, SHADOW, r, NULL);             /* ignore limits */
185  
186      while ((d = nextssamp(sr, si)) != 0.0) {
187          sr->rsrc = si->sn;                      /* remember source */
# Line 250 | Line 252 | nomat:
252   }
253  
254  
255 + static int
256 + transillum(                     /* check if material is transparent illum */
257 +        OBJECT  obj
258 + )
259 + {
260 +        OBJREC *m = findmaterial(objptr(obj));
261 +        
262 +        if (m == NULL)
263 +                return(1);
264 +        if (m->otype != MAT_ILLUM)
265 +                return(0);
266 +        return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID));
267 + }
268 +
269 +
270   extern int
271   sourcehit(                      /* check to see if ray hit distant source */
272          register RAY  *r
273   )
274   {
275 +        int  glowsrc = -1;
276 +        int  transrc = -1;
277          int  first, last;
278          register int  i;
279  
# Line 263 | Line 282 | sourcehit(                     /* check to see if ray hit distant source
282          } else {                        /* otherwise check all */
283                  first = 0; last = nsources-1;
284          }
285 <        for (i = first; i <= last; i++)
286 <                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT)
287 <                        /*
288 <                         * Check to see if ray is within
289 <                         * solid angle of source.
290 <                         */
291 <                        if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir))
292 <                                        <= source[i].ss2) {
293 <                                r->ro = source[i].so;
294 <                                if (!(source[i].sflags & SSKIP))
295 <                                        break;
296 <                        }
297 <
298 <        if (r->ro != NULL) {
299 <                r->robj = objndx(r->ro);
300 <                for (i = 0; i < 3; i++)
301 <                        r->ron[i] = -r->rdir[i];
302 <                r->rod = 1.0;
303 <                r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
304 <                r->uv[0] = r->uv[1] = 0.0;
305 <                r->rox = NULL;
306 <                return(1);
285 >        for (i = first; i <= last; i++) {
286 >                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT)
287 >                        continue;
288 >                /*
289 >                 * Check to see if ray is within
290 >                 * solid angle of source.
291 >                 */
292 >                if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2)
293 >                        continue;
294 >                                        /* is it the only possibility? */
295 >                if (first == last) {
296 >                        r->ro = source[i].so;
297 >                        break;
298 >                }
299 >                /*
300 >                 * If it's a glow or transparent illum, just remember it.
301 >                 */
302 >                if (source[i].sflags & SSKIP) {
303 >                        glowsrc = i;
304 >                        continue;
305 >                }
306 >                if (transillum(source[i].so->omod)) {
307 >                        transrc = i;
308 >                        continue;
309 >                }
310 >                r->ro = source[i].so;   /* otherwise, use first hit */
311 >                break;
312          }
313 <        return(0);
313 >        /*
314 >         * Do we need fallback?
315 >         */
316 >        if (r->ro == NULL) {
317 >                if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR))
318 >                        return(0);      /* avoid overcounting */
319 >                if (glowsrc >= 0)
320 >                        r->ro = source[glowsrc].so;
321 >                else
322 >                        return(0);      /* nothing usable */
323 >        }
324 >        /*
325 >         * Make assignments.
326 >         */
327 >        r->robj = objndx(r->ro);
328 >        for (i = 0; i < 3; i++)
329 >                r->ron[i] = -r->rdir[i];
330 >        r->rod = 1.0;
331 >        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
332 >        r->uv[0] = r->uv[1] = 0.0;
333 >        r->rox = NULL;
334 >        return(1);
335   }
336  
337  
# Line 341 | Line 386 | direct(                                        /* add direct component */
386                  scp->sno = sr.rsrc;
387                                                  /* compute coefficient */
388                  (*f)(scp->coef, p, sr.rdir, si.dom);
389 <                cntord[sn].brt = bright(scp->coef);
389 >                cntord[sn].brt = intens(scp->coef);
390                  if (cntord[sn].brt <= 0.0)
391                          continue;
392   #if SHADCACHE
# Line 352 | Line 397 | direct(                                        /* add direct component */
397                  }
398   #endif
399                  VCOPY(scp->dir, sr.rdir);
400 +                copycolor(sr.rcoef, scp->coef);
401                                                  /* compute potential */
402                  sr.revf = srcvalue;
403                  rayvalue(&sr);
404 +                multcolor(sr.rcol, sr.rcoef);
405                  copycolor(scp->val, sr.rcol);
406 <                multcolor(scp->val, scp->coef);
360 <                cntord[sn].brt = bright(scp->val);
406 >                cntord[sn].brt = intens(sr.rcol);
407          }
408                                                  /* sort contributions */
409          qsort(cntord, sn, sizeof(CNTPTR), cntcmp);
# Line 395 | Line 441 | direct(                                        /* add direct component */
441                          break;
442                  scp = srccnt + cntord[sn].sndx;
443                                                  /* test for hit */
444 <                rayorigin(&sr, r, SHADOW, 1.0);
444 >                rayorigin(&sr, SHADOW, r, NULL);
445 >                copycolor(sr.rcoef, scp->coef);
446                  VCOPY(sr.rdir, scp->dir);
447                  sr.rsrc = scp->sno;
448                                                  /* keep statistics */
# Line 408 | Line 455 | direct(                                        /* add direct component */
455                                  source[scp->sno].sflags & SFOLLOW )) {
456                                                  /* follow entire path */
457                          raycont(&sr);
411                        rayparticipate(&sr);
458                          if (trace != NULL)
459                                  (*trace)(&sr);  /* trace execution */
460                          if (bright(sr.rcol) <= FTINY) {
# Line 420 | Line 466 | direct(                                        /* add direct component */
466   #endif
467                                  continue;       /* missed! */
468                          }
469 +                        rayparticipate(&sr);
470 +                        multcolor(sr.rcol, sr.rcoef);
471                          copycolor(scp->val, sr.rcol);
472 <                        multcolor(scp->val, scp->coef);
472 >                } else if (trace != NULL &&
473 >                        (source[scp->sno].sflags & (SDISTANT|SVIRTUAL|SFOLLOW))
474 >                                                == (SDISTANT|SFOLLOW) &&
475 >                                sourcehit(&sr) && rayshade(&sr, sr.ro->omod)) {
476 >                        (*trace)(&sr);          /* trace execution */
477 >                        /* skip call to rayparticipate() & scp->val update */
478                  }
479                                                  /* add contribution if hit */
480                  addcolor(r->rcol, scp->val);
# Line 443 | Line 496 | direct(                                        /* add direct component */
496                  scp = srccnt + cntord[sn].sndx;
497                  prob = hwt * (double)source[scp->sno].nhits /
498                                  (double)source[scp->sno].ntests;
499 <                if (prob > 1.0)
500 <                        prob = 1.0;
448 <                scalecolor(scp->val, prob);
499 >                if (prob < 1.0)
500 >                        scalecolor(scp->val, prob);
501                  addcolor(r->rcol, scp->val);
502          }
503   }
# Line 553 | Line 605 | srcscatter(                    /* compute source scattering into ray */
605   static int
606   weaksrcmat(OBJECT obj)          /* identify material */
607   {
608 <        OBJREC *o = findmaterial(objptr(obj));
608 >        OBJREC *m = findmaterial(objptr(obj));
609          
610 <        if (o == NULL) return 0;
611 <        return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW));
610 >        if (m == NULL) return(0);
611 >        return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW));
612   }
613  
614   #define  illumblock(m, r)       (!(source[r->rsrc].sflags&SVIRTUAL) && \
# Line 624 | Line 676 | m_light(                               /* ray hit a light source */
676   )
677   {
678                                                  /* check for over-counting */
679 <        if (badcomponent(m, r))
679 >        if (badcomponent(m, r)) {
680 >                setcolor(r->rcoef, 0.0, 0.0, 0.0);
681                  return(1);
682 <        if (wrongsource(m, r))
682 >        }
683 >        if (wrongsource(m, r)) {
684 >                setcolor(r->rcoef, 0.0, 0.0, 0.0);
685                  return(1);
686 +        }
687                                                  /* check for passed illum */
688          if (passillum(m, r)) {
689                  if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID))
# Line 635 | Line 691 | m_light(                               /* ray hit a light source */
691                  raytrans(r);
692                  return(1);
693          }
694 +                                                /* check for invisibility */
695 +        if (srcignore(m, r)) {
696 +                setcolor(r->rcoef, 0.0, 0.0, 0.0);
697 +                return(1);
698 +        }
699                                          /* otherwise treat as source */
700                                                  /* check for behind */
701          if (r->rod < 0.0)
641                return(1);
642                                                /* check for invisibility */
643        if (srcignore(m, r))
702                  return(1);
703                                                  /* check for outside spot */
704          if (m->otype==MAT_SPOT && spotout(r, makespot(m)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines