--- ray/src/rt/raytrace.c 2015/05/21 15:28:24 2.67 +++ ray/src/rt/raytrace.c 2019/02/13 01:00:31 2.75 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.67 2015/05/21 15:28:24 greg Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.75 2019/02/13 01:00:31 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -51,6 +51,8 @@ rayorigin( /* start new ray from old one */ setcolor(r->rcoef, 1., 1., 1.); } else { rw = intens(rc); + if (rw > 1.0) + rw = 1.0; /* avoid calculation growth */ if (rc != r->rcoef) copycolor(r->rcoef, rc); } @@ -108,8 +110,12 @@ rayorigin( /* start new ray from old one */ if (r->crtype & SHADOW) /* shadow commitment */ return(0); /* ambient in photon map? */ - if (r->crtype & AMBIENT && photonMapping) - return(-1); + if (ro != NULL && ro->crtype & AMBIENT) { + if (causticPhotonMapping) + return(-1); + if (photonMapping && rt != TRANS) + return(-1); + } if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ if (minweight <= 0.0) error(USER, "zero ray weight in Russian roulette"); @@ -139,10 +145,11 @@ rayclear( /* clear a ray for (re)evaluation */ r->robj = OVOID; r->ro = NULL; r->rox = NULL; - r->rt = r->rot = FHUGE; + r->rxt = r->rmt = r->rot = FHUGE; r->pert[0] = r->pert[1] = r->pert[2] = 0.0; r->uv[0] = r->uv[1] = 0.0; setcolor(r->pcol, 1.0, 1.0, 1.0); + setcolor(r->mcol, 0.0, 0.0, 0.0); setcolor(r->rcol, 0.0, 0.0, 0.0); } @@ -188,20 +195,41 @@ raytrans( /* transmit ray as is */ rayorigin(&tr, TRANS, r, NULL); /* always continue */ VCOPY(tr.rdir, r->rdir); rayvalue(&tr); + copycolor(r->mcol, tr.mcol); copycolor(r->rcol, tr.rcol); - r->rt = r->rot + tr.rt; + r->rmt = r->rot + tr.rmt; + r->rxt = r->rot + tr.rxt; } int +raytirrad( /* irradiance hack */ + OBJREC *m, + RAY *r +) +{ + if (ofun[m->otype].flags & (T_M|T_X) && m->otype != MAT_CLIP) { + if (istransp(m->otype) || isBSDFproxy(m)) { + raytrans(r); + return(1); + } + if (!islight(m->otype)) + return((*ofun[Lamb.otype].funp)(&Lamb, r)); + } + return(0); /* not a qualifying surface */ +} + + +int rayshade( /* shade ray r with material mod */ RAY *r, int mod ) { + int tst_irrad = do_irrad && !(r->crtype & ~(PRIMARY|TRANS)); OBJREC *m; - r->rt = r->rot; /* set effective ray length */ + r->rxt = r->rmt = r->rot; /* preset effective ray length */ for ( ; mod != OVOID; mod = m->omod) { m = objptr(mod); /****** unnecessary test since modifier() is always called @@ -211,16 +239,9 @@ rayshade( /* shade ray r with material mod */ } ******/ /* hack for irradiance calculation */ - if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && - m->otype != MAT_CLIP && - (ofun[m->otype].flags & (T_M|T_X))) { - if (irr_ignore(m->otype)) { - raytrans(r); - return(1); - } - if (!islight(m->otype)) - m = &Lamb; - } + if (tst_irrad && raytirrad(m, r)) + return(1); + if ((*ofun[m->otype].funp)(m, r)) return(1); /* materials call raytexture() */ } @@ -300,6 +321,7 @@ raymixture( /* mix modifiers */ ) { RAY fr, br; + double mfore, mback; int foremat, backmat; int i; /* bound coefficient */ @@ -346,7 +368,14 @@ raymixture( /* mix modifiers */ scalecolor(br.rcol, 1.0-coef); copycolor(r->rcol, fr.rcol); addcolor(r->rcol, br.rcol); - r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; + scalecolor(fr.mcol, coef); + scalecolor(br.mcol, 1.0-coef); + copycolor(r->mcol, fr.mcol); + addcolor(r->mcol, br.mcol); + mfore = bright(fr.mcol); mback = bright(br.mcol); + r->rmt = mfore > mback ? fr.rmt : br.rmt; + r->rxt = bright(fr.rcol)-mfore > bright(br.rcol)-mback ? + fr.rxt : br.rxt; return(1); }