--- ray/src/rt/raytrace.c 1995/12/08 18:49:09 2.23 +++ ray/src/rt/raytrace.c 1997/03/07 16:58:54 2.28 @@ -1,4 +1,4 @@ -/* Copyright (c) 1995 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -27,7 +27,7 @@ extern int do_irrad; /* compute irradiance? */ extern COLOR ambval; /* ambient value */ extern COLOR cextinction; /* global extinction coefficient */ -extern double salbedo; /* global scattering albedo */ +extern COLOR salbedo; /* global scattering albedo */ extern double seccg; /* global scattering eccentricity */ extern double ssampdist; /* scatter sampling distance */ @@ -62,7 +62,7 @@ double rw; r->clipset = NULL; r->revf = raytrace; copycolor(r->cext, cextinction); - r->albedo = salbedo; + copycolor(r->albedo, salbedo); r->gecc = seccg; r->slights = NULL; } else { /* spawned ray */ @@ -79,7 +79,7 @@ double rw; } r->revf = ro->revf; copycolor(r->cext, ro->cext); - r->albedo = ro->albedo; + copycolor(r->albedo, ro->albedo); r->gecc = ro->gecc; r->slights = ro->slights; r->rweight = ro->rweight * rw; @@ -96,6 +96,7 @@ register RAY *r; { r->rno = raynum++; r->newcset = r->clipset; + r->robj = OVOID; r->ro = NULL; r->rot = FHUGE; r->pert[0] = r->pert[1] = r->pert[2] = 0.0; @@ -109,19 +110,15 @@ raytrace(r) /* trace a ray and compute its value */ RAY *r; { extern int (*trace)(); - int gotmat; if (localhit(r, &thescene)) - gotmat = raycont(r); /* hit local surface, evaluate */ + raycont(r); /* hit local surface, evaluate */ else if (r->ro == &Aftplane) { r->ro = NULL; /* hit aft clipping plane */ r->rot = FHUGE; } else if (sourcehit(r)) - gotmat = rayshade(r, r->ro->omod); /* distant source */ + rayshade(r, r->ro->omod); /* distant source */ - if (r->ro != NULL && !gotmat) - objerror(r->ro, USER, "material not found"); - rayparticipate(r); /* for participating medium */ if (trace != NULL) @@ -133,11 +130,8 @@ raycont(r) /* check for clipped object and continue register RAY *r; { if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || - r->ro->omod == OVOID) { + !rayshade(r, r->ro->omod)) raytrans(r); - return(1); - } - return(rayshade(r, r->ro->omod)); } @@ -196,29 +190,28 @@ rayparticipate(r) /* compute ray medium participatio register RAY *r; { COLOR ce, ca; - double dist; double re, ge, be; if (intens(r->cext) <= 1./FHUGE) return; /* no medium */ - if ((dist = r->rot) >= FHUGE) - dist = 2.*thescene.cusize; /* what to use for infinity? */ - if (r->crtype & SHADOW) - dist *= 1. - salbedo; /* no scattering for sources */ - if (dist <= FTINY) - return; /* no effective ray travel */ - re = dist*colval(r->cext,RED); - ge = dist*colval(r->cext,GRN); - be = dist*colval(r->cext,BLU); - setcolor(ce, re>92. ? 0. : exp(-re), - ge>92. ? 0. : exp(-ge), - be>92. ? 0. : exp(-be)); + re = r->rot*colval(r->cext,RED); + ge = r->rot*colval(r->cext,GRN); + be = r->rot*colval(r->cext,BLU); + if (r->crtype & SHADOW) { /* no scattering for sources */ + re *= 1. - colval(r->albedo,RED); + ge *= 1. - colval(r->albedo,GRN); + be *= 1. - colval(r->albedo,BLU); + } + setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), + ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), + be<=0. ? 1. : be>92. ? 0. : exp(-be)); multcolor(r->rcol, ce); /* path absorption */ - if (r->albedo <= FTINY || r->crtype & SHADOW) + if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) return; /* no scattering */ - setcolor(ca, salbedo*colval(ambval,RED)*(1.-colval(ce,RED)), - salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)), - salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU))); + setcolor(ca, + colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), + colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), + colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); addcolor(r->rcol, ca); /* ambient in scattering */ srcscatter(r); /* source in scattering */ } @@ -260,31 +253,27 @@ double coef; RAY fr, br; int foremat, backmat; register int i; - /* clip coefficient */ + /* bound coefficient */ if (coef > 1.0) coef = 1.0; else if (coef < 0.0) coef = 0.0; /* compute foreground and background */ - foremat = backmat = -1; + foremat = backmat = 0; /* foreground */ copystruct(&fr, r); - if (fore != OVOID && coef > FTINY) + if (coef > FTINY) foremat = rayshade(&fr, fore); /* background */ copystruct(&br, r); - if (back != OVOID && coef < 1.0-FTINY) + if (coef < 1.0-FTINY) backmat = rayshade(&br, back); - /* check */ - if (foremat < 0) - if (backmat < 0) - foremat = backmat = 0; + /* check for transparency */ + if (backmat ^ foremat) + if (backmat) + raytrans(&fr); else - foremat = backmat; - else if (backmat < 0) - backmat = foremat; - if ((foremat==0) != (backmat==0)) - objerror(r->ro, USER, "mixing material with non-material"); + raytrans(&br); /* mix perturbations */ for (i = 0; i < 3; i++) r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; @@ -293,16 +282,16 @@ double coef; scalecolor(br.pcol, 1.0-coef); copycolor(r->pcol, fr.pcol); addcolor(r->pcol, br.pcol); - /* mix returned ray values */ - if (foremat) { - scalecolor(fr.rcol, coef); - 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; - } /* return value tells if material */ - return(foremat); + if (!foremat & !backmat) + return(0); + /* mix returned ray values */ + scalecolor(fr.rcol, coef); + 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; + return(1); } @@ -566,7 +555,8 @@ OBJECT *cxs; checkset(oset, cxs); /* eliminate double-checking */ for (i = oset[0]; i > 0; i--) { o = objptr(oset[i]); - (*ofun[o->otype].funp)(o, r); + if ((*ofun[o->otype].funp)(o, r)) + r->robj = oset[i]; } if (r->ro == NULL) return(0); /* no scores yet */