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.73 by greg, Tue Nov 13 19:58:33 2018 UTC vs.
Revision 2.81 by greg, Sun Mar 29 18:21:57 2020 UTC

# Line 68 | 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 116 | Line 116 | rayorigin(             /* start new ray from old one */
116                  if (photonMapping && rt != TRANS)
117                          return(-1);
118          }
119 <        if (maxdepth <= 0 && rc != NULL) {      /* Russian roulette */
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 130 | 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 146 | Line 146 | rayclear(                      /* clear a ray for (re)evaluation */
146          r->ro = NULL;
147          r->rox = NULL;
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);
# Line 195 | 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->rmt = r->rot + tr.rmt;
203          r->rxt = r->rot + tr.rxt;
# Line 202 | Line 205 | raytrans(                      /* transmit ray as is */
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->rxt = r->rmt = r->rot;       /* preset 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 219 | 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 <                                (ofun[m->otype].flags & (T_M|T_X)) &&
246 <                                m->otype != MAT_CLIP) {
225 <                        if (istransp(m->otype) || isBSDFproxy(m)) {
226 <                                raytrans(r);
227 <                                return(1);
228 <                        }
229 <                        if (!islight(m->otype))
230 <                                m = &Lamb;
231 <                }
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 355 | 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 +        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 ?
# Line 386 | Line 405 | raycontrib(            /* compute (cumulative) ray contribution
405          int  flags
406   )
407   {
408 <        double  eext[3];
390 <        int     i;
408 >        static int      warnedPM = 0;
409  
392        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          }
402        for (i = 3; i--; )
403                rc[i] *= (eext[i] <= FTINY) ? 1. :
404                                (eext[i] > 92.) ? 0. : exp(-eext[i]);
425   }
426  
427  
# Line 491 | 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