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.27 by gregl, Fri Aug 15 10:24:24 1997 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 131 | 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 141 | 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 166 | 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 175 | 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 217 | Line 227 | register RAY  *r;
227                          }
228  
229          if (r->ro != NULL) {
230 +                r->robj = objndx(r->ro);
231                  for (i = 0; i < 3; i++)
232                          r->ron[i] = -r->rdir[i];
233                  r->rod = 1.0;
# Line 327 | Line 338 | char  *p;                      /* data for f */
338                                  ( sr.ro != source[scp->sno].so ||
339                                  source[scp->sno].sflags & SFOLLOW )) {
340                                                  /* follow entire path */
341 <                        if (!raycont(&sr))
342 <                                objerror(sr.ro, USER, "material not found");
341 >                        raycont(&sr);
342 >                        rayparticipate(&sr);
343                          if (trace != NULL)
344                                  (*trace)(&sr);  /* trace execution */
345                          if (bright(sr.rcol) <= FTINY)
# Line 364 | 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, d;
386 +        double  re, ge, be;
387 +        COLOR  cvext;
388 +        int  i, j;
389 +
390 +        if (r->slights == NULL || r->slights[0] == 0
391 +                        || r->gecc >= 1.-FTINY || r->rot >= FHUGE)
392 +                return;
393 +        if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
394 +                nsamps = 1;
395 + #if MAXSSAMP
396 +        else if (nsamps > MAXSSAMP)
397 +                nsamps = MAXSSAMP;
398 + #endif
399 +        oldsampndx = samplendx;
400 +        samplendx = random()&0x7fff;            /* randomize */
401 +        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
402 +                for (j = 0; j < nsamps; j++) {  /* for each sample position */
403 +                        samplendx++;
404 +                        t = r->rot * (j+frandom())/nsamps;
405 +                                                        /* extinction */
406 +                        re = t*colval(r->cext,RED);
407 +                        ge = t*colval(r->cext,GRN);
408 +                        be = t*colval(r->cext,BLU);
409 +                        setcolor(cvext, re > 92. ? 0. : exp(-re),
410 +                                        ge > 92. ? 0. : exp(-ge),
411 +                                        be > 92. ? 0. : exp(-be));
412 +                        if (intens(cvext) <= FTINY)
413 +                                break;                  /* too far away */
414 +                        sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
415 +                        sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
416 +                        sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
417 +                        sr.rmax = 0.;
418 +                        initsrcindex(&si);      /* sample ray to this source */
419 +                        si.sn = r->slights[i];
420 +                        nopart(&si, &sr);
421 +                        if (!srcray(&sr, NULL, &si) ||
422 +                                        sr.rsrc != r->slights[i])
423 +                                continue;               /* no path */
424 +                        copycolor(sr.cext, r->cext);
425 +                        copycolor(sr.albedo, r->albedo);
426 +                        sr.gecc = r->gecc;
427 +                        sr.slights = r->slights;
428 +                        rayvalue(&sr);                  /* eval. source ray */
429 +                        if (bright(sr.rcol) <= FTINY)
430 +                                continue;
431 +                        if (r->gecc <= FTINY)           /* compute P(theta) */
432 +                                d = 1.;
433 +                        else {
434 +                                d = DOT(r->rdir, sr.rdir);
435 +                                d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
436 +                                d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
437 +                        }
438 +                                                        /* other factors */
439 +                        d *= si.dom * r->rot / (4.*PI*nsamps);
440 +                        multcolor(sr.rcol, r->cext);
441 +                        multcolor(sr.rcol, r->albedo);
442 +                        scalecolor(sr.rcol, d);
443 +                        multcolor(sr.rcol, cvext);
444 +                        addcolor(r->rcol, sr.rcol);     /* add it in */
445 +                }
446 +        }
447 +        samplendx = oldsampndx;
448 + }
449 +
450 +
451   /****************************************************************
452   * The following macros were separated from the m_light() routine
453   * because they are very nasty and difficult to understand.
# Line 405 | Line 489 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
489   * (Glows with negative radii should NEVER participate in illumination.)
490   */
491  
492 < #define  distglow(m, r)         (m->otype==MAT_GLOW && \
492 > #define  distglow(m, r, d)      (m->otype==MAT_GLOW && \
493                                  m->oargs.farg[3] >= -FTINY && \
494 <                                r->rot > m->oargs.farg[3])
494 >                                d > m->oargs.farg[3])
495  
496   /* badcomponent *
497   *
# Line 420 | Line 504 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
504  
505   #define  badcomponent(m, r)     (r->crtype&(AMBIENT|SPECULAR) && \
506                                  !(r->crtype&SHADOW || r->rod < 0.0 || \
507 <                                        distglow(m, r)))
507 >                /* not 100% correct */  distglow(m, r, r->rot)))
508  
509   /* passillum *
510   *
# Line 438 | Line 522 | return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);}
522   * The -dv flag is normally on for sources to be visible.
523   */
524  
525 < #define  srcignore(m, r)        (!directvis && !(r->crtype&SHADOW) && \
526 <                                !distglow(m, r))
525 > #define  srcignore(m, r)        !(directvis || r->crtype&SHADOW || \
526 >                                distglow(m, r, raydist(r,PRIMARY)))
527  
528  
529   m_light(m, r)                   /* ray hit a light source */
# Line 449 | Line 533 | register RAY  *r;
533                                                  /* check for over-counting */
534          if (badcomponent(m, r))
535                  return(1);
536 <        if (wrongsource(m,r))
536 >        if (wrongsource(m, r))
537                  return(1);
538                                                  /* check for passed illum */
539          if (passillum(m, r)) {
# Line 466 | Line 550 | register RAY  *r;
550          if (srcignore(m, r))
551                  return(1);
552                                                  /* check for outside spot */
553 <        if (m->otype==MAT_SPOT && spotout(r, makespot(m), r->rot>=FHUGE))
553 >        if (m->otype==MAT_SPOT && spotout(r, makespot(m)))
554                  return(1);
555                                                  /* get distribution pattern */
556          raytexture(r, m->omod);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines