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.11 by greg, Sat Aug 18 04:25:59 1990 UTC vs.
Revision 2.2 by greg, Mon Jan 25 15:16:59 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 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 */
26 > long  raynum = 0L;                      /* next unique ray number */
27 > long  nrays = 0L;                       /* number of calls to localhit */
28  
29 + static FLOAT  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
30 + OBJREC  Lamb = {
31 +        OVOID, MAT_PLASTIC, "Lambertian",
32 +        {0, 5, NULL, Lambfa}, NULL,
33 + };                                      /* a Lambertian surface */
34 +
35   #define  MAXLOOP        128             /* modifier loop detection */
36  
37   #define  RAYHIT         (-1)            /* return value for intercepted ray */
# Line 38 | Line 48 | double  rw;
48                  r->crtype = r->rtype = rt;
49                  r->rsrc = -1;
50                  r->clipset = NULL;
51 +                r->revf = raytrace;
52          } else {                                /* spawned ray */
53                  r->rlvl = ro->rlvl;
54                  if (rt & RAYREFL) {
# Line 48 | Line 59 | double  rw;
59                          r->rsrc = ro->rsrc;
60                          r->clipset = ro->newcset;
61                  }
62 +                r->revf = ro->revf;
63                  r->rweight = ro->rweight * rw;
64                  r->crtype = ro->crtype | (r->rtype = rt);
65                  VCOPY(r->rorg, ro->rop);
66          }
67 <        r->rno = nrays;
67 >        rayclear(r);
68 >        return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
69 > }
70 >
71 >
72 > rayclear(r)                     /* clear a ray for (re)evaluation */
73 > register RAY  *r;
74 > {
75 >        r->rno = raynum++;
76 >        r->cxs[0] = 0;
77          r->newcset = r->clipset;
78          r->ro = NULL;
79          r->rot = FHUGE;
# Line 60 | Line 81 | double  rw;
81          setcolor(r->pcol, 1.0, 1.0, 1.0);
82          setcolor(r->rcol, 0.0, 0.0, 0.0);
83          r->rt = 0.0;
63        return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
84   }
85  
86  
87 < rayvalue(r)                     /* compute a ray's value */
87 > raytrace(r)                     /* trace a ray and compute its value */
88   RAY  *r;
89   {
90          extern int  (*trace)();
91  
92 <        if (localhit(r, &thescene) || sourcehit(r))
92 >        if (localhit(r, &thescene))
93                  raycont(r);
94 +        else if (sourcehit(r))
95 +                rayshade(r, r->ro->omod);
96  
97          if (trace != NULL)
98                  (*trace)(r);            /* trace execution */
# Line 110 | Line 132 | int  mod;
132                                          /* check for infinite loop */
133          if (depth++ >= MAXLOOP)
134                  objerror(r->ro, USER, "possible modifier loop");
135 +        r->rt = r->rot;                 /* set effective ray length */
136          for ( ; mod != OVOID; mod = m->omod) {
137                  m = objptr(mod);
138                  /****** unnecessary test since modifier() is always called
# Line 118 | Line 141 | int  mod;
141                          error(USER, errmsg);
142                  }
143                  ******/
144 +                                        /* hack for irradiance calculation */
145 +                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) {
146 +                        if (irr_ignore(m->otype)) {
147 +                                depth--;
148 +                                raytrans(r);
149 +                                return;
150 +                        }
151 +                        if (!islight(m->otype))
152 +                                m = &Lamb;
153 +                }
154                  (*ofun[m->otype].funp)(m, r);   /* execute function */
122                m->lastrno = r->rno;
155                  if (ismaterial(m->otype)) {     /* materials call raytexture */
156                          depth--;
157                          return;         /* we're done */
# Line 146 | Line 178 | int  mod;
178                          error(USER, errmsg);
179                  }
180                  (*ofun[m->otype].funp)(m, r);
149                m->lastrno = r->rno;
181          }
182          depth--;                        /* end here */
183   }
# Line 233 | Line 264 | register RAY  *r;
264   }
265  
266  
267 + newrayxf(r)                     /* get new tranformation matrix for ray */
268 + RAY  *r;
269 + {
270 +        static struct xfn {
271 +                struct xfn  *next;
272 +                FULLXF  xf;
273 +        }  xfseed = { &xfseed }, *xflast = &xfseed;
274 +        register struct xfn  *xp;
275 +        register RAY  *rp;
276 +
277 +        /*
278 +         * Search for transform in circular list that
279 +         * has no associated ray in the tree.
280 +         */
281 +        xp = xflast;
282 +        for (rp = r->parent; rp != NULL; rp = rp->parent)
283 +                if (rp->rox == &xp->xf) {               /* xp in use */
284 +                        xp = xp->next;                  /* move to next */
285 +                        if (xp == xflast) {             /* need new one */
286 +                                xp = (struct xfn *)bmalloc(sizeof(struct xfn));
287 +                                if (xp == NULL)
288 +                                        error(SYSTEM,
289 +                                                "out of memory in newrayxf");
290 +                                                        /* insert in list */
291 +                                xp->next = xflast->next;
292 +                                xflast->next = xp;
293 +                                break;                  /* we're done */
294 +                        }
295 +                        rp = r;                 /* start check over */
296 +                }
297 +                                        /* got it */
298 +        r->rox = &xp->xf;
299 +        xflast = xp;
300 + }
301 +
302 +
303   flipsurface(r)                  /* reverse surface orientation */
304   register RAY  *r;
305   {
# Line 256 | Line 323 | register CUBE  *scene;
323          register int  i;
324  
325          nrays++;                        /* increment trace counter */
259
326          sflags = 0;
327          for (i = 0; i < 3; i++) {
328                  curpos[i] = r->rorg[i];
# Line 265 | Line 331 | register CUBE  *scene;
331                  else if (r->rdir[i] < -FTINY)
332                          sflags |= 0x10 << i;
333          }
334 +        if (sflags == 0)
335 +                error(CONSISTENCY, "zero ray direction in localhit");
336          t = 0.0;
337          if (!incube(scene, curpos)) {
338                                          /* find distance to entry */
# Line 385 | Line 453 | CUBE  *cu;
453          register int  i;
454  
455          objset(oset, cu->cutree);
456 +        checkset(oset, r->cxs);                 /* eliminate double-checking */
457          for (i = oset[0]; i > 0; i--) {
458                  o = objptr(oset[i]);
390                if (o->lastrno == r->rno)               /* checked already? */
391                        continue;
459                  (*ofun[o->otype].funp)(o, r);
393                o->lastrno = r->rno;
460          }
461          if (r->ro == NULL)
462                  return(0);                      /* no scores yet */
463  
464          return(incube(cu, r->rop));             /* hit OK if in current cube */
465 + }
466 +
467 +
468 + static
469 + checkset(os, cs)                /* modify checked set and set to check */
470 + register OBJECT  os[MAXSET+1];          /* os' = os - cs */
471 + register OBJECT  cs[MAXCSET+1];         /* cs' = cs + os */
472 + {
473 +        OBJECT  cset[MAXCSET+MAXSET+1];
474 +        register int  i, j, k;
475 +                                        /* copy os in place, cset <- cs */
476 +        cset[0] = 0;
477 +        k = 0;
478 +        for (i = j = 1; i <= os[0]; i++) {
479 +                while (j <= cs[0] && cs[j] < os[i])
480 +                        cset[++cset[0]] = cs[j++];
481 +                if (j > cs[0] || os[i] != cs[j]) {      /* object to check */
482 +                        os[++k] = os[i];
483 +                        cset[++cset[0]] = os[i];
484 +                }
485 +        }
486 +        while (j <= cs[0])              /* get the rest of cs */
487 +                cset[++cset[0]] = cs[j++];
488 +        if (cset[0] > MAXCSET)          /* truncate if necessary */
489 +                cset[0] = MAXCSET;
490 +        setcopy(cs, cset);              /* copy new "checked" set back */
491 +        os[0] = k;                      /* new "to check" set size */
492   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines