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.41 by schorsch, Mon Jul 21 22:30:19 2003 UTC vs.
Revision 2.48 by greg, Fri Apr 15 04:44:51 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  
36 < int
37 < rayorigin(r, ro, rt, rw)                /* start new ray from old one */
38 < register RAY  *r, *ro;
39 < int  rt;
40 < double  rw;
36 >
37 > extern int
38 > rayorigin(              /* start new ray from old one */
39 >        register RAY  *r,
40 >        register RAY  *ro,
41 >        int  rt,
42 >        double  rw
43 > )
44   {
45          double  re;
46  
# Line 52 | Line 50 | double  rw;
50                  r->crtype = r->rtype = rt;
51                  r->rsrc = -1;
52                  r->clipset = NULL;
55                r->revf = raytrace;
53                  copycolor(r->cext, cextinction);
54                  copycolor(r->albedo, salbedo);
55                  r->gecc = seccg;
56                  r->slights = NULL;
57 +        } else if (ro->rot >= FHUGE) {          /* illegal continuation */
58 +                memset(r, 0, sizeof(RAY));
59 +                return(-1);
60          } else {                                /* spawned ray */
61                  r->rlvl = ro->rlvl;
62                  if (rt & RAYREFL) {
# Line 69 | Line 69 | double  rw;
69                          r->clipset = ro->newcset;
70                          r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
71                  }
72                r->revf = ro->revf;
72                  copycolor(r->cext, ro->cext);
73                  copycolor(r->albedo, ro->albedo);
74                  r->gecc = ro->gecc;
# Line 89 | Line 88 | double  rw;
88   }
89  
90  
91 < void
92 < rayclear(r)                     /* clear a ray for (re)evaluation */
93 < register RAY  *r;
91 > extern void
92 > rayclear(                       /* clear a ray for (re)evaluation */
93 >        register RAY  *r
94 > )
95   {
96          r->rno = raynum++;
97          r->newcset = r->clipset;
# Line 107 | Line 107 | register RAY  *r;
107   }
108  
109  
110 < void
111 < raytrace(r)                     /* trace a ray and compute its value */
112 < RAY  *r;
110 > extern void
111 > rayvalue(                       /* trace a ray and compute its value */
112 >        RAY  *r
113 > )
114   {
115          if (localhit(r, &thescene))
116                  raycont(r);             /* hit local surface, evaluate */
# Line 126 | Line 127 | RAY  *r;
127   }
128  
129  
130 < void
131 < raycont(r)                      /* check for clipped object and continue */
132 < register RAY  *r;
130 > extern void
131 > raycont(                        /* check for clipped object and continue */
132 >        register RAY  *r
133 > )
134   {
135          if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
136                          !rayshade(r, r->ro->omod))
# Line 136 | Line 138 | register RAY  *r;
138   }
139  
140  
141 < void
142 < raytrans(r)                     /* transmit ray as is */
143 < register RAY  *r;
141 > extern void
142 > raytrans(                       /* transmit ray as is */
143 >        register RAY  *r
144 > )
145   {
146          RAY  tr;
147  
# Line 151 | Line 154 | register RAY  *r;
154   }
155  
156  
157 < int
158 < rayshade(r, mod)                /* shade ray r with material mod */
159 < register RAY  *r;
160 < int  mod;
157 > extern int
158 > rayshade(               /* shade ray r with material mod */
159 >        register RAY  *r,
160 >        int  mod
161 > )
162   {
159        int  gotmat;
163          register OBJREC  *m;
164 < #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
164 >
165          r->rt = r->rot;                 /* set effective ray length */
166 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
166 >        for ( ; mod != OVOID; mod = m->omod) {
167                  m = objptr(mod);
168                  /****** unnecessary test since modifier() is always called
169                  if (!ismodifier(m->otype)) {
# Line 175 | Line 173 | int  mod;
173                  ******/
174                                          /* hack for irradiance calculation */
175                  if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
176 +                                m->otype != MAT_CLIP &&
177                                  (ofun[m->otype].flags & (T_M|T_X))) {
178                          if (irr_ignore(m->otype)) {
180 #if  MAXLOOP
181                                depth--;
182 #endif
179                                  raytrans(r);
180                                  return(1);
181                          }
182                          if (!islight(m->otype))
183                                  m = &Lamb;
184                  }
185 <                                        /* materials call raytexture */
186 <                gotmat = (*ofun[m->otype].funp)(m, r);
185 >                if ((*ofun[m->otype].funp)(m, r))
186 >                        return(1);      /* materials call raytexture() */
187          }
188 < #if  MAXLOOP
193 <        depth--;
194 < #endif
195 <        return(gotmat);
188 >        return(0);                      /* no material! */
189   }
190  
191  
192 < void
193 < rayparticipate(r)                       /* compute ray medium participation */
194 < register RAY  *r;
192 > extern void
193 > rayparticipate(                 /* compute ray medium participation */
194 >        register RAY  *r
195 > )
196   {
197          COLOR   ce, ca;
198          double  re, ge, be;
# Line 228 | Line 222 | register RAY  *r;
222   }
223  
224  
225 < void
226 < raytexture(r, mod)                      /* get material modifiers */
227 < RAY  *r;
228 < OBJECT  mod;
225 > extern void
226 > raytexture(                     /* get material modifiers */
227 >        RAY  *r,
228 >        OBJECT  mod
229 > )
230   {
231          register OBJREC  *m;
237 #if  MAXLOOP
238        static int  depth = 0;
239                                        /* check for infinite loop */
240        if (depth++ >= MAXLOOP)
241                objerror(r->ro, USER, "modifier loop");
242 #endif
232                                          /* execute textures and patterns */
233          for ( ; mod != OVOID; mod = m->omod) {
234                  m = objptr(mod);
# Line 255 | Line 244 | OBJECT  mod;
244                          objerror(r->ro, USER, errmsg);
245                  }
246          }
258 #if  MAXLOOP
259        depth--;                        /* end here */
260 #endif
247   }
248  
249  
250 < int
251 < raymixture(r, fore, back, coef)         /* mix modifiers */
252 < register RAY  *r;
253 < OBJECT  fore, back;
254 < double  coef;
250 > extern int
251 > raymixture(             /* mix modifiers */
252 >        register RAY  *r,
253 >        OBJECT  fore,
254 >        OBJECT  back,
255 >        double  coef
256 > )
257   {
258          RAY  fr, br;
259          int  foremat, backmat;
# Line 313 | Line 301 | double  coef;
301   }
302  
303  
304 < double
305 < raydist(r, flags)               /* compute (cumulative) ray distance */
306 < register RAY  *r;
307 < register int  flags;
304 > extern double
305 > raydist(                /* compute (cumulative) ray distance */
306 >        register RAY  *r,
307 >        register int  flags
308 > )
309   {
310          double  sum = 0.0;
311  
# Line 328 | Line 317 | register int  flags;
317   }
318  
319  
320 < double
321 < raynormal(norm, r)              /* compute perturbed normal for ray */
322 < FVECT  norm;
323 < register RAY  *r;
320 > extern double
321 > raynormal(              /* compute perturbed normal for ray */
322 >        FVECT  norm,
323 >        register RAY  *r
324 > )
325   {
326          double  newdot;
327          register int  i;
# Line 363 | Line 353 | register RAY  *r;
353   }
354  
355  
356 < void
357 < newrayxf(r)                     /* get new tranformation matrix for ray */
358 < RAY  *r;
356 > extern void
357 > newrayxf(                       /* get new tranformation matrix for ray */
358 >        RAY  *r
359 > )
360   {
361          static struct xfn {
362                  struct xfn  *next;
# Line 400 | Line 391 | RAY  *r;
391   }
392  
393  
394 < void
395 < flipsurface(r)                  /* reverse surface orientation */
396 < register RAY  *r;
394 > extern void
395 > flipsurface(                    /* reverse surface orientation */
396 >        register RAY  *r
397 > )
398   {
399          r->rod = -r->rod;
400          r->ron[0] = -r->ron[0];
# Line 414 | Line 406 | register RAY  *r;
406   }
407  
408  
409 < void
410 < rayhit(oset, r)                 /* standard ray hit test */
411 < OBJECT  *oset;
412 < RAY  *r;
409 > extern void
410 > rayhit(                 /* standard ray hit test */
411 >        OBJECT  *oset,
412 >        RAY  *r
413 > )
414   {
415          OBJREC  *o;
416          int     i;
# Line 430 | Line 423 | RAY  *r;
423   }
424  
425  
426 < int
427 < localhit(r, scene)              /* check for hit in the octree */
428 < register RAY  *r;
429 < register CUBE  *scene;
426 > extern int
427 > localhit(               /* check for hit in the octree */
428 >        register RAY  *r,
429 >        register CUBE  *scene
430 > )
431   {
432          OBJECT  cxset[MAXCSET+1];       /* set of checked objects */
433          FVECT  curpos;                  /* current cube position */
# Line 488 | Line 482 | register CUBE  *scene;
482          }
483          cxset[0] = 0;
484          raymove(curpos, cxset, sflags, r, scene);
485 <        return(r->ro != NULL & r->ro != &Aftplane);
485 >        return((r->ro != NULL) & (r->ro != &Aftplane));
486   }
487  
488  
489   static int
490 < raymove(pos, cxs, dirf, r, cu)          /* check for hit as we move */
491 < FVECT  pos;                     /* current position, modified herein */
492 < OBJECT  *cxs;                   /* checked objects, modified by checkhit */
493 < int  dirf;                      /* direction indicators to speed tests */
494 < register RAY  *r;
495 < register CUBE  *cu;
490 > raymove(                /* check for hit as we move */
491 >        FVECT  pos,                     /* current position, modified herein */
492 >        OBJECT  *cxs,                   /* checked objects, modified by checkhit */
493 >        int  dirf,                      /* direction indicators to speed tests */
494 >        register RAY  *r,
495 >        register CUBE  *cu
496 > )
497   {
498          int  ax;
499          double  dt, t;
# Line 579 | Line 574 | register CUBE  *cu;
574  
575  
576   static int
577 < checkhit(r, cu, cxs)            /* check for hit in full cube */
578 < register RAY  *r;
579 < CUBE  *cu;
580 < OBJECT  *cxs;
577 > checkhit(               /* check for hit in full cube */
578 >        register RAY  *r,
579 >        CUBE  *cu,
580 >        OBJECT  *cxs
581 > )
582   {
583          OBJECT  oset[MAXSET+1];
584  
# Line 599 | Line 595 | OBJECT  *cxs;
595  
596  
597   static void
598 < checkset(os, cs)                /* modify checked set and set to check */
599 < register OBJECT  *os;                   /* os' = os - cs */
600 < register OBJECT  *cs;                   /* cs' = cs + os */
598 > checkset(               /* modify checked set and set to check */
599 >        register OBJECT  *os,                   /* os' = os - cs */
600 >        register OBJECT  *cs                    /* cs' = cs + os */
601 > )
602   {
603          OBJECT  cset[MAXCSET+MAXSET+1];
604          register int  i, j;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines