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.19 by greg, Fri Dec 8 18:22:28 1995 UTC vs.
Revision 2.28 by gwlarson, Mon Aug 10 18:37:56 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
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 223 | 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 333 | 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))
337 <                                objerror(sr.ro, USER, "material not found");
341 >                        raycont(&sr);
342                          rayparticipate(&sr);
343                          if (trace != NULL)
344                                  (*trace)(&sr);  /* trace execution */
# Line 374 | Line 378 | char  *p;                      /* data for f */
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;
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 || r->gecc >= 1.-FTINY)
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 <        initsrcindex(&si);
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 <                setcolor(cumval, 0., 0., 0.);
391 <                lastt = r->rot;
392 <                for (j = nsamps; j-- > 0; ) {   /* for each sample position */
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 <                                                /* sample ray to this source */
419 <                        if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) ||
420 <                                        sr.rsrc != r->slights[i]) {
421 <                                si.sn = r->slights[i]-1;        /* reset */
422 <                                si.np = 0;
423 <                                if (!srcray(&sr, NULL, &si) ||
405 <                                                sr.rsrc != r->slights[i])
406 <                                        continue;               /* no path */
407 <                        }
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 <                        sr.albedo = r->albedo;
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;
414                                                        /* compute fall-off */
415                        d = lastt - t;
416                        setcolor(ctmp,  1.-d*colval(r->cext,RED),
417                                        1.-d*colval(r->cext,GRN),
418                                        1.-d*colval(r->cext,BLU));
419                        multcolor(cumval, ctmp);
420                        lastt = t;
431                          if (r->gecc <= FTINY)           /* compute P(theta) */
432                                  d = 1.;
433                          else {
434                                  d = DOT(r->rdir, sr.rdir);
435 <                                d = sqrt(1. + r->gecc*r->gecc - 2.*r->gecc*d);
436 <                                d = (1. - r->gecc*r->gecc) / (d*d*d);
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->albedo * r->rot / (4.*PI*nsamps);
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 <                        addcolor(cumval, sr.rcol);
443 >                        multcolor(sr.rcol, cvext);
444 >                        addcolor(r->rcol, sr.rcol);     /* add it in */
445                  }
434                                                /* final fall-off */
435                setcolor(ctmp,  1.-lastt*colval(r->cext,RED),
436                                1.-lastt*colval(r->cext,GRN),
437                                1.-lastt*colval(r->cext,BLU));
438                multcolor(cumval, ctmp);
439                addcolor(r->rcol, cumval);      /* sum into ray result */
446          }
447 +        samplendx = oldsampndx;
448   }
449  
450  
# Line 531 | Line 538 | register RAY  *r;
538                                                  /* check for passed illum */
539          if (passillum(m, r)) {
540                  if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID))
541 <                        return(rayshade(r, modifier(m->oargs.sarg[0])));
541 >                        return(rayshade(r,lastmod(objndx(m),m->oargs.sarg[0])));
542                  raytrans(r);
543                  return(1);
544          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines