--- ray/src/rt/raytrace.c 1995/12/08 18:49:09 2.23 +++ ray/src/rt/raytrace.c 1996/03/30 11:18:36 2.25 @@ -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"; @@ -109,19 +109,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 +129,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)); } @@ -204,7 +197,7 @@ register RAY *r; 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 */ + dist *= 1. - r->albedo; /* no scattering for sources */ if (dist <= FTINY) return; /* no effective ray travel */ re = dist*colval(r->cext,RED); @@ -216,9 +209,9 @@ register RAY *r; multcolor(r->rcol, ce); /* path absorption */ if (r->albedo <= FTINY || r->crtype & SHADOW) 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, r->albedo*colval(ambval,RED)*(1.-colval(ce,RED)), + r->albedo*colval(ambval,GRN)*(1.-colval(ce,GRN)), + r->albedo*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); }