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.27 by greg, Wed Apr 24 16:27:56 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 196 | Line 189 | rayparticipate(r)                      /* compute ray medium participatio
189   register RAY  *r;
190   {
191          COLOR   ce, ca;
199        double  dist;
192          double  re, ge, be;
193  
194          if (intens(r->cext) <= 1./FHUGE)
195                  return;                         /* no medium */
196 <        if ((dist = r->rot) >= FHUGE)
197 <                dist = 2.*thescene.cusize;      /* what to use for infinity? */
198 <        if (r->crtype & SHADOW)
199 <                dist *= 1. - salbedo;           /* no scattering for sources */
200 <        if (dist <= FTINY)
201 <                return;                         /* no effective ray travel */
202 <        re = dist*colval(r->cext,RED);
203 <        ge = dist*colval(r->cext,GRN);
204 <        be = dist*colval(r->cext,BLU);
205 <        setcolor(ce,    re>92. ? 0. : exp(-re),
206 <                        ge>92. ? 0. : exp(-ge),
215 <                        be>92. ? 0. : exp(-be));
196 >        re = r->rot*colval(r->cext,RED);
197 >        ge = r->rot*colval(r->cext,GRN);
198 >        be = r->rot*colval(r->cext,BLU);
199 >        if (r->crtype & SHADOW) {               /* no scattering for sources */
200 >                re *= 1. - colval(r->albedo,RED);
201 >                ge *= 1. - colval(r->albedo,GRN);
202 >                be *= 1. - colval(r->albedo,BLU);
203 >        }
204 >        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
205 >                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
206 >                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
207          multcolor(r->rcol, ce);                 /* path absorption */
208 <        if (r->albedo <= FTINY || r->crtype & SHADOW)
208 >        if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
209                  return;                         /* no scattering */
210 <        setcolor(ca,    salbedo*colval(ambval,RED)*(1.-colval(ce,RED)),
211 <                        salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)),
212 <                        salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU)));
210 >        setcolor(ca,
211 >                colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
212 >                colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
213 >                colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
214          addcolor(r->rcol, ca);                  /* ambient in scattering */
215          srcscatter(r);                          /* source in scattering */
216   }
# Line 260 | Line 252 | double  coef;
252          RAY  fr, br;
253          int  foremat, backmat;
254          register int  i;
255 <                                        /* clip coefficient */
255 >                                        /* bound coefficient */
256          if (coef > 1.0)
257                  coef = 1.0;
258          else if (coef < 0.0)
259                  coef = 0.0;
260                                          /* compute foreground and background */
261 <        foremat = backmat = -1;
261 >        foremat = backmat = 0;
262                                          /* foreground */
263          copystruct(&fr, r);
264 <        if (fore != OVOID && coef > FTINY)
264 >        if (coef > FTINY)
265                  foremat = rayshade(&fr, fore);
266                                          /* background */
267          copystruct(&br, r);
268 <        if (back != OVOID && coef < 1.0-FTINY)
268 >        if (coef < 1.0-FTINY)
269                  backmat = rayshade(&br, back);
270 <                                        /* check */
271 <        if (foremat < 0)
272 <                if (backmat < 0)
273 <                        foremat = backmat = 0;
270 >                                        /* check for transparency */
271 >        if (backmat ^ foremat)
272 >                if (backmat)
273 >                        raytrans(&fr);
274                  else
275 <                        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");
275 >                        raytrans(&br);
276                                          /* mix perturbations */
277          for (i = 0; i < 3; i++)
278                  r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
# Line 293 | Line 281 | double  coef;
281          scalecolor(br.pcol, 1.0-coef);
282          copycolor(r->pcol, fr.pcol);
283          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        }
284                                          /* return value tells if material */
285 <        return(foremat);
285 >        if (!foremat & !backmat)
286 >                return(0);
287 >                                        /* mix returned ray values */
288 >        scalecolor(fr.rcol, coef);
289 >        scalecolor(br.rcol, 1.0-coef);
290 >        copycolor(r->rcol, fr.rcol);
291 >        addcolor(r->rcol, br.rcol);
292 >        r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
293 >        return(1);
294   }
295  
296  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines