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.16 by greg, Tue Apr 25 19:51:38 1995 UTC vs.
Revision 2.20 by greg, Sat Dec 9 11:30:19 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1993 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "source.h"
20  
21 + #include  "random.h"
22 +
23 + extern double  ssampdist;               /* scatter sampling distance */
24 +
25   /*
26   * Structures used by direct()
27   */
# Line 131 | Line 135 | SRCINDEX  *si;                 /* source sample index */
135          sr->rsrc = si->sn;                      /* remember source */
136          srcp = source + si->sn;
137          if (srcp->sflags & SDISTANT) {
138 <                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s, 1))
138 >                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s))
139                          continue;
140                  return(1);              /* sample OK */
141          }
# Line 141 | Line 145 | SRCINDEX  *si;                 /* source sample index */
145                  continue;
146                                                  /* check angle */
147          if (srcp->sflags & SSPOT) {
148 <                if (spotout(sr, srcp->sl.s, 0))
148 >                if (spotout(sr, srcp->sl.s))
149                          continue;
150                                          /* adjust solid angle */
151                  si->dom *= d*d;
# Line 166 | Line 170 | register RAY  *r;
170                          return;
171                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
172                          goto nomat;
173 +                rayparticipate(r);
174                  return;
175          }
176                                          /* compute intersection */
# Line 175 | Line 180 | register RAY  *r;
180                          sp->sa.success++;
181                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
182                          goto nomat;
183 +                rayparticipate(r);
184                  return;
185          }
186                                          /* we missed our mark! */
# Line 329 | Line 335 | char  *p;                      /* data for f */
335                                                  /* follow entire path */
336                          if (!raycont(&sr))
337                                  objerror(sr.ro, USER, "material not found");
338 +                        rayparticipate(&sr);
339                          if (trace != NULL)
340                                  (*trace)(&sr);  /* trace execution */
341                          if (bright(sr.rcol) <= FTINY)
# Line 364 | Line 371 | char  *p;                      /* data for f */
371   }
372  
373  
374 + srcscatter(r)                   /* compute source scattering into ray */
375 + register RAY  *r;
376 + {
377 +        int  oldsampndx;
378 +        int  nsamps;
379 +        RAY  sr;
380 +        SRCINDEX  si;
381 +        double  t, lastt, d;
382 +        COLOR  cumval, ctmp;
383 +        int  i, j;
384 +
385 +        if (r->slights == NULL || r->slights[0] == 0 || r->gecc >= 1.-FTINY)
386 +                return;
387 +        if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
388 +                nsamps = 1;
389 +        oldsampndx = samplendx;
390 +        samplendx = random()&0x7fff;            /* randomize */
391 +        initsrcindex(&si);
392 +        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
393 +                setcolor(cumval, 0., 0., 0.);
394 +                lastt = r->rot;
395 +                for (j = nsamps; j-- > 0; ) {   /* for each sample position */
396 +                        samplendx++;
397 +                        t = r->rot * (j+frandom())/nsamps;
398 +                        sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
399 +                        sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
400 +                        sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
401 +                        sr.rmax = 0.;
402 +                                                /* sample ray to this source */
403 +                        if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) ||
404 +                                        sr.rsrc != r->slights[i]) {
405 +                                si.sn = r->slights[i]-1;        /* reset */
406 +                                si.np = 0;
407 +                                if (!srcray(&sr, NULL, &si) ||
408 +                                                sr.rsrc != r->slights[i])
409 +                                        continue;               /* no path */
410 +                        }
411 +                        copycolor(sr.cext, r->cext);
412 +                        sr.albedo = r->albedo;
413 +                        sr.gecc = r->gecc;
414 +                        rayvalue(&sr);                  /* eval. source ray */
415 +                        if (bright(sr.rcol) <= FTINY)
416 +                                continue;
417 +                                                        /* compute fall-off */
418 +                        d = lastt - t;
419 +                        setcolor(ctmp,  1.-d*colval(r->cext,RED),
420 +                                        1.-d*colval(r->cext,GRN),
421 +                                        1.-d*colval(r->cext,BLU));
422 +                        multcolor(cumval, ctmp);
423 +                        lastt = t;
424 +                        if (r->gecc <= FTINY)           /* compute P(theta) */
425 +                                d = 1.;
426 +                        else {
427 +                                d = DOT(r->rdir, sr.rdir);
428 +                                d = sqrt(1. + r->gecc*r->gecc - 2.*r->gecc*d);
429 +                                d = (1. - r->gecc*r->gecc) / (d*d*d);
430 +                        }
431 +                                                        /* other factors */
432 +                        d *= si.dom * r->albedo * r->rot / (4.*PI*nsamps);
433 +                        multcolor(sr.rcol, r->cext);
434 +                        scalecolor(sr.rcol, d);
435 +                        addcolor(cumval, sr.rcol);
436 +                }
437 +                                                /* final fall-off */
438 +                setcolor(ctmp,  1.-lastt*colval(r->cext,RED),
439 +                                1.-lastt*colval(r->cext,GRN),
440 +                                1.-lastt*colval(r->cext,BLU));
441 +                multcolor(cumval, ctmp);
442 +                addcolor(r->rcol, cumval);      /* sum into ray result */
443 +        }
444 +        samplendx = oldsampndx;
445 + }
446 +
447 +
448   /****************************************************************
449   * The following macros were separated from the m_light() routine
450   * because they are very nasty and difficult to understand.
# Line 405 | Line 486 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
486   * (Glows with negative radii should NEVER participate in illumination.)
487   */
488  
489 < #define  distglow(m, r)         (m->otype==MAT_GLOW && \
489 > #define  distglow(m, r, d)      (m->otype==MAT_GLOW && \
490                                  m->oargs.farg[3] >= -FTINY && \
491 <                                r->rot > m->oargs.farg[3])
491 >                                d > m->oargs.farg[3])
492  
493   /* badcomponent *
494   *
# Line 420 | Line 501 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
501  
502   #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
503                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
504 <                                        distglow(m, r)))
504 >                /* not 100% correct */  distglow(m, r, r->rot)))
505  
506   /* passillum *
507   *
# Line 438 | Line 519 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
519   * The -dv flag is normally on for sources to be visible.
520   */
521  
522 < #define  srcignore(m, r)        (!directvis && !(r->crtype&SHADOW) && \
523 <                                !distglow(m, r))
522 > #define  srcignore(m, r)        !(directvis || r->crtype&SHADOW || \
523 >                                distglow(m, r, raydist(r,PRIMARY)))
524  
525  
526   m_light(m, r)                   /* ray hit a light source */
# Line 449 | Line 530 | register RAY  *r;
530                                                  /* check for over-counting */
531          if (badcomponent(m, r))
532                  return(1);
533 <        if (wrongsource(m,r))
533 >        if (wrongsource(m, r))
534                  return(1);
535                                                  /* check for passed illum */
536          if (passillum(m, r)) {
# Line 466 | Line 547 | register RAY  *r;
547          if (srcignore(m, r))
548                  return(1);
549                                                  /* check for outside spot */
550 <        if (m->otype==MAT_SPOT && spotout(r, makespot(m), r->rot>=FHUGE))
550 >        if (m->otype==MAT_SPOT && spotout(r, makespot(m)))
551                  return(1);
552                                                  /* get distribution pattern */
553          raytexture(r, m->omod);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines