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.67 by greg, Thu May 21 15:28:24 2015 UTC vs.
Revision 2.81 by greg, Sun Mar 29 18:21:57 2020 UTC

# Line 51 | 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 66 | 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 108 | Line 110 | rayorigin(             /* start new ray from old one */
110          if (r->crtype & SHADOW)                 /* shadow commitment */
111                  return(0);
112                                                  /* ambient in photon map? */
113 <        if (r->crtype & AMBIENT && photonMapping)
114 <                return(-1);
115 <        if (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
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 124 | 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 139 | 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 188 | Line 197 | raytrans(                      /* transmit ray as is */
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->rt = r->rot + tr.rt;
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 +
225 + int
226   rayshade(               /* shade ray r with material mod */
227          RAY  *r,
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 211 | 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))) {
217 <                        if (irr_ignore(m->otype)) {
218 <                                raytrans(r);
219 <                                return(1);
220 <                        }
221 <                        if (!islight(m->otype))
222 <                                m = &Lamb;
223 <                }
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 300 | 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 346 | 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 374 | Line 405 | raycontrib(            /* compute (cumulative) ray contribution
405          int  flags
406   )
407   {
408 <        double  eext[3];
378 <        int     i;
408 >        static int      warnedPM = 0;
409  
380        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          }
390        for (i = 3; i--; )
391                rc[i] *= (eext[i] <= FTINY) ? 1. :
392                                (eext[i] > 92.) ? 0. : exp(-eext[i]);
425   }
426  
427  
# Line 479 | 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