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.65 by greg, Wed Feb 19 14:12:48 2014 UTC vs.
Revision 2.81 by greg, Sun Mar 29 18:21:57 2020 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include  "otypes.h"
15   #include  "otspecial.h"
16   #include  "random.h"
17 + #include  "pmap.h"
18  
19   #define  MAXCSET        ((MAXSET+1)*2-1)        /* maximum check set size */
20  
# Line 50 | Line 51 | rayorigin(             /* start new ray from old one */
51                  setcolor(r->rcoef, 1., 1., 1.);
52          } else {
53                  rw = intens(rc);
54 +                if (rw > 1.0)
55 +                        rw = 1.0;               /* avoid calculation growth */
56                  if (rc != r->rcoef)
57                          copycolor(r->rcoef, rc);
58          }
# Line 65 | Line 68 | rayorigin(             /* start new ray from old one */
68                  r->gecc = seccg;
69                  r->slights = NULL;
70          } else {                                /* spawned ray */
71 <                if (ro->rot >= FHUGE) {
71 >                if (ro->rot >= FHUGE*.99) {
72                          memset(r, 0, sizeof(RAY));
73                          return(-1);             /* illegal continuation */
74                  }
# Line 106 | Line 109 | rayorigin(             /* start new ray from old one */
109                  return(-1);
110          if (r->crtype & SHADOW)                 /* shadow commitment */
111                  return(0);
112 <        if (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
112 >                                                /* ambient in photon map? */
113 >        if (ro != NULL && ro->crtype & AMBIENT) {
114 >                if (causticPhotonMapping)
115 >                        return(-1);
116 >                if (photonMapping && rt != TRANS)
117 >                        return(-1);
118 >        }
119 >        if ((maxdepth <= 0) & (rc != NULL)) {   /* Russian roulette */
120                  if (minweight <= 0.0)
121                          error(USER, "zero ray weight in Russian roulette");
122 <                if (maxdepth < 0 && r->rlvl > -maxdepth)
122 >                if ((maxdepth < 0) & (r->rlvl > -maxdepth))
123                          return(-1);             /* upper reflection limit */
124                  if (r->rweight >= minweight)
125                          return(0);
# Line 120 | Line 130 | rayorigin(             /* start new ray from old one */
130                  r->rweight = minweight;
131                  return(0);
132          }
133 <        return(r->rweight >= minweight && r->rlvl <= abs(maxdepth) ? 0 : -1);
133 >        return((r->rweight >= minweight) & (r->rlvl <= abs(maxdepth)) ? 0 : -1);
134   }
135  
136  
# Line 135 | Line 145 | rayclear(                      /* clear a ray for (re)evaluation */
145          r->robj = OVOID;
146          r->ro = NULL;
147          r->rox = NULL;
148 <        r->rt = r->rot = FHUGE;
148 >        r->rxt = r->rmt = r->rot = FHUGE;
149 >        VCOPY(r->rop, r->rorg);
150          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
151 +        r->rflips = 0;
152          r->uv[0] = r->uv[1] = 0.0;
153          setcolor(r->pcol, 1.0, 1.0, 1.0);
154 +        setcolor(r->mcol, 0.0, 0.0, 0.0);
155          setcolor(r->rcol, 0.0, 0.0, 0.0);
156   }
157  
# Line 181 | Line 194 | raytrans(                      /* transmit ray as is */
194   {
195          RAY  tr;
196  
197 <        if (rayorigin(&tr, TRANS, r, NULL) == 0) {
198 <                VCOPY(tr.rdir, r->rdir);
199 <                rayvalue(&tr);
200 <                copycolor(r->rcol, tr.rcol);
201 <                r->rt = r->rot + tr.rt;
197 >        rayorigin(&tr, TRANS, r, NULL);         /* always continue */
198 >        VCOPY(tr.rdir, r->rdir);
199 >        rayvalue(&tr);
200 >        copycolor(r->mcol, tr.mcol);
201 >        copycolor(r->rcol, tr.rcol);
202 >        r->rmt = r->rot + tr.rmt;
203 >        r->rxt = r->rot + tr.rxt;
204 > }
205 >
206 >
207 > int
208 > raytirrad(                      /* irradiance hack */
209 >        OBJREC  *m,
210 >        RAY     *r
211 > )
212 > {
213 >        if (ofun[m->otype].flags & (T_M|T_X) && m->otype != MAT_CLIP) {
214 >                if (istransp(m->otype) || isBSDFproxy(m)) {
215 >                        raytrans(r);
216 >                        return(1);
217 >                }
218 >                if (!islight(m->otype))
219 >                        return((*ofun[Lamb.otype].funp)(&Lamb, r));
220          }
221 +        return(0);              /* not a qualifying surface */
222   }
223  
224  
# Line 196 | Line 228 | rayshade(              /* shade ray r with material mod */
228          int  mod
229   )
230   {
231 +        int     tst_irrad = do_irrad && !(r->crtype & ~(PRIMARY|TRANS));
232          OBJREC  *m;
233  
234 <        r->rt = r->rot;                 /* set effective ray length */
234 >        r->rxt = r->rot;                /* preset effective ray length */
235          for ( ; mod != OVOID; mod = m->omod) {
236                  m = objptr(mod);
237                  /****** unnecessary test since modifier() is always called
# Line 208 | Line 241 | rayshade(              /* shade ray r with material mod */
241                  }
242                  ******/
243                                          /* hack for irradiance calculation */
244 <                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
245 <                                m->otype != MAT_CLIP &&
246 <                                (ofun[m->otype].flags & (T_M|T_X))) {
214 <                        if (irr_ignore(m->otype)) {
215 <                                raytrans(r);
216 <                                return(1);
217 <                        }
218 <                        if (!islight(m->otype))
219 <                                m = &Lamb;
220 <                }
244 >                if (tst_irrad && raytirrad(m, r))
245 >                        return(1);
246 >
247                  if ((*ofun[m->otype].funp)(m, r))
248                          return(1);      /* materials call raytexture() */
249          }
# Line 249 | Line 275 | rayparticipate(                        /* compute ray medium participation
275          multcolor(r->rcol, ce);                 /* path extinction */
276          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
277                  return;                         /* no scattering */
278 <        setcolor(ca,
279 <                colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
280 <                colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
281 <                colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
282 <        addcolor(r->rcol, ca);                  /* ambient in scattering */
278 >        
279 >        /* PMAP: indirect inscattering accounted for by volume photons? */
280 >        if (!volumePhotonMapping) {
281 >                setcolor(ca,
282 >                        colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
283 >                        colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
284 >                        colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
285 >                addcolor(r->rcol, ca);                  /* ambient in scattering */
286 >        }
287 >        
288          srcscatter(r);                          /* source in scattering */
289   }
290  
# Line 292 | Line 323 | raymixture(            /* mix modifiers */
323   )
324   {
325          RAY  fr, br;
326 +        double  mfore, mback;
327          int  foremat, backmat;
328          int  i;
329                                          /* bound coefficient */
# Line 338 | Line 370 | raymixture(            /* mix modifiers */
370          scalecolor(br.rcol, 1.0-coef);
371          copycolor(r->rcol, fr.rcol);
372          addcolor(r->rcol, br.rcol);
373 <        r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
373 >        scalecolor(fr.mcol, coef);
374 >        scalecolor(br.mcol, 1.0-coef);
375 >        copycolor(r->mcol, fr.mcol);
376 >        addcolor(r->mcol, br.mcol);
377 >        mfore = bright(fr.mcol); mback = bright(br.mcol);
378 >        r->rmt = mfore > mback ? fr.rmt : br.rmt;
379 >        r->rxt = bright(fr.rcol)-mfore > bright(br.rcol)-mback ?
380 >                        fr.rxt : br.rxt;
381          return(1);
382   }
383  
# Line 366 | Line 405 | raycontrib(            /* compute (cumulative) ray contribution
405          int  flags
406   )
407   {
408 <        double  eext[3];
370 <        int     i;
408 >        static int      warnedPM = 0;
409  
372        eext[0] = eext[1] = eext[2] = 0.;
410          rc[0] = rc[1] = rc[2] = 1.;
411  
412          while (r != NULL && r->crtype&flags) {
413 <                for (i = 3; i--; ) {
413 >                int     i = 3;
414 >                while (i--)
415                          rc[i] *= colval(r->rcoef,i);
416 <                        eext[i] += r->rot * colval(r->cext,i);
416 >                                        /* check for participating medium */
417 >                if (!warnedPM && (bright(r->cext) > FTINY) |
418 >                                (bright(r->albedo) > FTINY)) {
419 >                        error(WARNING,
420 >        "ray contribution calculation does not support participating media");
421 >                        warnedPM++;
422                  }
423                  r = r->parent;
424          }
382        for (i = 3; i--; )
383                rc[i] *= (eext[i] <= FTINY) ? 1. :
384                                (eext[i] > 92.) ? 0. : exp(-eext[i]);
425   }
426  
427  
# Line 471 | Line 511 | flipsurface(                   /* reverse surface orientation */
511          r->pert[0] = -r->pert[0];
512          r->pert[1] = -r->pert[1];
513          r->pert[2] = -r->pert[2];
514 +        r->rflips++;
515   }
516  
517  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines