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.43 by greg, Tue Sep 9 03:28:43 2003 UTC vs.
Revision 2.50 by greg, Thu May 26 06:55:22 2005 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include  "ray.h"
13 <
13 > #include  "source.h"
14   #include  "otypes.h"
15
15   #include  "otspecial.h"
16  
17   #define  MAXCSET        ((MAXSET+1)*2-1)        /* maximum check set size */
# Line 28 | Line 27 | OBJREC  Lamb = {
27  
28   OBJREC  Aftplane;                       /* aft clipping plane object */
29  
31 static int  raymove(), checkhit();
32 static void  checkset();
33
34 #ifndef  MAXLOOP
35 #define  MAXLOOP        0               /* modifier loop detection */
36 #endif
37
30   #define  RAYHIT         (-1)            /* return value for intercepted ray */
31  
32 + static int raymove(FVECT  pos, OBJECT  *cxs, int  dirf, RAY  *r, CUBE  *cu);
33 + static int checkhit(RAY  *r, CUBE  *cu, OBJECT  *cxs);
34 + static void checkset(OBJECT  *os, OBJECT  *cs);
35  
41 int
42 rayorigin(r, ro, rt, rw)                /* start new ray from old one */
43 register RAY  *r, *ro;
44 int  rt;
45 double  rw;
46 {
47        double  re;
36  
37 + extern int
38 + rayorigin(              /* start new ray from old one */
39 +        RAY  *r,
40 +        int  rt,
41 +        const RAY  *ro,
42 +        const COLOR rc
43 + )
44 + {
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 58 | Line 64 | double  rw;
64                  r->gecc = seccg;
65                  r->slights = NULL;
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 77 | Line 87 | double  rw;
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);
100   }
101  
102  
103 < void
104 < rayclear(r)                     /* clear a ray for (re)evaluation */
105 < register RAY  *r;
103 > extern void
104 > rayclear(                       /* clear a ray for (re)evaluation */
105 >        register RAY  *r
106 > )
107   {
108          r->rno = raynum++;
109          r->newcset = r->clipset;
# Line 107 | Line 119 | register RAY  *r;
119   }
120  
121  
122 < void
123 < raytrace(r)                     /* trace a ray and compute its value */
124 < RAY  *r;
122 > extern void
123 > raytrace(                       /* trace a ray and compute its value */
124 >        RAY  *r
125 > )
126   {
127          if (localhit(r, &thescene))
128                  raycont(r);             /* hit local surface, evaluate */
# Line 119 | Line 132 | RAY  *r;
132          } else if (sourcehit(r))
133                  rayshade(r, r->ro->omod);       /* distant source */
134  
122        rayparticipate(r);              /* for participating medium */
123
135          if (trace != NULL)
136                  (*trace)(r);            /* trace execution */
137 +
138 +        rayparticipate(r);              /* for participating medium */
139   }
140  
141  
142 < void
143 < raycont(r)                      /* check for clipped object and continue */
144 < register RAY  *r;
142 > extern void
143 > raycont(                        /* check for clipped object and continue */
144 >        register RAY  *r
145 > )
146   {
147          if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
148                          !rayshade(r, r->ro->omod))
# Line 136 | Line 150 | register RAY  *r;
150   }
151  
152  
153 < void
154 < raytrans(r)                     /* transmit ray as is */
155 < register RAY  *r;
153 > extern void
154 > raytrans(                       /* transmit ray as is */
155 >        register RAY  *r
156 > )
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 151 | Line 166 | register RAY  *r;
166   }
167  
168  
169 < int
170 < rayshade(r, mod)                /* shade ray r with material mod */
171 < register RAY  *r;
172 < int  mod;
169 > extern int
170 > rayshade(               /* shade ray r with material mod */
171 >        register RAY  *r,
172 >        int  mod
173 > )
174   {
159        int  gotmat;
175          register OBJREC  *m;
176 < #if  MAXLOOP
162 <        static int  depth = 0;
163 <                                        /* check for infinite loop */
164 <        if (depth++ >= MAXLOOP)
165 <                objerror(r->ro, USER, "possible modifier loop");
166 < #endif
176 >
177          r->rt = r->rot;                 /* set effective ray length */
178 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
178 >        for ( ; mod != OVOID; mod = m->omod) {
179                  m = objptr(mod);
180                  /****** unnecessary test since modifier() is always called
181                  if (!ismodifier(m->otype)) {
# Line 178 | Line 188 | int  mod;
188                                  m->otype != MAT_CLIP &&
189                                  (ofun[m->otype].flags & (T_M|T_X))) {
190                          if (irr_ignore(m->otype)) {
181 #if  MAXLOOP
182                                depth--;
183 #endif
191                                  raytrans(r);
192                                  return(1);
193                          }
194                          if (!islight(m->otype))
195                                  m = &Lamb;
196                  }
197 <                                        /* materials call raytexture */
198 <                gotmat = (*ofun[m->otype].funp)(m, r);
197 >                if ((*ofun[m->otype].funp)(m, r))
198 >                        return(1);      /* materials call raytexture() */
199          }
200 < #if  MAXLOOP
194 <        depth--;
195 < #endif
196 <        return(gotmat);
200 >        return(0);                      /* no material! */
201   }
202  
203  
204 < void
205 < rayparticipate(r)                       /* compute ray medium participation */
206 < register RAY  *r;
204 > extern void
205 > rayparticipate(                 /* compute ray medium participation */
206 >        register RAY  *r
207 > )
208   {
209          COLOR   ce, ca;
210          double  re, ge, be;
# Line 214 | Line 219 | register RAY  *r;
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 229 | Line 234 | register RAY  *r;
234   }
235  
236  
237 < void
238 < raytexture(r, mod)                      /* get material modifiers */
239 < RAY  *r;
240 < OBJECT  mod;
237 > extern void
238 > raytexture(                     /* get material modifiers */
239 >        RAY  *r,
240 >        OBJECT  mod
241 > )
242   {
243          register OBJREC  *m;
238 #if  MAXLOOP
239        static int  depth = 0;
240                                        /* check for infinite loop */
241        if (depth++ >= MAXLOOP)
242                objerror(r->ro, USER, "modifier loop");
243 #endif
244                                          /* execute textures and patterns */
245          for ( ; mod != OVOID; mod = m->omod) {
246                  m = objptr(mod);
# Line 256 | Line 256 | OBJECT  mod;
256                          objerror(r->ro, USER, errmsg);
257                  }
258          }
259 #if  MAXLOOP
260        depth--;                        /* end here */
261 #endif
259   }
260  
261  
262 < int
263 < raymixture(r, fore, back, coef)         /* mix modifiers */
264 < register RAY  *r;
265 < OBJECT  fore, back;
266 < double  coef;
262 > extern int
263 > raymixture(             /* mix modifiers */
264 >        register RAY  *r,
265 >        OBJECT  fore,
266 >        OBJECT  back,
267 >        double  coef
268 > )
269   {
270          RAY  fr, br;
271          int  foremat, backmat;
# Line 314 | Line 313 | double  coef;
313   }
314  
315  
316 < double
317 < raydist(r, flags)               /* compute (cumulative) ray distance */
318 < register RAY  *r;
319 < register int  flags;
316 > extern double
317 > raydist(                /* compute (cumulative) ray distance */
318 >        register const RAY  *r,
319 >        register int  flags
320 > )
321   {
322          double  sum = 0.0;
323  
# Line 329 | Line 329 | register int  flags;
329   }
330  
331  
332 < double
333 < raynormal(norm, r)              /* compute perturbed normal for ray */
334 < FVECT  norm;
335 < register RAY  *r;
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,
363 +        register RAY  *r
364 + )
365 + {
366          double  newdot;
367          register int  i;
368  
# Line 364 | Line 393 | register RAY  *r;
393   }
394  
395  
396 < void
397 < newrayxf(r)                     /* get new tranformation matrix for ray */
398 < RAY  *r;
396 > extern void
397 > newrayxf(                       /* get new tranformation matrix for ray */
398 >        RAY  *r
399 > )
400   {
401          static struct xfn {
402                  struct xfn  *next;
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
# Line 401 | Line 431 | RAY  *r;
431   }
432  
433  
434 < void
435 < flipsurface(r)                  /* reverse surface orientation */
436 < register RAY  *r;
434 > extern void
435 > flipsurface(                    /* reverse surface orientation */
436 >        register RAY  *r
437 > )
438   {
439          r->rod = -r->rod;
440          r->ron[0] = -r->ron[0];
# Line 415 | Line 446 | register RAY  *r;
446   }
447  
448  
449 < void
450 < rayhit(oset, r)                 /* standard ray hit test */
451 < OBJECT  *oset;
452 < RAY  *r;
449 > extern void
450 > rayhit(                 /* standard ray hit test */
451 >        OBJECT  *oset,
452 >        RAY  *r
453 > )
454   {
455          OBJREC  *o;
456          int     i;
# Line 431 | Line 463 | RAY  *r;
463   }
464  
465  
466 < int
467 < localhit(r, scene)              /* check for hit in the octree */
468 < register RAY  *r;
469 < register CUBE  *scene;
466 > extern int
467 > localhit(               /* check for hit in the octree */
468 >        register RAY  *r,
469 >        register CUBE  *scene
470 > )
471   {
472          OBJECT  cxset[MAXCSET+1];       /* set of checked objects */
473          FVECT  curpos;                  /* current cube position */
# Line 494 | Line 527 | register CUBE  *scene;
527  
528  
529   static int
530 < raymove(pos, cxs, dirf, r, cu)          /* check for hit as we move */
531 < FVECT  pos;                     /* current position, modified herein */
532 < OBJECT  *cxs;                   /* checked objects, modified by checkhit */
533 < int  dirf;                      /* direction indicators to speed tests */
534 < register RAY  *r;
535 < register CUBE  *cu;
530 > raymove(                /* check for hit as we move */
531 >        FVECT  pos,                     /* current position, modified herein */
532 >        OBJECT  *cxs,                   /* checked objects, modified by checkhit */
533 >        int  dirf,                      /* direction indicators to speed tests */
534 >        register RAY  *r,
535 >        register CUBE  *cu
536 > )
537   {
538          int  ax;
539          double  dt, t;
# Line 580 | Line 614 | register CUBE  *cu;
614  
615  
616   static int
617 < checkhit(r, cu, cxs)            /* check for hit in full cube */
618 < register RAY  *r;
619 < CUBE  *cu;
620 < OBJECT  *cxs;
617 > checkhit(               /* check for hit in full cube */
618 >        register RAY  *r,
619 >        CUBE  *cu,
620 >        OBJECT  *cxs
621 > )
622   {
623          OBJECT  oset[MAXSET+1];
624  
# Line 600 | Line 635 | OBJECT  *cxs;
635  
636  
637   static void
638 < checkset(os, cs)                /* modify checked set and set to check */
639 < register OBJECT  *os;                   /* os' = os - cs */
640 < register OBJECT  *cs;                   /* cs' = cs + os */
638 > checkset(               /* modify checked set and set to check */
639 >        register OBJECT  *os,                   /* os' = os - cs */
640 >        register OBJECT  *cs                    /* cs' = cs + os */
641 > )
642   {
643          OBJECT  cset[MAXCSET+MAXSET+1];
644          register int  i, j;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines