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.34 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.45 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  raytrace.c - routines for tracing and shading rays.
# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in ray.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12   #include  "ray.h"
13 <
13 > #include  "source.h"
14   #include  "otypes.h"
70
15   #include  "otspecial.h"
16  
17   #define  MAXCSET        ((MAXSET+1)*2-1)        /* maximum check set size */
# Line 75 | Line 19 | static const char      RCSid[] = "$Id$";
19   unsigned long  raynum = 0;              /* next unique ray number */
20   unsigned long  nrays = 0;               /* number of calls to localhit */
21  
22 < static FLOAT  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
22 > static RREAL  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
23   OBJREC  Lamb = {
24          OVOID, MAT_PLASTIC, "Lambertian",
25          {0, 5, NULL, Lambfa}, NULL,
# Line 83 | Line 27 | OBJREC  Lamb = {
27  
28   OBJREC  Aftplane;                       /* aft clipping plane object */
29  
86 static int  raymove(), checkhit();
87 static void  checkset();
88
89 #ifndef  MAXLOOP
90 #define  MAXLOOP        0               /* modifier loop detection */
91 #endif
92
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 144 | Line 87 | double  rw;
87   }
88  
89  
90 < void
91 < rayclear(r)                     /* clear a ray for (re)evaluation */
92 < register RAY  *r;
90 > extern void
91 > rayclear(                       /* clear a ray for (re)evaluation */
92 >        register RAY  *r
93 > )
94   {
95          r->rno = raynum++;
96          r->newcset = r->clipset;
97 +        r->hitf = rayhit;
98          r->robj = OVOID;
99          r->ro = NULL;
100          r->rox = NULL;
101          r->rt = r->rot = FHUGE;
102          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
103 +        r->uv[0] = r->uv[1] = 0.0;
104          setcolor(r->pcol, 1.0, 1.0, 1.0);
105          setcolor(r->rcol, 0.0, 0.0, 0.0);
106   }
107  
108  
109 < void
110 < raytrace(r)                     /* trace a ray and compute its value */
111 < RAY  *r;
109 > extern void
110 > raytrace(                       /* trace a ray and compute its value */
111 >        RAY  *r
112 > )
113   {
114          if (localhit(r, &thescene))
115                  raycont(r);             /* hit local surface, evaluate */
# Line 179 | Line 126 | RAY  *r;
126   }
127  
128  
129 < void
130 < raycont(r)                      /* check for clipped object and continue */
131 < register RAY  *r;
129 > extern void
130 > raycont(                        /* check for clipped object and continue */
131 >        register RAY  *r
132 > )
133   {
134          if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
135                          !rayshade(r, r->ro->omod))
# Line 189 | Line 137 | register RAY  *r;
137   }
138  
139  
140 < void
141 < raytrans(r)                     /* transmit ray as is */
142 < register RAY  *r;
140 > extern void
141 > raytrans(                       /* transmit ray as is */
142 >        register RAY  *r
143 > )
144   {
145          RAY  tr;
146  
# Line 204 | Line 153 | register RAY  *r;
153   }
154  
155  
156 < int
157 < rayshade(r, mod)                /* shade ray r with material mod */
158 < register RAY  *r;
159 < int  mod;
156 > extern int
157 > rayshade(               /* shade ray r with material mod */
158 >        register RAY  *r,
159 >        int  mod
160 > )
161   {
162          int  gotmat;
163          register OBJREC  *m;
214 #if  MAXLOOP
215        static int  depth = 0;
216                                        /* check for infinite loop */
217        if (depth++ >= MAXLOOP)
218                objerror(r->ro, USER, "possible modifier loop");
219 #endif
164          r->rt = r->rot;                 /* set effective ray length */
165          for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
166                  m = objptr(mod);
# Line 227 | Line 171 | int  mod;
171                  }
172                  ******/
173                                          /* hack for irradiance calculation */
174 <                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) {
174 >                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
175 >                                m->otype != MAT_CLIP &&
176 >                                (ofun[m->otype].flags & (T_M|T_X))) {
177                          if (irr_ignore(m->otype)) {
232 #if  MAXLOOP
233                                depth--;
234 #endif
178                                  raytrans(r);
179                                  return(1);
180                          }
# Line 241 | Line 184 | int  mod;
184                                          /* materials call raytexture */
185                  gotmat = (*ofun[m->otype].funp)(m, r);
186          }
244 #if  MAXLOOP
245        depth--;
246 #endif
187          return(gotmat);
188   }
189  
190  
191 < void
192 < rayparticipate(r)                       /* compute ray medium participation */
193 < register RAY  *r;
191 > extern void
192 > rayparticipate(                 /* compute ray medium participation */
193 >        register RAY  *r
194 > )
195   {
196          COLOR   ce, ca;
197          double  re, ge, be;
# Line 280 | Line 221 | register RAY  *r;
221   }
222  
223  
224 < raytexture(r, mod)                      /* get material modifiers */
225 < RAY  *r;
226 < int  mod;
224 > extern void
225 > raytexture(                     /* get material modifiers */
226 >        RAY  *r,
227 >        OBJECT  mod
228 > )
229   {
230          register OBJREC  *m;
288 #if  MAXLOOP
289        static int  depth = 0;
290                                        /* check for infinite loop */
291        if (depth++ >= MAXLOOP)
292                objerror(r->ro, USER, "modifier loop");
293 #endif
231                                          /* execute textures and patterns */
232          for ( ; mod != OVOID; mod = m->omod) {
233                  m = objptr(mod);
# Line 306 | Line 243 | int  mod;
243                          objerror(r->ro, USER, errmsg);
244                  }
245          }
309 #if  MAXLOOP
310        depth--;                        /* end here */
311 #endif
246   }
247  
248  
249 < int
250 < raymixture(r, fore, back, coef)         /* mix modifiers */
251 < register RAY  *r;
252 < OBJECT  fore, back;
253 < double  coef;
249 > extern int
250 > raymixture(             /* mix modifiers */
251 >        register RAY  *r,
252 >        OBJECT  fore,
253 >        OBJECT  back,
254 >        double  coef
255 > )
256   {
257          RAY  fr, br;
258          int  foremat, backmat;
# Line 329 | Line 265 | double  coef;
265                                          /* compute foreground and background */
266          foremat = backmat = 0;
267                                          /* foreground */
268 <        copystruct(&fr, r);
268 >        fr = *r;
269          if (coef > FTINY)
270                  foremat = rayshade(&fr, fore);
271                                          /* background */
272 <        copystruct(&br, r);
272 >        br = *r;
273          if (coef < 1.0-FTINY)
274                  backmat = rayshade(&br, back);
275                                          /* check for transparency */
276 <        if (backmat ^ foremat)
276 >        if (backmat ^ foremat) {
277                  if (backmat && coef > FTINY)
278                          raytrans(&fr);
279                  else if (foremat && coef < 1.0-FTINY)
280                          raytrans(&br);
281 +        }
282                                          /* mix perturbations */
283          for (i = 0; i < 3; i++)
284                  r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
# Line 363 | Line 300 | double  coef;
300   }
301  
302  
303 < double
304 < raydist(r, flags)               /* compute (cumulative) ray distance */
305 < register RAY  *r;
306 < register int  flags;
303 > extern double
304 > raydist(                /* compute (cumulative) ray distance */
305 >        register RAY  *r,
306 >        register int  flags
307 > )
308   {
309          double  sum = 0.0;
310  
# Line 378 | Line 316 | register int  flags;
316   }
317  
318  
319 < double
320 < raynormal(norm, r)              /* compute perturbed normal for ray */
321 < FVECT  norm;
322 < register RAY  *r;
319 > extern double
320 > raynormal(              /* compute perturbed normal for ray */
321 >        FVECT  norm,
322 >        register RAY  *r
323 > )
324   {
325          double  newdot;
326          register int  i;
# Line 413 | Line 352 | register RAY  *r;
352   }
353  
354  
355 < void
356 < newrayxf(r)                     /* get new tranformation matrix for ray */
357 < RAY  *r;
355 > extern void
356 > newrayxf(                       /* get new tranformation matrix for ray */
357 >        RAY  *r
358 > )
359   {
360          static struct xfn {
361                  struct xfn  *next;
# Line 450 | Line 390 | RAY  *r;
390   }
391  
392  
393 < void
394 < flipsurface(r)                  /* reverse surface orientation */
395 < register RAY  *r;
393 > extern void
394 > flipsurface(                    /* reverse surface orientation */
395 >        register RAY  *r
396 > )
397   {
398          r->rod = -r->rod;
399          r->ron[0] = -r->ron[0];
# Line 464 | Line 405 | register RAY  *r;
405   }
406  
407  
408 < int
409 < localhit(r, scene)              /* check for hit in the octree */
410 < register RAY  *r;
411 < register CUBE  *scene;
408 > extern void
409 > rayhit(                 /* standard ray hit test */
410 >        OBJECT  *oset,
411 >        RAY  *r
412 > )
413   {
414 +        OBJREC  *o;
415 +        int     i;
416 +
417 +        for (i = oset[0]; i > 0; i--) {
418 +                o = objptr(oset[i]);
419 +                if ((*ofun[o->otype].funp)(o, r))
420 +                        r->robj = oset[i];
421 +        }
422 + }
423 +
424 +
425 + extern int
426 + localhit(               /* check for hit in the octree */
427 +        register RAY  *r,
428 +        register CUBE  *scene
429 + )
430 + {
431          OBJECT  cxset[MAXCSET+1];       /* set of checked objects */
432          FVECT  curpos;                  /* current cube position */
433          int  sflags;                    /* sign flags */
# Line 522 | Line 481 | register CUBE  *scene;
481          }
482          cxset[0] = 0;
483          raymove(curpos, cxset, sflags, r, scene);
484 <        return(r->ro != NULL & r->ro != &Aftplane);
484 >        return((r->ro != NULL) & (r->ro != &Aftplane));
485   }
486  
487  
488   static int
489 < raymove(pos, cxs, dirf, r, cu)          /* check for hit as we move */
490 < FVECT  pos;                     /* current position, modified herein */
491 < OBJECT  *cxs;                   /* checked objects, modified by checkhit */
492 < int  dirf;                      /* direction indicators to speed tests */
493 < register RAY  *r;
494 < register CUBE  *cu;
489 > raymove(                /* check for hit as we move */
490 >        FVECT  pos,                     /* current position, modified herein */
491 >        OBJECT  *cxs,                   /* checked objects, modified by checkhit */
492 >        int  dirf,                      /* direction indicators to speed tests */
493 >        register RAY  *r,
494 >        register CUBE  *cu
495 > )
496   {
497          int  ax;
498          double  dt, t;
# Line 613 | Line 573 | register CUBE  *cu;
573  
574  
575   static int
576 < checkhit(r, cu, cxs)            /* check for hit in full cube */
577 < register RAY  *r;
578 < CUBE  *cu;
579 < OBJECT  *cxs;
576 > checkhit(               /* check for hit in full cube */
577 >        register RAY  *r,
578 >        CUBE  *cu,
579 >        OBJECT  *cxs
580 > )
581   {
582          OBJECT  oset[MAXSET+1];
622        register OBJREC  *o;
623        register int  i;
583  
584          objset(oset, cu->cutree);
585 <        checkset(oset, cxs);                    /* eliminate double-checking */
586 <        for (i = oset[0]; i > 0; i--) {
587 <                o = objptr(oset[i]);
588 <                if ((*ofun[o->otype].funp)(o, r))
589 <                        r->robj = oset[i];
631 <        }
632 <        if (r->ro == NULL)
585 >        checkset(oset, cxs);                    /* avoid double-checking */
586 >
587 >        (*r->hitf)(oset, r);                    /* test for hit in set */
588 >
589 >        if (r->robj == OVOID)
590                  return(0);                      /* no scores yet */
591  
592          return(incube(cu, r->rop));             /* hit OK if in current cube */
# Line 637 | Line 594 | OBJECT  *cxs;
594  
595  
596   static void
597 < checkset(os, cs)                /* modify checked set and set to check */
598 < register OBJECT  *os;                   /* os' = os - cs */
599 < register OBJECT  *cs;                   /* cs' = cs + os */
597 > checkset(               /* modify checked set and set to check */
598 >        register OBJECT  *os,                   /* os' = os - cs */
599 >        register OBJECT  *cs                    /* cs' = cs + os */
600 > )
601   {
602          OBJECT  cset[MAXCSET+MAXSET+1];
603          register int  i, j;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines