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.22 by greg, Wed Dec 6 12:07:50 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 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) {
# Line 68 | Line 78 | double  rw;
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);
# Line 95 | Line 109 | raytrace(r)                    /* trace a ray and compute its value */
109   RAY  *r;
110   {
111          extern int  (*trace)();
98        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)
109 <                objerror(r->ro, USER, "material not found");
121 >        rayparticipate(r);              /* for participating medium */
122  
123          if (trace != NULL)
124                  (*trace)(r);            /* trace execution */
# Line 117 | 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);
122                return(1);
123        }
124        return(rayshade(r, r->ro->omod));
134   }
135  
136  
# Line 176 | 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  re, ge, be;
193 +
194 +        if (intens(r->cext) <= 1./FHUGE)
195 +                return;                         /* no medium */
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->crtype & SHADOW || intens(r->albedo) <= FTINY)
209 +                return;                         /* no scattering */
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 + }
217 +
218 +
219   raytexture(r, mod)                      /* get material modifiers */
220   RAY  *r;
221   int  mod;
# Line 212 | 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;
236 <        else if (backmat < 0)
237 <                backmat = foremat;
238 <        if ((foremat==0) != (backmat==0))
239 <                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 245 | Line 281 | double  coef;
281          scalecolor(br.pcol, 1.0-coef);
282          copycolor(r->pcol, fr.pcol);
283          addcolor(r->pcol, br.pcol);
248                                        /* mix returned ray values */
249        if (foremat) {
250                scalecolor(fr.rcol, coef);
251                scalecolor(br.rcol, 1.0-coef);
252                copycolor(r->rcol, fr.rcol);
253                addcolor(r->rcol, br.rcol);
254                r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
255        }
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