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.48 by greg, Fri Apr 15 04:44:51 2005 UTC vs.
Revision 2.53 by greg, Thu Jun 23 09:11:38 2005 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include  "source.h"
14   #include  "otypes.h"
15   #include  "otspecial.h"
16 + #include  "random.h"
17  
18   #define  MAXCSET        ((MAXSET+1)*2-1)        /* maximum check set size */
19  
# Line 36 | Line 37 | static void checkset(OBJECT  *os, OBJECT  *cs);
37  
38   extern int
39   rayorigin(              /* start new ray from old one */
40 <        register RAY  *r,
40 <        register RAY  *ro,
40 >        RAY  *r,
41          int  rt,
42 <        double  rw
42 >        const RAY  *ro,
43 >        const COLOR rc
44   )
45   {
46 <        double  re;
47 <
46 >        double  rw, re;
47 >                                                /* assign coefficient/weight */
48 >        if (rc == NULL) {
49 >                rw = 1.0;
50 >                setcolor(r->rcoef, 1., 1., 1.);
51 >        } else {
52 >                rw = intens(rc);
53 >                if (rc != r->rcoef)
54 >                        copycolor(r->rcoef, rc);
55 >        }
56          if ((r->parent = ro) == NULL) {         /* primary ray */
57                  r->rlvl = 0;
58                  r->rweight = rw;
59                  r->crtype = r->rtype = rt;
60                  r->rsrc = -1;
61                  r->clipset = NULL;
62 +                r->revf = raytrace;
63                  copycolor(r->cext, cextinction);
64                  copycolor(r->albedo, salbedo);
65                  r->gecc = seccg;
66                  r->slights = NULL;
57        } else if (ro->rot >= FHUGE) {          /* illegal continuation */
58                memset(r, 0, sizeof(RAY));
59                return(-1);
67          } else {                                /* spawned ray */
68 +                if (ro->rot >= FHUGE) {
69 +                        memset(r, 0, sizeof(RAY));
70 +                        return(-1);             /* illegal continuation */
71 +                }
72                  r->rlvl = ro->rlvl;
73                  if (rt & RAYREFL) {
74                          r->rlvl++;
# Line 69 | Line 80 | rayorigin(             /* start new ray from old one */
80                          r->clipset = ro->newcset;
81                          r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
82                  }
83 +                r->revf = ro->revf;
84                  copycolor(r->cext, ro->cext);
85                  copycolor(r->albedo, ro->albedo);
86                  r->gecc = ro->gecc;
# Line 76 | Line 88 | rayorigin(             /* start new ray from old one */
88                  r->crtype = ro->crtype | (r->rtype = rt);
89                  VCOPY(r->rorg, ro->rop);
90                  r->rweight = ro->rweight * rw;
91 <                                                /* estimate absorption */
91 >                                                /* estimate extinction */
92                  re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
93                                  colval(ro->cext,RED) : colval(ro->cext,GRN);
94                  if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
95 <                if (re > 0.)
96 <                        r->rweight *= exp(-re*ro->rot);
95 >                re *= ro->rot;
96 >                if (re > 0.1)
97 >                        if (re > 92.)
98 >                                r->rweight = 0.0;
99 >                        else
100 >                                r->rweight *= exp(-re);
101          }
102          rayclear(r);
103 +        if (r->rweight <= 0.0)                  /* check for expiration */
104 +                return(-1);
105 +        if (r->crtype & SHADOW)                 /* shadow commitment */
106 +                return(0);
107 +        if (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
108 +                if (minweight <= 0.0)
109 +                        error(USER, "zero ray weight in Russian roulette");
110 +                if (maxdepth < 0 && r->rlvl > -maxdepth)
111 +                        return(-1);             /* upper reflection limit */
112 +                if (r->rweight >= minweight)
113 +                        return(0);
114 +                if (frandom() < r->rweight/minweight)
115 +                        return(-1);
116 +                rw = minweight/r->rweight;      /* promote survivor */
117 +                scalecolor(r->rcoef, rw);
118 +                r->rweight = minweight;
119 +                return(0);
120 +        }
121          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
122   }
123  
# Line 108 | Line 142 | rayclear(                      /* clear a ray for (re)evaluation */
142  
143  
144   extern void
145 < rayvalue(                       /* trace a ray and compute its value */
145 > raytrace(                       /* trace a ray and compute its value */
146          RAY  *r
147   )
148   {
# Line 120 | Line 154 | rayvalue(                      /* trace a ray and compute its value */
154          } else if (sourcehit(r))
155                  rayshade(r, r->ro->omod);       /* distant source */
156  
123        rayparticipate(r);              /* for participating medium */
124
157          if (trace != NULL)
158                  (*trace)(r);            /* trace execution */
159 +
160 +        rayparticipate(r);              /* for participating medium */
161   }
162  
163  
# Line 145 | Line 179 | raytrans(                      /* transmit ray as is */
179   {
180          RAY  tr;
181  
182 <        if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
182 >        if (rayorigin(&tr, TRANS, r, NULL) == 0) {
183                  VCOPY(tr.rdir, r->rdir);
184                  rayvalue(&tr);
185                  copycolor(r->rcol, tr.rcol);
# Line 207 | Line 241 | rayparticipate(                        /* compute ray medium participation
241                  ge *= 1. - colval(r->albedo,GRN);
242                  be *= 1. - colval(r->albedo,BLU);
243          }
244 <        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
245 <                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
246 <                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
247 <        multcolor(r->rcol, ce);                 /* path absorption */
244 >        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
245 >                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
246 >                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
247 >        multcolor(r->rcol, ce);                 /* path extinction */
248          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
249                  return;                         /* no scattering */
250          setcolor(ca,
# Line 303 | Line 337 | raymixture(            /* mix modifiers */
337  
338   extern double
339   raydist(                /* compute (cumulative) ray distance */
340 <        register RAY  *r,
340 >        register const RAY  *r,
341          register int  flags
342   )
343   {
# Line 317 | Line 351 | raydist(               /* compute (cumulative) ray distance */
351   }
352  
353  
354 + extern void
355 + raycontrib(             /* compute (cumulative) ray contribution */
356 +        double  rc[3],
357 +        const RAY  *r,
358 +        int  flags
359 + )
360 + {
361 +        double  eext[3];
362 +        int     i;
363 +
364 +        eext[0] = eext[1] = eext[2] = 0.;
365 +        rc[0] = rc[1] = rc[2] = 1.;
366 +
367 +        while (r != NULL && r->crtype&flags) {
368 +                for (i = 3; i--; ) {
369 +                        rc[i] *= colval(r->rcoef,i);
370 +                        eext[i] += r->rot * colval(r->cext,i);
371 +                }
372 +                r = r->parent;
373 +        }
374 +        for (i = 3; i--; )
375 +                rc[i] *= (eext[i] <= FTINY) ? 1. :
376 +                                (eext[i] > 92.) ? 0. : exp(-eext[i]);
377 + }
378 +
379 +
380   extern double
381   raynormal(              /* compute perturbed normal for ray */
382          FVECT  norm,
# Line 363 | Line 423 | newrayxf(                      /* get new tranformation matrix for ray */
423                  FULLXF  xf;
424          }  xfseed = { &xfseed }, *xflast = &xfseed;
425          register struct xfn  *xp;
426 <        register RAY  *rp;
426 >        register const RAY  *rp;
427  
428          /*
429           * Search for transform in circular list that

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines