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.46 by greg, Thu Mar 10 22:37:00 2005 UTC vs.
Revision 2.51 by greg, Tue May 31 18:01:09 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 55 | Line 64 | rayorigin(             /* start new ray from old one */
64                  copycolor(r->albedo, salbedo);
65                  r->gecc = seccg;
66                  r->slights = NULL;
58        } else if (ro->rot >= FHUGE) {          /* illegal continuation */
59                memset(r, 0, sizeof(RAY));
60                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 78 | 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 (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
101 +                if (minweight <= 0.0)
102 +                        error(USER, "zero ray weight in Russian roulette");
103 +                if (maxdepth < 0 && r->rlvl > -maxdepth)
104 +                        return(-1);             /* upper reflection limit */
105 +                if (r->rweight >= minweight)
106 +                        return(0);
107 +                if (frandom() < r->rweight/minweight)
108 +                        return(-1);
109 +                rw = minweight/r->rweight;      /* promote survivor */
110 +                scalecolor(r->rcoef, rw);
111 +                r->rweight = minweight;
112 +                return(0);
113 +        }
114          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
115   }
116  
# Line 122 | Line 147 | raytrace(                      /* trace a ray and compute its value */
147          } else if (sourcehit(r))
148                  rayshade(r, r->ro->omod);       /* distant source */
149  
125        rayparticipate(r);              /* for participating medium */
126
150          if (trace != NULL)
151                  (*trace)(r);            /* trace execution */
152 +
153 +        rayparticipate(r);              /* for participating medium */
154   }
155  
156  
# Line 147 | Line 172 | raytrans(                      /* transmit ray as is */
172   {
173          RAY  tr;
174  
175 <        if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
175 >        if (rayorigin(&tr, TRANS, r, NULL) == 0) {
176                  VCOPY(tr.rdir, r->rdir);
177                  rayvalue(&tr);
178                  copycolor(r->rcol, tr.rcol);
# Line 162 | Line 187 | rayshade(              /* shade ray r with material mod */
187          int  mod
188   )
189   {
165        int  gotmat;
190          register OBJREC  *m;
191 +
192          r->rt = r->rot;                 /* set effective ray length */
193 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
193 >        for ( ; mod != OVOID; mod = m->omod) {
194                  m = objptr(mod);
195                  /****** unnecessary test since modifier() is always called
196                  if (!ismodifier(m->otype)) {
# Line 184 | Line 209 | rayshade(              /* shade ray r with material mod */
209                          if (!islight(m->otype))
210                                  m = &Lamb;
211                  }
212 <                                        /* materials call raytexture */
213 <                gotmat = (*ofun[m->otype].funp)(m, r);
212 >                if ((*ofun[m->otype].funp)(m, r))
213 >                        return(1);      /* materials call raytexture() */
214          }
215 <        return(gotmat);
215 >        return(0);                      /* no material! */
216   }
217  
218  
# Line 209 | Line 234 | rayparticipate(                        /* compute ray medium participation
234                  ge *= 1. - colval(r->albedo,GRN);
235                  be *= 1. - colval(r->albedo,BLU);
236          }
237 <        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
238 <                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
239 <                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
240 <        multcolor(r->rcol, ce);                 /* path absorption */
237 >        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
238 >                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
239 >                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
240 >        multcolor(r->rcol, ce);                 /* path extinction */
241          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
242                  return;                         /* no scattering */
243          setcolor(ca,
# Line 305 | Line 330 | raymixture(            /* mix modifiers */
330  
331   extern double
332   raydist(                /* compute (cumulative) ray distance */
333 <        register RAY  *r,
333 >        register const RAY  *r,
334          register int  flags
335   )
336   {
# Line 319 | Line 344 | raydist(               /* compute (cumulative) ray distance */
344   }
345  
346  
347 + extern void
348 + raycontrib(             /* compute (cumulative) ray contribution */
349 +        COLOR  rc,
350 +        const RAY  *r,
351 +        int  flags
352 + )
353 + {
354 +        COLOR   eext, ext1;
355 +        
356 +        setcolor(eext, 0., 0., 0.);
357 +        setcolor(rc, 1., 1., 1.);
358 +
359 +        while (r != NULL && r->crtype&flags) {
360 +                multcolor(rc, r->rcoef);
361 +                copycolor(ext1, r->cext);
362 +                scalecolor(ext1, r->rot);
363 +                addcolor(eext, ext1);
364 +                r = r->parent;
365 +        }
366 +        if (intens(eext) > FTINY) {
367 +                setcolor(ext1,  exp(-colval(eext,RED)),
368 +                                exp(-colval(eext,GRN)),
369 +                                exp(-colval(eext,BLU)));
370 +                multcolor(rc, ext1);
371 +        }
372 + }
373 +
374 +
375   extern double
376   raynormal(              /* compute perturbed normal for ray */
377          FVECT  norm,
# Line 365 | 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