--- ray/src/rt/raytrace.c 2005/06/23 09:11:38 2.53 +++ ray/src/rt/raytrace.c 2007/07/02 20:16:00 2.59 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.53 2005/06/23 09:11:38 greg Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.59 2007/07/02 20:16:00 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -23,7 +23,7 @@ unsigned long nrays = 0; /* number of calls to local static RREAL Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; OBJREC Lamb = { OVOID, MAT_PLASTIC, "Lambertian", - {0, 5, NULL, Lambfa}, NULL, + {NULL, Lambfa, 0, 5}, NULL }; /* a Lambertian surface */ OBJREC Aftplane; /* aft clipping plane object */ @@ -93,11 +93,13 @@ rayorigin( /* start new ray from old one */ colval(ro->cext,RED) : colval(ro->cext,GRN); if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); re *= ro->rot; - if (re > 0.1) - if (re > 92.) + if (re > 0.1) { + if (re > 92.) { r->rweight = 0.0; - else + } else { r->rweight *= exp(-re); + } + } } rayclear(r); if (r->rweight <= 0.0) /* check for expiration */ @@ -111,14 +113,14 @@ rayorigin( /* start new ray from old one */ return(-1); /* upper reflection limit */ if (r->rweight >= minweight) return(0); - if (frandom() < r->rweight/minweight) + if (frandom() > r->rweight/minweight) return(-1); rw = minweight/r->rweight; /* promote survivor */ scalecolor(r->rcoef, rw); r->rweight = minweight; return(0); } - return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); + return(r->rlvl <= abs(maxdepth) && r->rweight >= minweight ? 0 : -1); } @@ -301,12 +303,18 @@ raymixture( /* mix modifiers */ foremat = backmat = 0; /* foreground */ fr = *r; - if (coef > FTINY) + if (coef > FTINY) { + fr.rweight *= coef; + scalecolor(fr.rcoef, coef); foremat = rayshade(&fr, fore); + } /* background */ br = *r; - if (coef < 1.0-FTINY) + if (coef < 1.0-FTINY) { + br.rweight *= 1.0-coef; + scalecolor(br.rcoef, 1.0-coef); backmat = rayshade(&br, back); + } /* check for transparency */ if (backmat ^ foremat) { if (backmat && coef > FTINY)