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.15 by greg, Thu Jan 13 10:43:36 1994 UTC vs.
Revision 2.22 by greg, Sun Dec 17 11:51:49 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 + #ifndef MAXSSAMP
26 + #define MAXSSAMP        16              /* maximum samples per ray */
27 + #endif
28 +
29   /*
30   * Structures used by direct()
31   */
# Line 68 | Line 76 | marksources()                  /* find and mark source objects */
76                                  o->otype != OBJ_SOURCE &&
77                                  m->oargs.farg[3] <= FTINY)
78                          continue;                       /* don't bother */
79 +                if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY &&
80 +                                m->oargs.farg[2] <= FTINY)
81 +                        continue;                       /* don't bother */
82  
83                  if (sfun[o->otype].of == NULL ||
84                                  sfun[o->otype].of->setsrc == NULL)
# Line 128 | Line 139 | SRCINDEX  *si;                 /* source sample index */
139          sr->rsrc = si->sn;                      /* remember source */
140          srcp = source + si->sn;
141          if (srcp->sflags & SDISTANT) {
142 <                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s, 1))
142 >                if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s))
143                          continue;
144                  return(1);              /* sample OK */
145          }
# Line 138 | Line 149 | SRCINDEX  *si;                 /* source sample index */
149                  continue;
150                                                  /* check angle */
151          if (srcp->sflags & SSPOT) {
152 <                if (spotout(sr, srcp->sl.s, 0))
152 >                if (spotout(sr, srcp->sl.s))
153                          continue;
154                                          /* adjust solid angle */
155                  si->dom *= d*d;
# Line 163 | Line 174 | register RAY  *r;
174                          return;
175                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
176                          goto nomat;
177 +                rayparticipate(r);
178                  return;
179          }
180                                          /* compute intersection */
# Line 172 | Line 184 | register RAY  *r;
184                          sp->sa.success++;
185                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
186                          goto nomat;
187 +                rayparticipate(r);
188                  return;
189          }
190                                          /* we missed our mark! */
# Line 326 | Line 339 | char  *p;                      /* data for f */
339                                                  /* follow entire path */
340                          if (!raycont(&sr))
341                                  objerror(sr.ro, USER, "material not found");
342 +                        rayparticipate(&sr);
343                          if (trace != NULL)
344                                  (*trace)(&sr);  /* trace execution */
345                          if (bright(sr.rcol) <= FTINY)
# Line 361 | Line 375 | char  *p;                      /* data for f */
375   }
376  
377  
378 + srcscatter(r)                   /* compute source scattering into ray */
379 + register RAY  *r;
380 + {
381 +        int  oldsampndx;
382 +        int  nsamps;
383 +        RAY  sr;
384 +        SRCINDEX  si;
385 +        double  t, lastt, d;
386 +        COLOR  cumval, ctmp;
387 +        int  i, j;
388 +
389 +        if (r->slights == NULL || r->slights[0] == 0
390 +                        || r->gecc >= 1.-FTINY || r->rot >= FHUGE)
391 +                return;
392 +        if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
393 +                nsamps = 1;
394 + #if MAXSSAMP
395 +        else if (nsamps > MAXSSAMP)
396 +                nsamps = MAXSSAMP;
397 + #endif
398 +        oldsampndx = samplendx;
399 +        samplendx = random()&0x7fff;            /* randomize */
400 +        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
401 +                setcolor(cumval, 0., 0., 0.);
402 +                lastt = r->rot;
403 +                for (j = nsamps; j-- > 0; ) {   /* for each sample position */
404 +                        samplendx++;
405 +                        t = r->rot * (j+frandom())/nsamps;
406 +                        sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
407 +                        sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
408 +                        sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
409 +                        sr.rmax = 0.;
410 +                        initsrcindex(&si);      /* sample ray to this source */
411 +                        si.sn = r->slights[i];
412 +                        nopart(&si, &sr);
413 +                        if (!srcray(&sr, NULL, &si) ||
414 +                                        sr.rsrc != r->slights[i])
415 +                                continue;               /* no path */
416 +                        copycolor(sr.cext, r->cext);
417 +                        sr.albedo = r->albedo;
418 +                        sr.gecc = r->gecc;
419 +                        rayvalue(&sr);                  /* eval. source ray */
420 +                        if (bright(sr.rcol) <= FTINY)
421 +                                continue;
422 +                                                        /* compute fall-off */
423 +                        d = lastt - t;
424 +                        setcolor(ctmp,  1.-d*colval(r->cext,RED),
425 +                                        1.-d*colval(r->cext,GRN),
426 +                                        1.-d*colval(r->cext,BLU));
427 +                        multcolor(cumval, ctmp);
428 +                        lastt = t;
429 +                        if (r->gecc <= FTINY)           /* compute P(theta) */
430 +                                d = 1.;
431 +                        else {
432 +                                d = DOT(r->rdir, sr.rdir);
433 +                                d = sqrt(1. + r->gecc*r->gecc - 2.*r->gecc*d);
434 +                                d = (1. - r->gecc*r->gecc) / (d*d*d);
435 +                        }
436 +                                                        /* other factors */
437 +                        d *= si.dom * r->albedo * r->rot / (4.*PI*nsamps);
438 +                        multcolor(sr.rcol, r->cext);
439 +                        scalecolor(sr.rcol, d);
440 +                        addcolor(cumval, sr.rcol);
441 +                }
442 +                                                /* final fall-off */
443 +                setcolor(ctmp,  1.-lastt*colval(r->cext,RED),
444 +                                1.-lastt*colval(r->cext,GRN),
445 +                                1.-lastt*colval(r->cext,BLU));
446 +                multcolor(cumval, ctmp);
447 +                addcolor(r->rcol, cumval);      /* sum into ray result */
448 +        }
449 +        samplendx = oldsampndx;
450 + }
451 +
452 +
453   /****************************************************************
454   * The following macros were separated from the m_light() routine
455   * because they are very nasty and difficult to understand.
# Line 402 | Line 491 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
491   * (Glows with negative radii should NEVER participate in illumination.)
492   */
493  
494 < #define  distglow(m, r)         (m->otype==MAT_GLOW && \
494 > #define  distglow(m, r, d)      (m->otype==MAT_GLOW && \
495                                  m->oargs.farg[3] >= -FTINY && \
496 <                                r->rot > m->oargs.farg[3])
496 >                                d > m->oargs.farg[3])
497  
498   /* badcomponent *
499   *
# Line 417 | Line 506 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
506  
507   #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
508                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
509 <                                        distglow(m, r)))
509 >                /* not 100% correct */  distglow(m, r, r->rot)))
510  
511   /* passillum *
512   *
# Line 435 | Line 524 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
524   * The -dv flag is normally on for sources to be visible.
525   */
526  
527 < #define  srcignore(m, r)        (!directvis && !(r->crtype&SHADOW) && \
528 <                                !distglow(m, r))
527 > #define  srcignore(m, r)        !(directvis || r->crtype&SHADOW || \
528 >                                distglow(m, r, raydist(r,PRIMARY)))
529  
530  
531   m_light(m, r)                   /* ray hit a light source */
# Line 446 | Line 535 | register RAY  *r;
535                                                  /* check for over-counting */
536          if (badcomponent(m, r))
537                  return(1);
538 <        if (wrongsource(m,r))
538 >        if (wrongsource(m, r))
539                  return(1);
540                                                  /* check for passed illum */
541          if (passillum(m, r)) {
# Line 463 | Line 552 | register RAY  *r;
552          if (srcignore(m, r))
553                  return(1);
554                                                  /* check for outside spot */
555 <        if (m->otype==MAT_SPOT && spotout(r, makespot(m), r->rot>=FHUGE))
555 >        if (m->otype==MAT_SPOT && spotout(r, makespot(m)))
556                  return(1);
557                                                  /* get distribution pattern */
558          raytexture(r, m->omod);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines