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.82 by greg, Mon Jan 4 19:07:15 2021 UTC vs.
Revision 2.92 by greg, Thu Dec 5 19:23:43 2024 UTC

# Line 41 | Line 41 | rayorigin(             /* start new ray from old one */
41          RAY  *r,
42          int  rt,
43          const RAY  *ro,
44 <        const COLOR rc
44 >        const SCOLOR rc
45   )
46   {
47          double  rw, re;
48                                                  /* assign coefficient/weight */
49          if (rc == NULL) {
50                  rw = 1.0;
51 <                setcolor(r->rcoef, 1., 1., 1.);
51 >                setscolor(r->rcoef, 1., 1., 1.);
52          } else {
53 <                rw = intens(rc);
53 >                rw = sintens((COLORV *)rc);
54                  if (rw > 1.0)
55                          rw = 1.0;               /* avoid calculation growth */
56                  if (rc != r->rcoef)
57 <                        copycolor(r->rcoef, rc);
57 >                        copyscolor(r->rcoef, rc);
58          }
59          if ((r->parent = ro) == NULL) {         /* primary ray */
60                  r->rlvl = 0;
61                  r->rweight = rw;
62                  r->crtype = r->rtype = rt;
63                  r->rsrc = -1;
64 + #ifdef SSKIPOPT
65 +                r->scorr = 1.f;
66 + #endif
67                  r->clipset = NULL;
68                  r->revf = raytrace;
69                  copycolor(r->cext, cextinction);
# Line 73 | Line 76 | rayorigin(             /* start new ray from old one */
76                          return(-1);             /* illegal continuation */
77                  }
78                  r->rlvl = ro->rlvl;
79 +                r->rsrc = ro->rsrc;
80 + #ifdef SSKIPOPT
81 +                r->scorr = ro->scorr;
82 + #endif
83                  if (rt & RAYREFL) {
84                          r->rlvl++;
85 <                        r->rsrc = -1;
85 >                        if (r->rsrc >= 0)       /* malfunctioning material? */
86 >                                r->rsrc = -1;
87                          r->clipset = ro->clipset;
88                          r->rmax = 0.0;
89                  } else {
82                        r->rsrc = ro->rsrc;
90                          r->clipset = ro->newcset;
91 <                        r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
91 >                        r->rmax = (ro->rmax > FTINY)*(ro->rmax - ro->rot);
92                  }
93                  r->revf = ro->revf;
94                  copycolor(r->cext, ro->cext);
# Line 126 | Line 133 | rayorigin(             /* start new ray from old one */
133                  if (frandom() > r->rweight/minweight)
134                          return(-1);
135                  rw = minweight/r->rweight;      /* promote survivor */
136 <                scalecolor(r->rcoef, rw);
136 >                scalescolor(r->rcoef, rw);
137                  r->rweight = minweight;
138                  return(0);
139          }
# Line 152 | Line 159 | rayclear(                      /* clear a ray for (re)evaluation */
159          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
160          r->rflips = 0;
161          r->uv[0] = r->uv[1] = 0.0;
162 <        setcolor(r->pcol, 1.0, 1.0, 1.0);
163 <        setcolor(r->mcol, 0.0, 0.0, 0.0);
164 <        setcolor(r->rcol, 0.0, 0.0, 0.0);
162 >        setscolor(r->pcol, 1.0, 1.0, 1.0);
163 >        scolorblack(r->mcol);
164 >        scolorblack(r->rcol);
165   }
166  
167  
# Line 199 | Line 206 | raytrans(                      /* transmit ray as is */
206          rayorigin(&tr, TRANS, r, NULL);         /* always continue */
207          VCOPY(tr.rdir, r->rdir);
208          rayvalue(&tr);
209 <        copycolor(r->mcol, tr.mcol);
210 <        copycolor(r->rcol, tr.rcol);
209 >        copyscolor(r->mcol, tr.mcol);
210 >        copyscolor(r->rcol, tr.rcol);
211          r->rmt = r->rot + tr.rmt;
212          r->rxt = r->rot + tr.rxt;
213   }
# Line 212 | Line 219 | raytirrad(                     /* irradiance hack */
219          RAY     *r
220   )
221   {
222 <        if (ofun[m->otype].flags & (T_M|T_X) && m->otype != MAT_CLIP) {
222 >        if (m->otype != MAT_CLIP && ismaterial(m->otype)) {
223                  if (istransp(m->otype) || isBSDFproxy(m)) {
224                          raytrans(r);
225                          return(1);
226                  }
227 <                if (!islight(m->otype))
227 >                if (!islight(m->otype)) {
228 >                        setscolor(r->pcol, 1.0, 1.0, 1.0);
229                          return((*ofun[Lamb.otype].funp)(&Lamb, r));
230 +                }
231          }
232          return(0);              /* not a qualifying surface */
233   }
# Line 258 | Line 267 | rayparticipate(                        /* compute ray medium participation
267          RAY  *r
268   )
269   {
270 <        COLOR   ce, ca;
270 >        SCOLOR  ce, ca;
271          double  re, ge, be;
272  
273          if (intens(r->cext) <= 1./FHUGE)
# Line 271 | Line 280 | rayparticipate(                        /* compute ray medium participation
280                  ge *= 1. - colval(r->albedo,GRN);
281                  be *= 1. - colval(r->albedo,BLU);
282          }
283 <        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
283 >        setscolor(ce,   re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
284                          ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
285                          be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
286 <        multcolor(r->rcol, ce);                 /* path extinction */
286 >        smultscolor(r->rcol, ce);               /* path extinction */
287          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
288                  return;                         /* no scattering */
289          
290          /* PMAP: indirect inscattering accounted for by volume photons? */
291          if (!volumePhotonMapping) {
292 <                setcolor(ca,
292 >                setscolor(ca,
293                          colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
294                          colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
295                          colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
296 <                addcolor(r->rcol, ca);                  /* ambient in scattering */
296 >                saddscolor(r->rcol, ca);                /* ambient in scattering */
297          }
298          
299          srcscatter(r);                          /* source in scattering */
# Line 339 | Line 348 | raymixture(            /* mix modifiers */
348          fr = *r;
349          if (coef > FTINY) {
350                  fr.rweight *= coef;
351 <                scalecolor(fr.rcoef, coef);
351 >                scalescolor(fr.rcoef, coef);
352                  foremat = rayshade(&fr, fore);
353          }
354                                          /* background */
355          br = *r;
356          if (coef < 1.0-FTINY) {
357                  br.rweight *= 1.0-coef;
358 <                scalecolor(br.rcoef, 1.0-coef);
358 >                scalescolor(br.rcoef, 1.0-coef);
359                  backmat = rayshade(&br, back);
360          }
361                                          /* check for transparency */
# Line 360 | Line 369 | raymixture(            /* mix modifiers */
369          for (i = 0; i < 3; i++)
370                  r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
371                                          /* mix pattern colors */
372 <        scalecolor(fr.pcol, coef);
373 <        scalecolor(br.pcol, 1.0-coef);
374 <        copycolor(r->pcol, fr.pcol);
375 <        addcolor(r->pcol, br.pcol);
372 >        scalescolor(fr.pcol, coef);
373 >        scalescolor(br.pcol, 1.0-coef);
374 >        copyscolor(r->pcol, fr.pcol);
375 >        saddscolor(r->pcol, br.pcol);
376                                          /* return value tells if material */
377          if (!foremat & !backmat)
378                  return(0);
379                                          /* mix returned ray values */
380 <        scalecolor(fr.rcol, coef);
381 <        scalecolor(br.rcol, 1.0-coef);
382 <        copycolor(r->rcol, fr.rcol);
383 <        addcolor(r->rcol, br.rcol);
384 <        scalecolor(fr.mcol, coef);
385 <        scalecolor(br.mcol, 1.0-coef);
386 <        copycolor(r->mcol, fr.mcol);
387 <        addcolor(r->mcol, br.mcol);
388 <        mfore = bright(fr.mcol); mback = bright(br.mcol);
380 >        scalescolor(fr.rcol, coef);
381 >        scalescolor(br.rcol, 1.0-coef);
382 >        copyscolor(r->rcol, fr.rcol);
383 >        saddscolor(r->rcol, br.rcol);
384 >        scalescolor(fr.mcol, coef);
385 >        scalescolor(br.mcol, 1.0-coef);
386 >        copyscolor(r->mcol, fr.mcol);
387 >        saddscolor(r->mcol, br.mcol);
388 >        mfore = pbright(fr.mcol); mback = pbright(br.mcol);
389          r->rmt = mfore > mback ? fr.rmt : br.rmt;
390 <        r->rxt = bright(fr.rcol)-mfore > bright(br.rcol)-mback ?
390 >        r->rxt = pbright(fr.rcol)-mfore > pbright(br.rcol)-mback ?
391                          fr.rxt : br.rxt;
392          return(1);
393   }
# Line 402 | Line 411 | raydist(               /* compute (cumulative) ray distance */
411  
412   void
413   raycontrib(             /* compute (cumulative) ray contribution */
414 <        RREAL  rc[3],
414 >        SCOLOR  rc,
415          const RAY  *r,
416          int  flags
417   )
418   {
419          static int      warnedPM = 0;
420  
421 <        rc[0] = rc[1] = rc[2] = 1.;
421 >        setscolor(rc, 1., 1., 1.);
422  
423          while (r != NULL && r->crtype&flags) {
424 <                int     i = 3;
416 <                while (i--)
417 <                        rc[i] *= colval(r->rcoef,i);
424 >                smultscolor(rc, r->rcoef);
425                                          /* check for participating medium */
426                  if (!warnedPM && (bright(r->cext) > FTINY) |
427                                  (bright(r->albedo) > FTINY)) {
# Line 454 | Line 461 | raynormal(             /* compute perturbed normal for ray */
461                  return(r->rod);
462          }
463          newdot = -DOT(norm, r->rdir);
464 <        if ((newdot > 0.0) != (r->rod > 0.0)) {         /* fix orientation */
464 >        if ((newdot > 0.0) ^ (r->rod > 0.0)) {          /* fix orientation */
465                  for (i = 0; i < 3; i++)
466                          norm[i] += 2.0*newdot*r->rdir[i];
467                  newdot = -newdot;
# Line 516 | Line 523 | flipsurface(                   /* reverse surface orientation */
523          r->rflips++;
524   }
525  
526 +
527 + int
528 + rayreject(              /* check if candidate hit is worse than current */
529 +        OBJREC *o,
530 +        RAY *r,
531 +        double t,
532 +        double rod
533 + )
534 + {
535 +        OBJREC  *mnew, *mray;
536 +
537 +        if ((t <= FTINY) | (t > r->rot + FTINY))
538 +                return(1);
539 +        if (t < r->rot - FTINY)         /* is new hit significantly closer? */
540 +                return(0);
541 +                                        /* coincident point, so decide... */
542 +        if (o == r->ro)
543 +                return(1);              /* shouldn't happen */
544 +        if (r->ro == NULL)
545 +                return(0);              /* ditto */
546 +        mnew = findmaterial(o);
547 +        mray = findmaterial(r->ro);     /* check material transparencies */
548 +        if (mnew == NULL) {
549 +                if (mray != NULL)
550 +                        return(1);      /* old has material, new does not */
551 +        } else if (mray == NULL) {
552 +                return(0);              /* new has material, old does not */
553 +        } else if (istransp(mnew->otype)) {
554 +                if (!istransp(mray->otype))
555 +                        return(1);      /* new is transparent, old is not */
556 +        } else if (istransp(mray->otype)) {
557 +                return(0);              /* old is transparent, new is not */
558 +        }
559 +        if (rod <= 0) {                 /* check which side we hit */
560 +                if (r->rod > 0)
561 +                        return(1);      /* old hit front, new did not */
562 +        } else if (r->rod <= 0) {
563 +                return(0);              /* new hit front, old did not */
564 +        }
565 +                        /* earlier modifier definition wins tie */
566 +        return (r->ro->omod >= o->omod);
567 + }
568  
569   void
570   rayhit(                 /* standard ray hit test */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines