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.52 by greg, Tue Jun 21 15:06:50 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 > .1)
97 >                        r->rweight *= exp(-re);
98          }
99          rayclear(r);
100 +        if (r->crtype & SHADOW)                 /* shadow commitment */
101 +                return(0);
102 +        if (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
103 +                if (minweight <= 0.0)
104 +                        error(USER, "zero ray weight in Russian roulette");
105 +                if (maxdepth < 0 && r->rlvl > -maxdepth)
106 +                        return(-1);             /* upper reflection limit */
107 +                if (r->rweight >= minweight)
108 +                        return(0);
109 +                if (frandom() < r->rweight/minweight)
110 +                        return(-1);
111 +                rw = minweight/r->rweight;      /* promote survivor */
112 +                scalecolor(r->rcoef, rw);
113 +                r->rweight = minweight;
114 +                return(0);
115 +        }
116          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
117   }
118  
# Line 119 | Line 149 | raytrace(                      /* trace a ray and compute its value */
149          } else if (sourcehit(r))
150                  rayshade(r, r->ro->omod);       /* distant source */
151  
122        rayparticipate(r);              /* for participating medium */
123
152          if (trace != NULL)
153                  (*trace)(r);            /* trace execution */
154 +
155 +        rayparticipate(r);              /* for participating medium */
156   }
157  
158  
# Line 144 | Line 174 | raytrans(                      /* transmit ray as is */
174   {
175          RAY  tr;
176  
177 <        if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
177 >        if (rayorigin(&tr, TRANS, r, NULL) == 0) {
178                  VCOPY(tr.rdir, r->rdir);
179                  rayvalue(&tr);
180                  copycolor(r->rcol, tr.rcol);
# Line 159 | Line 189 | rayshade(              /* shade ray r with material mod */
189          int  mod
190   )
191   {
162        int  gotmat;
192          register OBJREC  *m;
193 +
194          r->rt = r->rot;                 /* set effective ray length */
195 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
195 >        for ( ; mod != OVOID; mod = m->omod) {
196                  m = objptr(mod);
197                  /****** unnecessary test since modifier() is always called
198                  if (!ismodifier(m->otype)) {
# Line 181 | Line 211 | rayshade(              /* shade ray r with material mod */
211                          if (!islight(m->otype))
212                                  m = &Lamb;
213                  }
214 <                                        /* materials call raytexture */
215 <                gotmat = (*ofun[m->otype].funp)(m, r);
214 >                if ((*ofun[m->otype].funp)(m, r))
215 >                        return(1);      /* materials call raytexture() */
216          }
217 <        return(gotmat);
217 >        return(0);                      /* no material! */
218   }
219  
220  
# Line 206 | Line 236 | rayparticipate(                        /* compute ray medium participation
236                  ge *= 1. - colval(r->albedo,GRN);
237                  be *= 1. - colval(r->albedo,BLU);
238          }
239 <        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
240 <                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
241 <                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
242 <        multcolor(r->rcol, ce);                 /* path absorption */
239 >        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
240 >                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
241 >                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
242 >        multcolor(r->rcol, ce);                 /* path extinction */
243          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
244                  return;                         /* no scattering */
245          setcolor(ca,
# Line 302 | Line 332 | raymixture(            /* mix modifiers */
332  
333   extern double
334   raydist(                /* compute (cumulative) ray distance */
335 <        register RAY  *r,
335 >        register const RAY  *r,
336          register int  flags
337   )
338   {
# Line 316 | Line 346 | raydist(               /* compute (cumulative) ray distance */
346   }
347  
348  
349 + extern void
350 + raycontrib(             /* compute (cumulative) ray contribution */
351 +        double  rc[3],
352 +        const RAY  *r,
353 +        int  flags
354 + )
355 + {
356 +        double  eext[3];
357 +        int     i;
358 +
359 +        eext[0] = eext[1] = eext[2] = 0.;
360 +        rc[0] = rc[1] = rc[2] = 1.;
361 +
362 +        while (r != NULL && r->crtype&flags) {
363 +                for (i = 3; i--; ) {
364 +                        rc[i] *= colval(r->rcoef,i);
365 +                        eext[i] += r->rot * colval(r->cext,i);
366 +                }
367 +                r = r->parent;
368 +        }
369 +        for (i = 3; i--; )
370 +                rc[i] *= (eext[i] <= FTINY) ? 1. :
371 +                                (eext[i] > 300.) ? 0. : exp(-eext[i]);
372 + }
373 +
374 +
375   extern double
376   raynormal(              /* compute perturbed normal for ray */
377          FVECT  norm,
# Line 362 | Line 418 | newrayxf(                      /* get new tranformation matrix for ray */
418                  FULLXF  xf;
419          }  xfseed = { &xfseed }, *xflast = &xfseed;
420          register struct xfn  *xp;
421 <        register RAY  *rp;
421 >        register const RAY  *rp;
422  
423          /*
424           * Search for transform in circular list that

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines