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.9 by greg, Tue Mar 6 08:47:30 1990 UTC vs.
Revision 1.16 by greg, Thu May 2 11:58:20 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1990 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "otypes.h"
18  
19 + #include  "otspecial.h"
20 +
21   extern CUBE  thescene;                  /* our scene */
22   extern int  maxdepth;                   /* maximum recursion depth */
23   extern double  minweight;               /* minimum ray weight */
24 + extern int  do_irrad;                   /* compute irradiance? */
25  
26   long  nrays = 0L;                       /* number of rays traced */
27  
28 + static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
29 + OBJREC  Lamb = {
30 +        OVOID, MAT_PLASTIC, "Lambertian",
31 +        {0, 5, NULL, Lambfa}, NULL, -1,
32 + };                                      /* a Lambertian surface */
33 +
34   #define  MAXLOOP        128             /* modifier loop detection */
35  
36   #define  RAYHIT         (-1)            /* return value for intercepted ray */
# Line 59 | Line 68 | double  rw;
68          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
69          setcolor(r->pcol, 1.0, 1.0, 1.0);
70          setcolor(r->rcol, 0.0, 0.0, 0.0);
71 +        r->rt = 0.0;
72          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
73   }
74  
# Line 68 | Line 78 | RAY  *r;
78   {
79          extern int  (*trace)();
80  
81 <        if (localhit(r, &thescene) || sourcehit(r))
81 >        if (localhit(r, &thescene))
82                  raycont(r);
83 +        else if (sourcehit(r))
84 +                rayshade(r, r->ro->omod);
85  
86          if (trace != NULL)
87                  (*trace)(r);            /* trace execution */
# Line 95 | Line 107 | register RAY  *r;
107                  VCOPY(tr.rdir, r->rdir);
108                  rayvalue(&tr);
109                  copycolor(r->rcol, tr.rcol);
110 +                r->rt = r->rot + tr.rt;
111          }
112   }
113  
# Line 116 | Line 129 | int  mod;
129                          error(USER, errmsg);
130                  }
131                  ******/
132 +                                        /* hack for irradiance calculation */
133 +                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) {
134 +                        if (irr_ignore(m->otype)) {
135 +                                depth--;
136 +                                raytrans(r);
137 +                                return;
138 +                        }
139 +                        if (m->otype != MAT_ILLUM)
140 +                                m = &Lamb;
141 +                }
142                  (*ofun[m->otype].funp)(m, r);   /* execute function */
143                  m->lastrno = r->rno;
144                  if (ismaterial(m->otype)) {     /* materials call raytexture */
# Line 231 | Line 254 | register RAY  *r;
254   }
255  
256  
257 + newrayxf(r)                     /* get new tranformation matrix for ray */
258 + RAY  *r;
259 + {
260 +        static struct xfn {
261 +                struct xfn  *next;
262 +                FULLXF  xf;
263 +        }  xfseed = { &xfseed }, *xflast = &xfseed;
264 +        register struct xfn  *xp;
265 +        register RAY  *rp;
266 +
267 +        /*
268 +         * Search for transform in circular list that
269 +         * has no associated ray in the tree.
270 +         */
271 +        xp = xflast;
272 +        for (rp = r->parent; rp != NULL; rp = rp->parent)
273 +                if (rp->rox == &xp->xf) {               /* xp in use */
274 +                        xp = xp->next;                  /* move to next */
275 +                        if (xp == xflast) {             /* need new one */
276 +                                xp = (struct xfn *)bmalloc(sizeof(struct xfn));
277 +                                if (xp == NULL)
278 +                                        error(SYSTEM,
279 +                                                "out of memory in newrayxf");
280 +                                                        /* insert in list */
281 +                                xp->next = xflast->next;
282 +                                xflast->next = xp;
283 +                                break;                  /* we're done */
284 +                        }
285 +                        rp = r;                 /* start check over */
286 +                }
287 +                                        /* got it */
288 +        r->rox = &xp->xf;
289 +        xflast = xp;
290 + }
291 +
292 +
293   flipsurface(r)                  /* reverse surface orientation */
294   register RAY  *r;
295   {
# Line 249 | Line 308 | register RAY  *r;
308   register CUBE  *scene;
309   {
310          FVECT  curpos;                  /* current cube position */
311 <        int  mpos, mneg;                /* sign flags */
311 >        int  sflags;                    /* sign flags */
312          double  t, dt;
313          register int  i;
314  
315          nrays++;                        /* increment trace counter */
316  
317 <        mpos = mneg = 0;
317 >        sflags = 0;
318          for (i = 0; i < 3; i++) {
319                  curpos[i] = r->rorg[i];
320                  if (r->rdir[i] > FTINY)
321 <                        mpos |= 1 << i;
321 >                        sflags |= 1 << i;
322                  else if (r->rdir[i] < -FTINY)
323 <                        mneg |= 1 << i;
323 >                        sflags |= 0x10 << i;
324          }
325          t = 0.0;
326          if (!incube(scene, curpos)) {
327                                          /* find distance to entry */
328                  for (i = 0; i < 3; i++) {
329                                          /* plane in our direction */
330 <                        if (mpos & 1<<i)
330 >                        if (sflags & 1<<i)
331                                  dt = scene->cuorg[i];
332 <                        else if (mneg & 1<<i)
332 >                        else if (sflags & 0x10<<i)
333                                  dt = scene->cuorg[i] + scene->cusize;
334                          else
335                                  continue;
# Line 287 | Line 346 | register CUBE  *scene;
346                  if (!incube(scene, curpos))     /* non-intersecting ray */
347                          return(0);
348          }
349 <        return(raymove(curpos, mpos, mneg, r, scene) == RAYHIT);
349 >        return(raymove(curpos, sflags, r, scene) == RAYHIT);
350   }
351  
352  
353   static int
354 < raymove(pos, plus, minus, r, cu)        /* check for hit as we move */
354 > raymove(pos, dirf, r, cu)               /* check for hit as we move */
355   FVECT  pos;                     /* modified */
356 < int  plus, minus;               /* direction indicators to speed tests */
356 > int  dirf;                      /* direction indicators to speed tests */
357   register RAY  *r;
358   register CUBE  *cu;
359   {
360          int  ax;
361          double  dt, t;
303        register int  sgn;
362  
363          if (istree(cu->cutree)) {               /* recurse on subcubes */
364                  CUBE  cukid;
365 <                register int  br;
365 >                register int  br, sgn;
366  
367                  cukid.cusize = cu->cusize * 0.5;        /* find subcube */
368                  VCOPY(cukid.cuorg, cu->cuorg);
# Line 323 | Line 381 | register CUBE  *cu;
381                  }
382                  for ( ; ; ) {
383                          cukid.cutree = octkid(cu->cutree, br);
384 <                        if ((ax = raymove(pos,plus,minus,r,&cukid)) == RAYHIT)
384 >                        if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT)
385                                  return(RAYHIT);
386                          sgn = 1 << ax;
387 <                        if (sgn & minus)                /* negative axis? */
330 <                                if (sgn & br) {
331 <                                        cukid.cuorg[ax] -= cukid.cusize;
332 <                                        br &= ~sgn;
333 <                                } else
334 <                                        return(ax);     /* underflow */
335 <                        else
387 >                        if (sgn & dirf)                 /* positive axis? */
388                                  if (sgn & br)
389                                          return(ax);     /* overflow */
390                                  else {
391                                          cukid.cuorg[ax] += cukid.cusize;
392                                          br |= sgn;
393                                  }
394 +                        else
395 +                                if (sgn & br) {
396 +                                        cukid.cuorg[ax] -= cukid.cusize;
397 +                                        br &= ~sgn;
398 +                                } else
399 +                                        return(ax);     /* underflow */
400                  }
401                  /*NOTREACHED*/
402          }
403          if (isfull(cu->cutree) && checkhit(r, cu))
404                  return(RAYHIT);
405                                          /* advance to next cube */
406 <        sgn = plus | minus;
407 <        if (sgn&1) {
350 <                dt = plus&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
406 >        if (dirf&0x11) {
407 >                dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
408                  t = (dt - pos[0])/r->rdir[0];
409                  ax = 0;
410          } else
411                  t = FHUGE;
412 <        if (sgn&2) {
413 <                dt = plus&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
412 >        if (dirf&0x22) {
413 >                dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
414                  dt = (dt - pos[1])/r->rdir[1];
415                  if (dt < t) {
416                          t = dt;
417                          ax = 1;
418                  }
419          }
420 <        if (sgn&4) {
421 <                dt = plus&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
420 >        if (dirf&0x44) {
421 >                dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
422                  dt = (dt - pos[2])/r->rdir[2];
423                  if (dt < t) {
424                          t = dt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines