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.18 by greg, Tue Nov 7 12:40:32 1995 UTC vs.
Revision 2.19 by greg, Fri Dec 8 18:22:28 1995 UTC

# 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   /*
26   * Structures used by direct()
27   */
# Line 166 | Line 170 | register RAY  *r;
170                          return;
171                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
172                          goto nomat;
173 +                rayparticipate(r);
174                  return;
175          }
176                                          /* compute intersection */
# Line 175 | Line 180 | register RAY  *r;
180                          sp->sa.success++;
181                  if (!rayshade(r, r->ro->omod))  /* compute contribution */
182                          goto nomat;
183 +                rayparticipate(r);
184                  return;
185          }
186                                          /* we missed our mark! */
# Line 329 | Line 335 | char  *p;                      /* data for f */
335                                                  /* follow entire path */
336                          if (!raycont(&sr))
337                                  objerror(sr.ro, USER, "material not found");
338 +                        rayparticipate(&sr);
339                          if (trace != NULL)
340                                  (*trace)(&sr);  /* trace execution */
341                          if (bright(sr.rcol) <= FTINY)
# Line 360 | Line 367 | char  *p;                      /* data for f */
367                          prob = 1.0;
368                  scalecolor(scp->val, prob);
369                  addcolor(r->rcol, scp->val);
370 +        }
371 + }
372 +
373 +
374 + srcscatter(r)                   /* compute source scattering into ray */
375 + register RAY  *r;
376 + {
377 +        int  nsamps;
378 +        RAY  sr;
379 +        SRCINDEX  si;
380 +        double  t, lastt, d;
381 +        COLOR  cumval, ctmp;
382 +        int  i, j;
383 +
384 +        if (r->slights == NULL || r->slights[0] == 0 || r->gecc >= 1.-FTINY)
385 +                return;
386 +        if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1)
387 +                nsamps = 1;
388 +        initsrcindex(&si);
389 +        for (i = r->slights[0]; i > 0; i--) {   /* for each source */
390 +                setcolor(cumval, 0., 0., 0.);
391 +                lastt = r->rot;
392 +                for (j = nsamps; j-- > 0; ) {   /* for each sample position */
393 +                        samplendx++;
394 +                        t = r->rot * (j+frandom())/nsamps;
395 +                        sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
396 +                        sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
397 +                        sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;
398 +                        sr.rmax = 0.;
399 +                                                /* sample ray to this source */
400 +                        if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) ||
401 +                                        sr.rsrc != r->slights[i]) {
402 +                                si.sn = r->slights[i]-1;        /* reset */
403 +                                si.np = 0;
404 +                                if (!srcray(&sr, NULL, &si) ||
405 +                                                sr.rsrc != r->slights[i])
406 +                                        continue;               /* no path */
407 +                        }
408 +                        copycolor(sr.cext, r->cext);
409 +                        sr.albedo = r->albedo;
410 +                        sr.gecc = r->gecc;
411 +                        rayvalue(&sr);                  /* eval. source ray */
412 +                        if (bright(sr.rcol) <= FTINY)
413 +                                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;
421 +                        if (r->gecc <= FTINY)           /* compute P(theta) */
422 +                                d = 1.;
423 +                        else {
424 +                                d = DOT(r->rdir, sr.rdir);
425 +                                d = sqrt(1. + r->gecc*r->gecc - 2.*r->gecc*d);
426 +                                d = (1. - r->gecc*r->gecc) / (d*d*d);
427 +                        }
428 +                                                        /* other factors */
429 +                        d *= si.dom * r->albedo * r->rot / (4.*PI*nsamps);
430 +                        multcolor(sr.rcol, r->cext);
431 +                        scalecolor(sr.rcol, d);
432 +                        addcolor(cumval, sr.rcol);
433 +                }
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 */
440          }
441   }
442  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines