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.11 by greg, Thu Jan 13 09:45:11 1994 UTC vs.
Revision 2.20 by greg, Fri Sep 29 10:46:12 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 34 | Line 34 | OBJREC  Lamb = {
34          {0, 5, NULL, Lambfa}, NULL,
35   };                                      /* a Lambertian surface */
36  
37 + OBJREC  Aftplane;                       /* aft clipping plane object */
38 +
39   static int  raymove(), checkset(), checkhit();
40  
41   #define  MAXLOOP        128             /* modifier loop detection */
# Line 67 | Line 69 | double  rw;
69                  r->rweight = ro->rweight * rw;
70                  r->crtype = ro->crtype | (r->rtype = rt);
71                  VCOPY(r->rorg, ro->rop);
72 +                r->rmax = 0.0;
73          }
74          rayclear(r);
75          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
# Line 95 | Line 98 | RAY  *r;
98  
99          if (localhit(r, &thescene))
100                  gotmat = raycont(r);
101 <        else if (sourcehit(r))
101 >        else if (r->ro == &Aftplane) {
102 >                r->ro = NULL;
103 >                r->rot = FHUGE;
104 >        } else if (sourcehit(r))
105                  gotmat = rayshade(r, r->ro->omod);
106  
107 <        if (!gotmat)
107 >        if (r->ro != NULL && !gotmat)
108                  objerror(r->ro, USER, "material not found");
109  
110          if (trace != NULL)
# Line 125 | Line 131 | register RAY  *r;
131  
132          if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
133                  VCOPY(tr.rdir, r->rdir);
134 +                if (r->rmax > FTINY)
135 +                        tr.rmax = r->rmax - r->rot;
136                  rayvalue(&tr);
137                  copycolor(r->rcol, tr.rcol);
138                  r->rt = r->rot + tr.rt;
# Line 156 | Line 164 | int  mod;
164                          if (irr_ignore(m->otype)) {
165                                  depth--;
166                                  raytrans(r);
167 <                                return;
167 >                                return(1);
168                          }
169                          if (!islight(m->otype))
170                                  m = &Lamb;
# Line 187 | Line 195 | int  mod;
195                          error(USER, errmsg);
196                  }
197                  ******/
198 <                if ((*ofun[m->otype].funp)(m, r))
199 <                        objerror(r->ro, USER, "conflicting materials");
198 >                if ((*ofun[m->otype].funp)(m, r)) {
199 >                        sprintf(errmsg, "conflicting material \"%s\"",
200 >                                        m->oname);
201 >                        objerror(r->ro, USER, errmsg);
202 >                }
203          }
204          depth--;                        /* end here */
205   }
# Line 200 | Line 211 | OBJECT  fore, back;
211   double  coef;
212   {
213          RAY  fr, br;
203        COLOR  ctmp;
214          int  foremat, backmat;
215          register int  i;
216                                          /* clip coefficient */
# Line 208 | Line 218 | double  coef;
218                  coef = 1.0;
219          else if (coef < 0.0)
220                  coef = 0.0;
221 +                                        /* compute foreground and background */
222 +        foremat = backmat = -1;
223                                          /* foreground */
224          copystruct(&fr, r);
213        fr.pert[0] = fr.pert[1] = fr.pert[2] = 0.0;
214        setcolor(fr.pcol, 1.0, 1.0, 1.0);
215        setcolor(fr.rcol, 0.0, 0.0, 0.0);
225          if (fore != OVOID && coef > FTINY)
226                  foremat = rayshade(&fr, fore);
218        else
219                foremat = 0;
227                                          /* background */
228          copystruct(&br, r);
222        br.pert[0] = br.pert[1] = br.pert[2] = 0.0;
223        setcolor(br.pcol, 1.0, 1.0, 1.0);
224        setcolor(br.rcol, 0.0, 0.0, 0.0);
229          if (back != OVOID && coef < 1.0-FTINY)
230                  backmat = rayshade(&br, back);
227        else
228                backmat = foremat;
231                                          /* check */
232 <        if ((backmat==0) != (foremat==0))
232 >        if (foremat < 0)
233 >                if (backmat < 0)
234 >                        foremat = backmat = 0;
235 >                else
236 >                        foremat = backmat;
237 >        else if (backmat < 0)
238 >                backmat = foremat;
239 >        if ((foremat==0) != (backmat==0))
240                  objerror(r->ro, USER, "mixing material with non-material");
241 <                                        /* sum perturbations */
241 >                                        /* mix perturbations */
242          for (i = 0; i < 3; i++)
243 <                r->pert[i] += coef*fr.pert[i] + (1.0-coef)*br.pert[i];
244 <                                        /* multiply pattern colors */
243 >                r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
244 >                                        /* mix pattern colors */
245          scalecolor(fr.pcol, coef);
246          scalecolor(br.pcol, 1.0-coef);
247 <        copycolor(ctmp, fr.pcol);
248 <        addcolor(ctmp, br.pcol);
249 <        multcolor(r->pcol, ctmp);
250 <                                        /* sum returned ray values */
251 <        scalecolor(fr.rcol, coef);
252 <        scalecolor(br.rcol, 1.0-coef);
253 <        addcolor(r->rcol, fr.rcol);
254 <        addcolor(r->rcol, br.rcol);
246 <        if (foremat)
247 >        copycolor(r->pcol, fr.pcol);
248 >        addcolor(r->pcol, br.pcol);
249 >                                        /* mix returned ray values */
250 >        if (foremat) {
251 >                scalecolor(fr.rcol, coef);
252 >                scalecolor(br.rcol, 1.0-coef);
253 >                copycolor(r->rcol, fr.rcol);
254 >                addcolor(r->rcol, br.rcol);
255                  r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
256 +        }
257                                          /* return value tells if material */
258          return(foremat);
259   }
# Line 355 | Line 364 | register CUBE  *scene;
364          }
365          if (sflags == 0)
366                  error(CONSISTENCY, "zero ray direction in localhit");
367 +                                        /* start off assuming nothing hit */
368 +        if (r->rmax > FTINY) {          /* except aft plane if one */
369 +                r->ro = &Aftplane;
370 +                r->rot = r->rmax;
371 +                for (i = 0; i < 3; i++)
372 +                        r->rop[i] = r->rorg[i] + r->rot*r->rdir[i];
373 +        }
374 +                                        /* find global cube entrance point */
375          t = 0.0;
376          if (!incube(scene, curpos)) {
377                                          /* find distance to entry */
# Line 372 | Line 389 | register CUBE  *scene;
389                                  t = dt; /* farthest face is the one */
390                  }
391                  t += FTINY;             /* fudge to get inside cube */
392 +                if (t >= r->rot)        /* clipped already */
393 +                        return(0);
394                                          /* advance position */
395                  for (i = 0; i < 3; i++)
396                          curpos[i] += r->rdir[i]*t;
# Line 380 | Line 399 | register CUBE  *scene;
399                          return(0);
400          }
401          cxset[0] = 0;
402 <        return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT);
402 >        raymove(curpos, cxset, sflags, r, scene);
403 >        return(r->ro != NULL & r->ro != &Aftplane);
404   }
405  
406  
# Line 435 | Line 455 | register CUBE  *cu;
455                  }
456                  /*NOTREACHED*/
457          }
458 <        if (isfull(cu->cutree) && checkhit(r, cu, cxs))
458 >        if (isfull(cu->cutree)) {
459 >                if (checkhit(r, cu, cxs))
460 >                        return(RAYHIT);
461 >        } else if (r->ro == &Aftplane && incube(cu, r->rop))
462                  return(RAYHIT);
463                                          /* advance to next cube */
464          if (dirf&0x11) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines