ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
(Generate patch)

Comparing ray/src/rt/raytrace.c (file contents):
Revision 2.47 by greg, Thu Apr 14 18:04:12 2005 UTC vs.
Revision 2.50 by greg, Thu May 26 06:55:22 2005 UTC

# Line 36 | Line 36 | static void checkset(OBJECT  *os, OBJECT  *cs);
36  
37   extern int
38   rayorigin(              /* start new ray from old one */
39 <        register RAY  *r,
40 <        register RAY  *ro,
39 >        RAY  *r,
40          int  rt,
41 <        double  rw
41 >        const RAY  *ro,
42 >        const COLOR rc
43   )
44   {
45 <        double  re;
46 <
45 >        double  rw, re;
46 >                                                /* assign coefficient/weight */
47 >        if (rc == NULL) {
48 >                rw = 1.0;
49 >                setcolor(r->rcoef, 1., 1., 1.);
50 >        } else {
51 >                rw = intens(rc);
52 >                if (rc != r->rcoef)
53 >                        copycolor(r->rcoef, rc);
54 >        }
55          if ((r->parent = ro) == NULL) {         /* primary ray */
56                  r->rlvl = 0;
57                  r->rweight = rw;
# Line 55 | Line 63 | rayorigin(             /* start new ray from old one */
63                  copycolor(r->albedo, salbedo);
64                  r->gecc = seccg;
65                  r->slights = NULL;
58        } else if (ro->rot >= FHUGE) {          /* illegal continuation */
59                memset(r, 0, sizeof(RAY));
60                return(-1);
66          } else {                                /* spawned ray */
67 +                if (ro->rot >= FHUGE) {
68 +                        memset(r, 0, sizeof(RAY));
69 +                        return(-1);             /* illegal continuation */
70 +                }
71                  r->rlvl = ro->rlvl;
72                  if (rt & RAYREFL) {
73                          r->rlvl++;
# Line 78 | Line 87 | rayorigin(             /* start new ray from old one */
87                  r->crtype = ro->crtype | (r->rtype = rt);
88                  VCOPY(r->rorg, ro->rop);
89                  r->rweight = ro->rweight * rw;
90 <                                                /* estimate absorption */
90 >                                                /* estimate extinction */
91                  re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
92                                  colval(ro->cext,RED) : colval(ro->cext,GRN);
93                  if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
94 <                if (re > 0.)
95 <                        r->rweight *= exp(-re*ro->rot);
94 >                re *= ro->rot;
95 >                if (re > .1)
96 >                        r->rweight *= exp(-re);
97          }
98          rayclear(r);
99          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
# Line 122 | Line 132 | raytrace(                      /* trace a ray and compute its value */
132          } else if (sourcehit(r))
133                  rayshade(r, r->ro->omod);       /* distant source */
134  
125        rayparticipate(r);              /* for participating medium */
126
135          if (trace != NULL)
136                  (*trace)(r);            /* trace execution */
137 +
138 +        rayparticipate(r);              /* for participating medium */
139   }
140  
141  
# Line 147 | Line 157 | raytrans(                      /* transmit ray as is */
157   {
158          RAY  tr;
159  
160 <        if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
160 >        if (rayorigin(&tr, TRANS, r, NULL) == 0) {
161                  VCOPY(tr.rdir, r->rdir);
162                  rayvalue(&tr);
163                  copycolor(r->rcol, tr.rcol);
# Line 209 | Line 219 | rayparticipate(                        /* compute ray medium participation
219                  ge *= 1. - colval(r->albedo,GRN);
220                  be *= 1. - colval(r->albedo,BLU);
221          }
222 <        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
223 <                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
224 <                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
225 <        multcolor(r->rcol, ce);                 /* path absorption */
222 >        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
223 >                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
224 >                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
225 >        multcolor(r->rcol, ce);                 /* path extinction */
226          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
227                  return;                         /* no scattering */
228          setcolor(ca,
# Line 305 | Line 315 | raymixture(            /* mix modifiers */
315  
316   extern double
317   raydist(                /* compute (cumulative) ray distance */
318 <        register RAY  *r,
318 >        register const RAY  *r,
319          register int  flags
320   )
321   {
# Line 319 | Line 329 | raydist(               /* compute (cumulative) ray distance */
329   }
330  
331  
332 + extern void
333 + raycontrib(             /* compute (cumulative) ray contribution */
334 +        COLOR  rc,
335 +        const RAY  *r,
336 +        int  flags
337 + )
338 + {
339 +        COLOR   eext, ext1;
340 +        
341 +        setcolor(eext, 0., 0., 0.);
342 +        setcolor(rc, 1., 1., 1.);
343 +
344 +        while (r != NULL && r->crtype&flags) {
345 +                multcolor(rc, r->rcoef);
346 +                copycolor(ext1, r->cext);
347 +                scalecolor(ext1, r->rot);
348 +                addcolor(eext, ext1);
349 +                r = r->parent;
350 +        }
351 +        if (intens(eext) > FTINY) {
352 +                setcolor(ext1,  exp(-colval(eext,RED)),
353 +                                exp(-colval(eext,GRN)),
354 +                                exp(-colval(eext,BLU)));
355 +                multcolor(rc, ext1);
356 +        }
357 + }
358 +
359 +
360   extern double
361   raynormal(              /* compute perturbed normal for ray */
362          FVECT  norm,
# Line 365 | Line 403 | newrayxf(                      /* get new tranformation matrix for ray */
403                  FULLXF  xf;
404          }  xfseed = { &xfseed }, *xflast = &xfseed;
405          register struct xfn  *xp;
406 <        register RAY  *rp;
406 >        register const RAY  *rp;
407  
408          /*
409           * Search for transform in circular list that

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines