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.3 by greg, Tue Jan 26 09:28:00 1993 UTC vs.
Revision 2.12 by greg, Thu Jan 13 10:43:34 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 25 | Line 25 | extern int  maxdepth;                  /* maximum recursion depth */
25   extern double  minweight;               /* minimum ray weight */
26   extern int  do_irrad;                   /* compute irradiance? */
27  
28 < long  raynum = 0L;                      /* next unique ray number */
29 < long  nrays = 0L;                       /* number of calls to localhit */
28 > unsigned long  raynum = 0;              /* next unique ray number */
29 > unsigned long  nrays = 0;               /* number of calls to localhit */
30  
31   static FLOAT  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
32   OBJREC  Lamb = {
# Line 34 | Line 34 | OBJREC  Lamb = {
34          {0, 5, NULL, Lambfa}, NULL,
35   };                                      /* a Lambertian surface */
36  
37 + static int  raymove(), checkset(), checkhit();
38 +
39   #define  MAXLOOP        128             /* modifier loop detection */
40  
41   #define  RAYHIT         (-1)            /* return value for intercepted ray */
# Line 89 | Line 91 | raytrace(r)                    /* trace a ray and compute its value */
91   RAY  *r;
92   {
93          extern int  (*trace)();
94 +        int  gotmat;
95  
96          if (localhit(r, &thescene))
97 <                raycont(r);
97 >                gotmat = raycont(r);
98          else if (sourcehit(r))
99 <                rayshade(r, r->ro->omod);
99 >                gotmat = rayshade(r, r->ro->omod);
100  
101 +        if (!gotmat)
102 +                objerror(r->ro, USER, "material not found");
103 +
104          if (trace != NULL)
105                  (*trace)(r);            /* trace execution */
106   }
# Line 103 | Line 109 | RAY  *r;
109   raycont(r)                      /* check for clipped object and continue */
110   register RAY  *r;
111   {
112 <        if (r->clipset != NULL && inset(r->clipset, r->ro->omod))
112 >        if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
113 >                        r->ro->omod == OVOID) {
114                  raytrans(r);
115 <        else
116 <                rayshade(r, r->ro->omod);
115 >                return(1);
116 >        }
117 >        return(rayshade(r, r->ro->omod));
118   }
119  
120  
# Line 129 | Line 137 | register RAY  *r;
137   int  mod;
138   {
139          static int  depth = 0;
140 +        int  gotmat;
141          register OBJREC  *m;
142                                          /* check for infinite loop */
143          if (depth++ >= MAXLOOP)
144                  objerror(r->ro, USER, "possible modifier loop");
145          r->rt = r->rot;                 /* set effective ray length */
146 <        for ( ; mod != OVOID; mod = m->omod) {
146 >        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
147                  m = objptr(mod);
148                  /****** unnecessary test since modifier() is always called
149                  if (!ismodifier(m->otype)) {
# Line 152 | Line 161 | int  mod;
161                          if (!islight(m->otype))
162                                  m = &Lamb;
163                  }
164 <                (*ofun[m->otype].funp)(m, r);   /* execute function */
165 <                if (ismaterial(m->otype)) {     /* materials call raytexture */
157 <                        depth--;
158 <                        return;         /* we're done */
159 <                }
164 >                                        /* materials call raytexture */
165 >                gotmat = (*ofun[m->otype].funp)(m, r);
166          }
167 <        objerror(r->ro, USER, "material not found");
167 >        depth--;
168 >        return(gotmat);
169   }
170  
171  
# Line 174 | Line 181 | int  mod;
181                                          /* execute textures and patterns */
182          for ( ; mod != OVOID; mod = m->omod) {
183                  m = objptr(mod);
184 <                if (!istexture(m->otype)) {
184 >                /****** unnecessary test since modifier() is always called
185 >                if (!ismodifier(m->otype)) {
186                          sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
187                          error(USER, errmsg);
188                  }
189 <                (*ofun[m->otype].funp)(m, r);
189 >                ******/
190 >                if ((*ofun[m->otype].funp)(m, r))
191 >                        objerror(r->ro, USER, "conflicting materials");
192          }
193          depth--;                        /* end here */
194   }
# Line 189 | Line 199 | register RAY  *r;
199   OBJECT  fore, back;
200   double  coef;
201   {
202 <        FVECT  curpert, forepert, backpert;
203 <        COLOR  curpcol, forepcol, backpcol;
202 >        RAY  fr, br;
203 >        int  foremat, backmat;
204          register int  i;
205                                          /* clip coefficient */
206          if (coef > 1.0)
207                  coef = 1.0;
208          else if (coef < 0.0)
209                  coef = 0.0;
210 <                                        /* save current mods */
211 <        VCOPY(curpert, r->pert);
202 <        copycolor(curpcol, r->pcol);
203 <                                        /* compute new mods */
204 <                                                /* foreground */
205 <        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
206 <        setcolor(r->pcol, 1.0, 1.0, 1.0);
210 >                                        /* foreground */
211 >        copystruct(&fr, r);
212          if (fore != OVOID && coef > FTINY)
213 <                raytexture(r, fore);
214 <        VCOPY(forepert, r->pert);
215 <        copycolor(forepcol, r->pcol);
216 <                                                /* background */
217 <        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
213 <        setcolor(r->pcol, 1.0, 1.0, 1.0);
213 >                foremat = rayshade(&fr, fore);
214 >        else
215 >                foremat = 0;
216 >                                        /* background */
217 >        copystruct(&br, r);
218          if (back != OVOID && coef < 1.0-FTINY)
219 <                raytexture(r, back);
220 <        VCOPY(backpert, r->pert);
221 <        copycolor(backpcol, r->pcol);
222 <                                        /* sum perturbations */
219 >                backmat = rayshade(&br, back);
220 >        else
221 >                backmat = foremat;
222 >                                        /* check */
223 >        if ((foremat==0) != (backmat==0))
224 >                objerror(r->ro, USER, "mixing material with non-material");
225 >                                        /* mix perturbations */
226          for (i = 0; i < 3; i++)
227 <                r->pert[i] = curpert[i] + coef*forepert[i] +
228 <                                (1.0-coef)*backpert[i];
229 <                                        /* multiply colors */
230 <        setcolor(r->pcol, coef*colval(forepcol,RED) +
231 <                                (1.0-coef)*colval(backpcol,RED),
232 <                        coef*colval(forepcol,GRN) +
233 <                                (1.0-coef)*colval(backpcol,GRN),
234 <                        coef*colval(forepcol,BLU) +
235 <                                (1.0-coef)*colval(backpcol,BLU));
236 <        multcolor(r->pcol, curpcol);
227 >                r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
228 >                                        /* mix pattern colors */
229 >        scalecolor(fr.pcol, coef);
230 >        scalecolor(br.pcol, 1.0-coef);
231 >        copycolor(r->pcol, fr.pcol);
232 >        addcolor(r->pcol, br.pcol);
233 >                                        /* mix returned ray values */
234 >        if (foremat) {
235 >                scalecolor(fr.rcol, coef);
236 >                scalecolor(br.rcol, 1.0-coef);
237 >                copycolor(r->rcol, fr.rcol);
238 >                addcolor(r->rcol, br.rcol);
239 >                r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
240 >        }
241 >                                        /* return value tells if material */
242 >        return(foremat);
243   }
244  
245  
# Line 328 | Line 341 | register CUBE  *scene;
341          sflags = 0;
342          for (i = 0; i < 3; i++) {
343                  curpos[i] = r->rorg[i];
344 <                if (r->rdir[i] > FTINY)
344 >                if (r->rdir[i] > 1e-7)
345                          sflags |= 1 << i;
346 <                else if (r->rdir[i] < -FTINY)
346 >                else if (r->rdir[i] < -1e-7)
347                          sflags |= 0x10 << i;
348          }
349          if (sflags == 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines