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.24 by greg, Thu Mar 21 15:33:05 1996 UTC vs.
Revision 2.32 by gwlarson, Thu Aug 6 10:30:38 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# 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 54 | Line 54 | register RAY  *r, *ro;
54   int  rt;
55   double  rw;
56   {
57 +        double  re;
58 +
59          if ((r->parent = ro) == NULL) {         /* primary ray */
60                  r->rlvl = 0;
61                  r->rweight = rw;
# Line 62 | Line 64 | double  rw;
64                  r->clipset = NULL;
65                  r->revf = raytrace;
66                  copycolor(r->cext, cextinction);
67 <                r->albedo = salbedo;
67 >                copycolor(r->albedo, salbedo);
68                  r->gecc = seccg;
69                  r->slights = NULL;
70          } else {                                /* spawned ray */
# Line 79 | Line 81 | double  rw;
81                  }
82                  r->revf = ro->revf;
83                  copycolor(r->cext, ro->cext);
84 <                r->albedo = ro->albedo;
84 >                copycolor(r->albedo, ro->albedo);
85                  r->gecc = ro->gecc;
86                  r->slights = ro->slights;
85                r->rweight = ro->rweight * rw;
87                  r->crtype = ro->crtype | (r->rtype = rt);
88                  VCOPY(r->rorg, ro->rop);
89 +                r->rweight = ro->rweight * rw;
90 +                                                /* estimate absorption */
91 +                re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
92 +                                colval(ro->cext,RED) : colval(ro->cext,GRN);
93 +                if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
94 +                if (re > 0.)
95 +                        r->rweight *= exp(-re*ro->rot);
96          }
97          rayclear(r);
98          return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
# Line 96 | Line 104 | register RAY  *r;
104   {
105          r->rno = raynum++;
106          r->newcset = r->clipset;
107 +        r->robj = OVOID;
108          r->ro = NULL;
109 <        r->rot = FHUGE;
109 >        r->rt = r->rot = FHUGE;
110          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
111          setcolor(r->pcol, 1.0, 1.0, 1.0);
112          setcolor(r->rcol, 0.0, 0.0, 0.0);
104        r->rt = 0.0;
113   }
114  
115  
# Line 189 | Line 197 | rayparticipate(r)                      /* compute ray medium participatio
197   register RAY  *r;
198   {
199          COLOR   ce, ca;
192        double  dist;
200          double  re, ge, be;
201  
202          if (intens(r->cext) <= 1./FHUGE)
203                  return;                         /* no medium */
204 <        if ((dist = r->rot) >= FHUGE)
205 <                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 */
210 <        re = dist*colval(r->cext,RED);
211 <        ge = dist*colval(r->cext,GRN);
212 <        be = dist*colval(r->cext,BLU);
213 <        setcolor(ce,    re>92. ? 0. : exp(-re),
214 <                        ge>92. ? 0. : exp(-ge),
208 <                        be>92. ? 0. : exp(-be));
204 >        re = r->rot*colval(r->cext,RED);
205 >        ge = r->rot*colval(r->cext,GRN);
206 >        be = r->rot*colval(r->cext,BLU);
207 >        if (r->crtype & SHADOW) {               /* no scattering for sources */
208 >                re *= 1. - colval(r->albedo,RED);
209 >                ge *= 1. - colval(r->albedo,GRN);
210 >                be *= 1. - colval(r->albedo,BLU);
211 >        }
212 >        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
213 >                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
214 >                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
215          multcolor(r->rcol, ce);                 /* path absorption */
216 <        if (r->albedo <= FTINY || r->crtype & SHADOW)
216 >        if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
217                  return;                         /* no scattering */
218 <        setcolor(ca,    salbedo*colval(ambval,RED)*(1.-colval(ce,RED)),
219 <                        salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)),
220 <                        salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU)));
218 >        setcolor(ca,
219 >                colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
220 >                colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
221 >                colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
222          addcolor(r->rcol, ca);                  /* ambient in scattering */
223          srcscatter(r);                          /* source in scattering */
224   }
# Line 270 | Line 277 | double  coef;
277                  backmat = rayshade(&br, back);
278                                          /* check for transparency */
279          if (backmat ^ foremat)
280 <                if (backmat)
280 >                if (!foremat && coef > FTINY)
281                          raytrans(&fr);
282 <                else
282 >                else if (!backmat && coef < 1.0-FTINY)
283                          raytrans(&br);
284                                          /* mix perturbations */
285          for (i = 0; i < 3; i++)
# Line 555 | Line 562 | OBJECT  *cxs;
562          checkset(oset, cxs);                    /* eliminate double-checking */
563          for (i = oset[0]; i > 0; i--) {
564                  o = objptr(oset[i]);
565 <                (*ofun[o->otype].funp)(o, r);
565 >                if ((*ofun[o->otype].funp)(o, r))
566 >                        r->robj = oset[i];
567          }
568          if (r->ro == NULL)
569                  return(0);                      /* no scores yet */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines