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.19 by greg, Thu Jan 26 15:34:55 1995 UTC vs.
Revision 2.26 by greg, Wed Apr 17 14:06:35 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 24 | Line 24 | extern CUBE  thescene;                 /* our scene */
24   extern int  maxdepth;                   /* maximum recursion depth */
25   extern double  minweight;               /* minimum ray weight */
26   extern int  do_irrad;                   /* compute irradiance? */
27 + extern COLOR  ambval;                   /* ambient value */
28  
29 + extern COLOR  cextinction;              /* global extinction coefficient */
30 + extern COLOR  salbedo;                  /* global scattering albedo */
31 + extern double  seccg;                   /* global scattering eccentricity */
32 + extern double  ssampdist;               /* scatter sampling distance */
33 +
34   unsigned long  raynum = 0;              /* next unique ray number */
35   unsigned long  nrays = 0;               /* number of calls to localhit */
36  
# Line 55 | Line 61 | double  rw;
61                  r->rsrc = -1;
62                  r->clipset = NULL;
63                  r->revf = raytrace;
64 +                copycolor(r->cext, cextinction);
65 +                copycolor(r->albedo, salbedo);
66 +                r->gecc = seccg;
67 +                r->slights = NULL;
68          } else {                                /* spawned ray */
69                  r->rlvl = ro->rlvl;
70                  if (rt & RAYREFL) {
71                          r->rlvl++;
72                          r->rsrc = -1;
73                          r->clipset = ro->clipset;
74 +                        r->rmax = 0.0;
75                  } else {
76                          r->rsrc = ro->rsrc;
77                          r->clipset = ro->newcset;
78 +                        r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
79                  }
80                  r->revf = ro->revf;
81 +                copycolor(r->cext, ro->cext);
82 +                copycolor(r->albedo, ro->albedo);
83 +                r->gecc = ro->gecc;
84 +                r->slights = ro->slights;
85                  r->rweight = ro->rweight * rw;
86                  r->crtype = ro->crtype | (r->rtype = rt);
87                  VCOPY(r->rorg, ro->rop);
72                r->rmax = 0.0;
88          }
89          rayclear(r);
90          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
# Line 94 | Line 109 | raytrace(r)                    /* trace a ray and compute its value */
109   RAY  *r;
110   {
111          extern int  (*trace)();
97        int  gotmat;
112  
113          if (localhit(r, &thescene))
114 <                gotmat = raycont(r);
114 >                raycont(r);             /* hit local surface, evaluate */
115          else if (r->ro == &Aftplane) {
116 <                r->ro = NULL;
116 >                r->ro = NULL;           /* hit aft clipping plane */
117                  r->rot = FHUGE;
118          } else if (sourcehit(r))
119 <                gotmat = rayshade(r, r->ro->omod);
119 >                rayshade(r, r->ro->omod);       /* distant source */
120  
121 <        if (r->ro != NULL && !gotmat)
108 <                objerror(r->ro, USER, "material not found");
121 >        rayparticipate(r);              /* for participating medium */
122  
123          if (trace != NULL)
124                  (*trace)(r);            /* trace execution */
# Line 116 | Line 129 | raycont(r)                     /* check for clipped object and continue
129   register RAY  *r;
130   {
131          if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
132 <                        r->ro->omod == OVOID) {
132 >                        !rayshade(r, r->ro->omod))
133                  raytrans(r);
121                return(1);
122        }
123        return(rayshade(r, r->ro->omod));
134   }
135  
136  
# Line 131 | Line 141 | register RAY  *r;
141  
142          if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
143                  VCOPY(tr.rdir, r->rdir);
134                if (r->rmax > FTINY)
135                        tr.rmax = r->rmax - r->rot;
144                  rayvalue(&tr);
145                  copycolor(r->rcol, tr.rcol);
146                  r->rt = r->rot + tr.rt;
# Line 177 | Line 185 | int  mod;
185   }
186  
187  
188 + rayparticipate(r)                       /* compute ray medium participation */
189 + register RAY  *r;
190 + {
191 +        COLOR   ce, ca;
192 +        double  dist;
193 +        double  re, ge, be;
194 +
195 +        if (intens(r->cext) <= 1./FHUGE)
196 +                return;                         /* no medium */
197 +        if ((dist = r->rot) >= FHUGE)
198 +                dist = 2.*thescene.cusize;      /* what to use for infinity? */
199 +        re = dist*colval(r->cext,RED);
200 +        ge = dist*colval(r->cext,GRN);
201 +        be = dist*colval(r->cext,BLU);
202 +        if (r->crtype & SHADOW) {               /* no scattering for sources */
203 +                re *= 1. - colval(r->albedo,RED);
204 +                ge *= 1. - colval(r->albedo,GRN);
205 +                be *= 1. - colval(r->albedo,BLU);
206 +        }
207 +        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
208 +                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
209 +                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
210 +        multcolor(r->rcol, ce);                 /* path absorption */
211 +        if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
212 +                return;                         /* no scattering */
213 +        setcolor(ca,
214 +                colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
215 +                colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
216 +                colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
217 +        addcolor(r->rcol, ca);                  /* ambient in scattering */
218 +        srcscatter(r);                          /* source in scattering */
219 + }
220 +
221 +
222   raytexture(r, mod)                      /* get material modifiers */
223   RAY  *r;
224   int  mod;
# Line 195 | Line 237 | int  mod;
237                          error(USER, errmsg);
238                  }
239                  ******/
240 <                if ((*ofun[m->otype].funp)(m, r))
241 <                        objerror(r->ro, USER, "conflicting materials");
240 >                if ((*ofun[m->otype].funp)(m, r)) {
241 >                        sprintf(errmsg, "conflicting material \"%s\"",
242 >                                        m->oname);
243 >                        objerror(r->ro, USER, errmsg);
244 >                }
245          }
246          depth--;                        /* end here */
247   }
# Line 210 | Line 255 | double  coef;
255          RAY  fr, br;
256          int  foremat, backmat;
257          register int  i;
258 <                                        /* clip coefficient */
258 >                                        /* bound coefficient */
259          if (coef > 1.0)
260                  coef = 1.0;
261          else if (coef < 0.0)
262                  coef = 0.0;
263                                          /* compute foreground and background */
264 <        foremat = backmat = -1;
264 >        foremat = backmat = 0;
265                                          /* foreground */
266          copystruct(&fr, r);
267 <        if (fore != OVOID && coef > FTINY)
267 >        if (coef > FTINY)
268                  foremat = rayshade(&fr, fore);
269                                          /* background */
270          copystruct(&br, r);
271 <        if (back != OVOID && coef < 1.0-FTINY)
271 >        if (coef < 1.0-FTINY)
272                  backmat = rayshade(&br, back);
273 <                                        /* check */
274 <        if (foremat < 0)
275 <                if (backmat < 0)
276 <                        foremat = backmat = 0;
273 >                                        /* check for transparency */
274 >        if (backmat ^ foremat)
275 >                if (backmat)
276 >                        raytrans(&fr);
277                  else
278 <                        foremat = backmat;
234 <        else if (backmat < 0)
235 <                backmat = foremat;
236 <        if ((foremat==0) != (backmat==0))
237 <                objerror(r->ro, USER, "mixing material with non-material");
278 >                        raytrans(&br);
279                                          /* mix perturbations */
280          for (i = 0; i < 3; i++)
281                  r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
# Line 243 | Line 284 | double  coef;
284          scalecolor(br.pcol, 1.0-coef);
285          copycolor(r->pcol, fr.pcol);
286          addcolor(r->pcol, br.pcol);
287 +                                        /* return value tells if material */
288 +        if (!foremat & !backmat)
289 +                return(0);
290                                          /* mix returned ray values */
291 <        if (foremat) {
292 <                scalecolor(fr.rcol, coef);
293 <                scalecolor(br.rcol, 1.0-coef);
294 <                copycolor(r->rcol, fr.rcol);
295 <                addcolor(r->rcol, br.rcol);
296 <                r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
291 >        scalecolor(fr.rcol, coef);
292 >        scalecolor(br.rcol, 1.0-coef);
293 >        copycolor(r->rcol, fr.rcol);
294 >        addcolor(r->rcol, br.rcol);
295 >        r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
296 >        return(1);
297 > }
298 >
299 >
300 > double
301 > raydist(r, flags)               /* compute (cumulative) ray distance */
302 > register RAY  *r;
303 > register int  flags;
304 > {
305 >        double  sum = 0.0;
306 >
307 >        while (r != NULL && r->crtype&flags) {
308 >                sum += r->rot;
309 >                r = r->parent;
310          }
311 <                                        /* return value tells if material */
255 <        return(foremat);
311 >        return(sum);
312   }
313  
314  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines