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.25 by greg, Tue May 28 13:41:41 1996 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 324 | Line 337 | char  *p;                      /* data for f */
337                                  ( sr.ro != source[scp->sno].so ||
338                                  source[scp->sno].sflags & SFOLLOW )) {
339                                                  /* follow entire path */
340 <                        if (!raycont(&sr))
341 <                                objerror(sr.ro, USER, "material not found");
340 >                        raycont(&sr);
341 >                        rayparticipate(&sr);
342                          if (trace != NULL)
343                                  (*trace)(&sr);  /* trace execution */
344                          if (bright(sr.rcol) <= FTINY)
# Line 361 | Line 374 | char  *p;                      /* data for f */
374   }
375  
376  
377 + srcscatter(r)                   /* compute source scattering into ray */
378 + register RAY  *r;
379 + {
380 +        int  oldsampndx;
381 +        int  nsamps;
382 +        RAY  sr;
383 +        SRCINDEX  si;
384 +        double  t, d;
385 +        double  re, ge, be;
386 +        COLOR  cvext;
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 +                for (j = 0; j < nsamps; j++) {  /* for each sample position */
402 +                        samplendx++;
403 +                        t = r->rot * (j+frandom())/nsamps;
404 +                                                        /* extinction */
405 +                        re = t*colval(r->cext,RED);
406 +                        ge = t*colval(r->cext,GRN);
407 +                        be = t*colval(r->cext,BLU);
408 +                        setcolor(cvext, re > 92. ? 0. : exp(-re),
409 +                                        ge > 92. ? 0. : exp(-ge),
410 +                                        be > 92. ? 0. : exp(-be));
411 +                        if (intens(cvext) <= FTINY)
412 +                                break;                  /* too far away */
413 +                        sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
414 +                        sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
415 +                        sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
416 +                        sr.rmax = 0.;
417 +                        initsrcindex(&si);      /* sample ray to this source */
418 +                        si.sn = r->slights[i];
419 +                        nopart(&si, &sr);
420 +                        if (!srcray(&sr, NULL, &si) ||
421 +                                        sr.rsrc != r->slights[i])
422 +                                continue;               /* no path */
423 +                        copycolor(sr.cext, r->cext);
424 +                        copycolor(sr.albedo, r->albedo);
425 +                        sr.gecc = r->gecc;
426 +                        rayvalue(&sr);                  /* eval. source ray */
427 +                        if (bright(sr.rcol) <= FTINY)
428 +                                continue;
429 +                        if (r->gecc <= FTINY)           /* compute P(theta) */
430 +                                d = 1.;
431 +                        else {
432 +                                d = DOT(r->rdir, sr.rdir);
433 +                                d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
434 +                                d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
435 +                        }
436 +                                                        /* other factors */
437 +                        d *= si.dom * r->rot / (4.*PI*nsamps);
438 +                        multcolor(sr.rcol, r->cext);
439 +                        multcolor(sr.rcol, r->albedo);
440 +                        scalecolor(sr.rcol, d);
441 +                        multcolor(sr.rcol, cvext);
442 +                        addcolor(r->rcol, sr.rcol);     /* add it in */
443 +                }
444 +        }
445 +        samplendx = oldsampndx;
446 + }
447 +
448 +
449   /****************************************************************
450   * The following macros were separated from the m_light() routine
451   * because they are very nasty and difficult to understand.
# Line 402 | Line 487 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
487   * (Glows with negative radii should NEVER participate in illumination.)
488   */
489  
490 < #define  distglow(m, r)         (m->otype==MAT_GLOW && \
490 > #define  distglow(m, r, d)      (m->otype==MAT_GLOW && \
491                                  m->oargs.farg[3] >= -FTINY && \
492 <                                r->rot > m->oargs.farg[3])
492 >                                d > m->oargs.farg[3])
493  
494   /* badcomponent *
495   *
# Line 417 | Line 502 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
502  
503   #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
504                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
505 <                                        distglow(m, r)))
505 >                /* not 100% correct */  distglow(m, r, r->rot)))
506  
507   /* passillum *
508   *
# Line 435 | Line 520 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
520   * The -dv flag is normally on for sources to be visible.
521   */
522  
523 < #define  srcignore(m, r)        (!directvis && !(r->crtype&SHADOW) && \
524 <                                !distglow(m, r))
523 > #define  srcignore(m, r)        !(directvis || r->crtype&SHADOW || \
524 >                                distglow(m, r, raydist(r,PRIMARY)))
525  
526  
527   m_light(m, r)                   /* ray hit a light source */
# Line 446 | Line 531 | register RAY  *r;
531                                                  /* check for over-counting */
532          if (badcomponent(m, r))
533                  return(1);
534 <        if (wrongsource(m,r))
534 >        if (wrongsource(m, r))
535                  return(1);
536                                                  /* check for passed illum */
537          if (passillum(m, r)) {
# Line 463 | Line 548 | register RAY  *r;
548          if (srcignore(m, r))
549                  return(1);
550                                                  /* check for outside spot */
551 <        if (m->otype==MAT_SPOT && spotout(r, makespot(m), r->rot>=FHUGE))
551 >        if (m->otype==MAT_SPOT && spotout(r, makespot(m)))
552                  return(1);
553                                                  /* get distribution pattern */
554          raytexture(r, m->omod);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines