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 1.3 by greg, Wed Apr 19 22:24:28 1989 UTC vs.
Revision 1.11 by greg, Sat Aug 18 04:25:59 1990 UTC

# Line 22 | Line 22 | extern double  minweight;              /* minimum ray weight */
22  
23   long  nrays = 0L;                       /* number of rays traced */
24  
25 < #define  MAXLOOP        32              /* modifier loop detection */
25 > #define  MAXLOOP        128             /* modifier loop detection */
26  
27   #define  RAYHIT         (-1)            /* return value for intercepted ray */
28  
# Line 59 | Line 59 | double  rw;
59          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
60          setcolor(r->pcol, 1.0, 1.0, 1.0);
61          setcolor(r->rcol, 0.0, 0.0, 0.0);
62 +        r->rt = 0.0;
63          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
64   }
65  
66  
67   rayvalue(r)                     /* compute a ray's value */
68 < register RAY  *r;
68 > RAY  *r;
69   {
70          extern int  (*trace)();
71  
72 <        if (localhit(r, &thescene))
73 <                if (r->clipset != NULL && inset(r->clipset, r->ro->omod))
73 <                        raytrans(r);            /* object is clipped */
74 <                else
75 <                        rayshade(r, r->ro->omod);
76 <        else if (sourcehit(r))
77 <                rayshade(r, r->ro->omod);
72 >        if (localhit(r, &thescene) || sourcehit(r))
73 >                raycont(r);
74  
75          if (trace != NULL)
76                  (*trace)(r);            /* trace execution */
77   }
78  
79  
80 + raycont(r)                      /* check for clipped object and continue */
81 + register RAY  *r;
82 + {
83 +        if (r->clipset != NULL && inset(r->clipset, r->ro->omod))
84 +                raytrans(r);
85 +        else
86 +                rayshade(r, r->ro->omod);
87 + }
88 +
89 +
90   raytrans(r)                     /* transmit ray as is */
91 < RAY  *r;
91 > register RAY  *r;
92   {
93          RAY  tr;
94  
# Line 90 | Line 96 | RAY  *r;
96                  VCOPY(tr.rdir, r->rdir);
97                  rayvalue(&tr);
98                  copycolor(r->rcol, tr.rcol);
99 +                r->rt = r->rot + tr.rt;
100          }
101   }
102  
# Line 102 | Line 109 | int  mod;
109          register OBJREC  *m;
110                                          /* check for infinite loop */
111          if (depth++ >= MAXLOOP)
112 <                objerror(r->ro, USER, "material loop");
112 >                objerror(r->ro, USER, "possible modifier loop");
113          for ( ; mod != OVOID; mod = m->omod) {
114                  m = objptr(mod);
115 +                /****** unnecessary test since modifier() is always called
116                  if (!ismodifier(m->otype)) {
117                          sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
118                          error(USER, errmsg);
119                  }
120 +                ******/
121                  (*ofun[m->otype].funp)(m, r);   /* execute function */
122                  m->lastrno = r->rno;
123                  if (ismaterial(m->otype)) {     /* materials call raytexture */
# Line 203 | Line 212 | register RAY  *r;
212           *  still fraught with problems since reflected rays and similar
213           *  directions calculated from the surface normal may spawn rays behind
214           *  the surface.  The only solution is to curb textures at high
215 <         *  incidence (Rdot << 1).
215 >         *  incidence (namely, keep DOT(rdir,pert) < Rdot).
216           */
217  
218          for (i = 0; i < 3; i++)
# Line 242 | Line 251 | register RAY  *r;
251   register CUBE  *scene;
252   {
253          FVECT  curpos;                  /* current cube position */
254 <        int  mpos, mneg;                /* sign flags */
254 >        int  sflags;                    /* sign flags */
255          double  t, dt;
256          register int  i;
257  
258          nrays++;                        /* increment trace counter */
259  
260 <        mpos = mneg = 0;
260 >        sflags = 0;
261          for (i = 0; i < 3; i++) {
262                  curpos[i] = r->rorg[i];
263                  if (r->rdir[i] > FTINY)
264 <                        mpos |= 1 << i;
264 >                        sflags |= 1 << i;
265                  else if (r->rdir[i] < -FTINY)
266 <                        mneg |= 1 << i;
266 >                        sflags |= 0x10 << i;
267          }
268          t = 0.0;
269          if (!incube(scene, curpos)) {
270                                          /* find distance to entry */
271                  for (i = 0; i < 3; i++) {
272                                          /* plane in our direction */
273 <                        if (mpos & 1<<i)
273 >                        if (sflags & 1<<i)
274                                  dt = scene->cuorg[i];
275 <                        else if (mneg & 1<<i)
275 >                        else if (sflags & 0x10<<i)
276                                  dt = scene->cuorg[i] + scene->cusize;
277                          else
278                                  continue;
# Line 280 | Line 289 | register CUBE  *scene;
289                  if (!incube(scene, curpos))     /* non-intersecting ray */
290                          return(0);
291          }
292 <        return(raymove(curpos, mpos, mneg, r, scene) == RAYHIT);
292 >        return(raymove(curpos, sflags, r, scene) == RAYHIT);
293   }
294  
295  
296   static int
297 < raymove(pos, plus, minus, r, cu)        /* check for hit as we move */
297 > raymove(pos, dirf, r, cu)               /* check for hit as we move */
298   FVECT  pos;                     /* modified */
299 < int  plus, minus;               /* direction indicators to speed tests */
299 > int  dirf;                      /* direction indicators to speed tests */
300   register RAY  *r;
301   register CUBE  *cu;
302   {
303          int  ax;
304          double  dt, t;
296        register int  sgn;
305  
306          if (istree(cu->cutree)) {               /* recurse on subcubes */
307                  CUBE  cukid;
308 <                register int  br;
308 >                register int  br, sgn;
309  
310                  cukid.cusize = cu->cusize * 0.5;        /* find subcube */
311                  VCOPY(cukid.cuorg, cu->cuorg);
# Line 316 | Line 324 | register CUBE  *cu;
324                  }
325                  for ( ; ; ) {
326                          cukid.cutree = octkid(cu->cutree, br);
327 <                        if ((ax = raymove(pos,plus,minus,r,&cukid)) == RAYHIT)
327 >                        if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT)
328                                  return(RAYHIT);
329                          sgn = 1 << ax;
330 <                        if (sgn & minus)                /* negative axis? */
323 <                                if (sgn & br) {
324 <                                        cukid.cuorg[ax] -= cukid.cusize;
325 <                                        br &= ~sgn;
326 <                                } else
327 <                                        return(ax);     /* underflow */
328 <                        else
330 >                        if (sgn & dirf)                 /* positive axis? */
331                                  if (sgn & br)
332                                          return(ax);     /* overflow */
333                                  else {
334                                          cukid.cuorg[ax] += cukid.cusize;
335                                          br |= sgn;
336                                  }
337 +                        else
338 +                                if (sgn & br) {
339 +                                        cukid.cuorg[ax] -= cukid.cusize;
340 +                                        br &= ~sgn;
341 +                                } else
342 +                                        return(ax);     /* underflow */
343                  }
344                  /*NOTREACHED*/
345          }
346          if (isfull(cu->cutree) && checkhit(r, cu))
347                  return(RAYHIT);
348                                          /* advance to next cube */
349 <        sgn = plus | minus;
350 <        if (sgn&1) {
343 <                dt = plus&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
349 >        if (dirf&0x11) {
350 >                dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
351                  t = (dt - pos[0])/r->rdir[0];
352                  ax = 0;
353          } else
354                  t = FHUGE;
355 <        if (sgn&2) {
356 <                dt = plus&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
355 >        if (dirf&0x22) {
356 >                dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
357                  dt = (dt - pos[1])/r->rdir[1];
358                  if (dt < t) {
359                          t = dt;
360                          ax = 1;
361                  }
362          }
363 <        if (sgn&4) {
364 <                dt = plus&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
363 >        if (dirf&0x44) {
364 >                dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
365                  dt = (dt - pos[2])/r->rdir[2];
366                  if (dt < t) {
367                          t = dt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines