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 1.20 by greg, Mon Jun 17 08:26:18 1991 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 rayvalue */
28  
29 + static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
30 + OBJREC  Lamb = {
31 +        OVOID, MAT_PLASTIC, "Lambertian",
32 +        {0, 5, NULL, Lambfa}, NULL, -1,
33 + };                                      /* a Lambertian surface */
34 +
35   #define  MAXLOOP        128             /* modifier loop detection */
36  
37   #define  RAYHIT         (-1)            /* return value for intercepted ray */
# Line 52 | Line 62 | double  rw;
62                  r->crtype = ro->crtype | (r->rtype = rt);
63                  VCOPY(r->rorg, ro->rop);
64          }
65 <        r->rno = nrays;
65 >        r->rno = raynum++;
66          r->newcset = r->clipset;
67          r->ro = NULL;
68          r->rot = FHUGE;
# Line 69 | Line 79 | RAY  *r;
79   {
80          extern int  (*trace)();
81  
82 <        if (localhit(r, &thescene) || sourcehit(r))
82 >        nrays++;                        /* increment trace counter */
83 >        if (localhit(r, &thescene))
84                  raycont(r);
85 +        else if (sourcehit(r))
86 +                rayshade(r, r->ro->omod);
87  
88          if (trace != NULL)
89                  (*trace)(r);            /* trace execution */
# Line 110 | Line 123 | int  mod;
123                                          /* check for infinite loop */
124          if (depth++ >= MAXLOOP)
125                  objerror(r->ro, USER, "possible modifier loop");
126 +        r->rt = r->rot;                 /* set effective ray length */
127          for ( ; mod != OVOID; mod = m->omod) {
128                  m = objptr(mod);
129                  /****** unnecessary test since modifier() is always called
# Line 118 | Line 132 | int  mod;
132                          error(USER, errmsg);
133                  }
134                  ******/
135 +                                        /* hack for irradiance calculation */
136 +                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) {
137 +                        if (irr_ignore(m->otype)) {
138 +                                depth--;
139 +                                raytrans(r);
140 +                                return;
141 +                        }
142 +                        if (!islight(m->otype))
143 +                                m = &Lamb;
144 +                }
145                  (*ofun[m->otype].funp)(m, r);   /* execute function */
146                  m->lastrno = r->rno;
147                  if (ismaterial(m->otype)) {     /* materials call raytexture */
# Line 233 | Line 257 | register RAY  *r;
257   }
258  
259  
260 + newrayxf(r)                     /* get new tranformation matrix for ray */
261 + RAY  *r;
262 + {
263 +        static struct xfn {
264 +                struct xfn  *next;
265 +                FULLXF  xf;
266 +        }  xfseed = { &xfseed }, *xflast = &xfseed;
267 +        register struct xfn  *xp;
268 +        register RAY  *rp;
269 +
270 +        /*
271 +         * Search for transform in circular list that
272 +         * has no associated ray in the tree.
273 +         */
274 +        xp = xflast;
275 +        for (rp = r->parent; rp != NULL; rp = rp->parent)
276 +                if (rp->rox == &xp->xf) {               /* xp in use */
277 +                        xp = xp->next;                  /* move to next */
278 +                        if (xp == xflast) {             /* need new one */
279 +                                xp = (struct xfn *)bmalloc(sizeof(struct xfn));
280 +                                if (xp == NULL)
281 +                                        error(SYSTEM,
282 +                                                "out of memory in newrayxf");
283 +                                                        /* insert in list */
284 +                                xp->next = xflast->next;
285 +                                xflast->next = xp;
286 +                                break;                  /* we're done */
287 +                        }
288 +                        rp = r;                 /* start check over */
289 +                }
290 +                                        /* got it */
291 +        r->rox = &xp->xf;
292 +        xflast = xp;
293 + }
294 +
295 +
296   flipsurface(r)                  /* reverse surface orientation */
297   register RAY  *r;
298   {
# Line 255 | Line 315 | register CUBE  *scene;
315          double  t, dt;
316          register int  i;
317  
258        nrays++;                        /* increment trace counter */
259
318          sflags = 0;
319          for (i = 0; i < 3; i++) {
320                  curpos[i] = r->rorg[i];
# Line 265 | Line 323 | register CUBE  *scene;
323                  else if (r->rdir[i] < -FTINY)
324                          sflags |= 0x10 << i;
325          }
326 +        if (sflags == 0)
327 +                error(CONSISTENCY, "zero ray direction in localhit");
328          t = 0.0;
329          if (!incube(scene, curpos)) {
330                                          /* find distance to entry */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines