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.23 by greg, Fri Dec 8 18:49:09 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 27 | Line 27 | extern int  do_irrad;                  /* compute irradiance? */
27   extern COLOR  ambval;                   /* ambient value */
28  
29   extern COLOR  cextinction;              /* global extinction coefficient */
30 < extern double  salbedo;                 /* global scattering albedo */
30 > extern COLOR  salbedo;                  /* global scattering albedo */
31   extern double  seccg;                   /* global scattering eccentricity */
32   extern double  ssampdist;               /* scatter sampling distance */
33  
# Line 62 | Line 62 | double  rw;
62                  r->clipset = NULL;
63                  r->revf = raytrace;
64                  copycolor(r->cext, cextinction);
65 <                r->albedo = salbedo;
65 >                copycolor(r->albedo, salbedo);
66                  r->gecc = seccg;
67                  r->slights = NULL;
68          } else {                                /* spawned ray */
# Line 79 | Line 79 | double  rw;
79                  }
80                  r->revf = ro->revf;
81                  copycolor(r->cext, ro->cext);
82 <                r->albedo = ro->albedo;
82 >                copycolor(r->albedo, ro->albedo);
83                  r->gecc = ro->gecc;
84                  r->slights = ro->slights;
85                  r->rweight = ro->rweight * rw;
# Line 109 | Line 109 | raytrace(r)                    /* trace a ray and compute its value */
109   RAY  *r;
110   {
111          extern int  (*trace)();
112        int  gotmat;
112  
113          if (localhit(r, &thescene))
114 <                gotmat = raycont(r);    /* hit local surface, evaluate */
114 >                raycont(r);             /* hit local surface, evaluate */
115          else if (r->ro == &Aftplane) {
116                  r->ro = NULL;           /* hit aft clipping plane */
117                  r->rot = FHUGE;
118          } else if (sourcehit(r))
119 <                gotmat = rayshade(r, r->ro->omod);      /* distant source */
119 >                rayshade(r, r->ro->omod);       /* distant source */
120  
122        if (r->ro != NULL && !gotmat)
123                objerror(r->ro, USER, "material not found");
124
121          rayparticipate(r);              /* for participating medium */
122  
123          if (trace != NULL)
# Line 133 | 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);
138                return(1);
139        }
140        return(rayshade(r, r->ro->omod));
134   }
135  
136  
# Line 203 | Line 196 | register RAY  *r;
196                  return;                         /* no medium */
197          if ((dist = r->rot) >= FHUGE)
198                  dist = 2.*thescene.cusize;      /* what to use for infinity? */
206        if (r->crtype & SHADOW)
207                dist *= 1. - salbedo;           /* no scattering for sources */
208        if (dist <= FTINY)
209                return;                         /* no effective ray travel */
199          re = dist*colval(r->cext,RED);
200          ge = dist*colval(r->cext,GRN);
201          be = dist*colval(r->cext,BLU);
202 <        setcolor(ce,    re>92. ? 0. : exp(-re),
203 <                        ge>92. ? 0. : exp(-ge),
204 <                        be>92. ? 0. : exp(-be));
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->albedo <= FTINY || r->crtype & SHADOW)
211 >        if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
212                  return;                         /* no scattering */
213 <        setcolor(ca,    salbedo*colval(ambval,RED)*(1.-colval(ce,RED)),
214 <                        salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)),
215 <                        salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU)));
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   }
# Line 260 | 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;
284 <        else if (backmat < 0)
285 <                backmat = foremat;
286 <        if ((foremat==0) != (backmat==0))
287 <                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 293 | Line 284 | double  coef;
284          scalecolor(br.pcol, 1.0-coef);
285          copycolor(r->pcol, fr.pcol);
286          addcolor(r->pcol, br.pcol);
296                                        /* mix returned ray values */
297        if (foremat) {
298                scalecolor(fr.rcol, coef);
299                scalecolor(br.rcol, 1.0-coef);
300                copycolor(r->rcol, fr.rcol);
301                addcolor(r->rcol, br.rcol);
302                r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
303        }
287                                          /* return value tells if material */
288 <        return(foremat);
288 >        if (!foremat & !backmat)
289 >                return(0);
290 >                                        /* mix returned ray values */
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines