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.26 by gregl, Fri May 30 19:04:51 1997 UTC

# 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 333 | 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))
337 <                                objerror(sr.ro, USER, "material not found");
340 >                        raycont(&sr);
341                          rayparticipate(&sr);
342                          if (trace != NULL)
343                                  (*trace)(&sr);  /* trace execution */
# Line 374 | Line 377 | char  *p;                      /* data for f */
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, lastt, d;
385 <        COLOR  cumval, ctmp;
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 || r->gecc >= 1.-FTINY)
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 <        initsrcindex(&si);
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.);
391 <                lastt = r->rot;
392 <                for (j = nsamps; j-- > 0; ) {   /* for each sample position */
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 <                                                /* sample ray to this source */
418 <                        if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) ||
419 <                                        sr.rsrc != r->slights[i]) {
420 <                                si.sn = r->slights[i]-1;        /* reset */
421 <                                si.np = 0;
422 <                                if (!srcray(&sr, NULL, &si) ||
405 <                                                sr.rsrc != r->slights[i])
406 <                                        continue;               /* no path */
407 <                        }
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 <                        sr.albedo = r->albedo;
424 >                        copycolor(sr.albedo, r->albedo);
425                          sr.gecc = r->gecc;
426 +                        sr.slights = r->slights;
427                          rayvalue(&sr);                  /* eval. source ray */
428                          if (bright(sr.rcol) <= FTINY)
429                                  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;
430                          if (r->gecc <= FTINY)           /* compute P(theta) */
431                                  d = 1.;
432                          else {
433                                  d = DOT(r->rdir, sr.rdir);
434 <                                d = sqrt(1. + r->gecc*r->gecc - 2.*r->gecc*d);
435 <                                d = (1. - r->gecc*r->gecc) / (d*d*d);
434 >                                d = 1. + r->gecc*r->gecc - 2.*r->gecc*d;
435 >                                d = (1. - r->gecc*r->gecc) / (d*sqrt(d));
436                          }
437                                                          /* other factors */
438 <                        d *= si.dom * r->albedo * r->rot / (4.*PI*nsamps);
438 >                        d *= si.dom * r->rot / (4.*PI*nsamps);
439                          multcolor(sr.rcol, r->cext);
440 +                        multcolor(sr.rcol, r->albedo);
441                          scalecolor(sr.rcol, d);
442 <                        addcolor(cumval, sr.rcol);
442 >                        multcolor(sr.rcol, cvext);
443 >                        addcolor(r->rcol, sr.rcol);     /* add it in */
444                  }
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 */
445          }
446 +        samplendx = oldsampndx;
447   }
448  
449  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines