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.45 by schorsch, Tue Mar 30 16:13:01 2004 UTC vs.
Revision 2.55 by greg, Sat Jul 30 16:41:46 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;
# Line 56 | Line 65 | rayorigin(             /* start new ray from old one */
65                  r->gecc = seccg;
66                  r->slights = NULL;
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 75 | 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 119 | Line 154 | raytrace(                      /* trace a ray and compute its value */
154          } else if (sourcehit(r))
155                  rayshade(r, r->ro->omod);       /* distant source */
156  
122        rayparticipate(r);              /* for participating medium */
123
157          if (trace != NULL)
158                  (*trace)(r);            /* trace execution */
159 +
160 +        rayparticipate(r);              /* for participating medium */
161   }
162  
163  
# Line 144 | 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 159 | Line 194 | rayshade(              /* shade ray r with material mod */
194          int  mod
195   )
196   {
162        int  gotmat;
197          register OBJREC  *m;
198 +
199          r->rt = r->rot;                 /* set effective ray length */
200 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
200 >        for ( ; mod != OVOID; mod = m->omod) {
201                  m = objptr(mod);
202                  /****** unnecessary test since modifier() is always called
203                  if (!ismodifier(m->otype)) {
# Line 181 | Line 216 | rayshade(              /* shade ray r with material mod */
216                          if (!islight(m->otype))
217                                  m = &Lamb;
218                  }
219 <                                        /* materials call raytexture */
220 <                gotmat = (*ofun[m->otype].funp)(m, r);
219 >                if ((*ofun[m->otype].funp)(m, r))
220 >                        return(1);      /* materials call raytexture() */
221          }
222 <        return(gotmat);
222 >        return(0);                      /* no material! */
223   }
224  
225  
# Line 206 | 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 266 | Line 301 | raymixture(            /* mix modifiers */
301          foremat = backmat = 0;
302                                          /* foreground */
303          fr = *r;
304 <        if (coef > FTINY)
304 >        if (coef > FTINY) {
305 >                scalecolor(fr.rcoef, coef);
306                  foremat = rayshade(&fr, fore);
307 +        }
308                                          /* background */
309          br = *r;
310 <        if (coef < 1.0-FTINY)
310 >        if (coef < 1.0-FTINY) {
311 >                scalecolor(br.rcoef, 1.0-coef);
312                  backmat = rayshade(&br, back);
313 +        }
314                                          /* check for transparency */
315          if (backmat ^ foremat) {
316                  if (backmat && coef > FTINY)
# Line 302 | Line 341 | raymixture(            /* mix modifiers */
341  
342   extern double
343   raydist(                /* compute (cumulative) ray distance */
344 <        register RAY  *r,
344 >        register const RAY  *r,
345          register int  flags
346   )
347   {
# Line 316 | Line 355 | raydist(               /* compute (cumulative) ray distance */
355   }
356  
357  
358 + extern void
359 + raycontrib(             /* compute (cumulative) ray contribution */
360 +        double  rc[3],
361 +        const RAY  *r,
362 +        int  flags
363 + )
364 + {
365 +        double  eext[3];
366 +        int     i;
367 +
368 +        eext[0] = eext[1] = eext[2] = 0.;
369 +        rc[0] = rc[1] = rc[2] = 1.;
370 +
371 +        while (r != NULL && r->crtype&flags) {
372 +                for (i = 3; i--; ) {
373 +                        rc[i] *= colval(r->rcoef,i);
374 +                        eext[i] += r->rot * colval(r->cext,i);
375 +                }
376 +                r = r->parent;
377 +        }
378 +        for (i = 3; i--; )
379 +                rc[i] *= (eext[i] <= FTINY) ? 1. :
380 +                                (eext[i] > 92.) ? 0. : exp(-eext[i]);
381 + }
382 +
383 +
384   extern double
385   raynormal(              /* compute perturbed normal for ray */
386          FVECT  norm,
# Line 362 | Line 427 | newrayxf(                      /* get new tranformation matrix for ray */
427                  FULLXF  xf;
428          }  xfseed = { &xfseed }, *xflast = &xfseed;
429          register struct xfn  *xp;
430 <        register RAY  *rp;
430 >        register const RAY  *rp;
431  
432          /*
433           * Search for transform in circular list that

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines