--- ray/src/rt/raytrace.c 2005/08/22 21:54:41 2.56 +++ ray/src/rt/raytrace.c 2011/04/06 00:14:26 2.63 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.56 2005/08/22 21:54:41 greg Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.63 2011/04/06 00:14:26 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -17,13 +17,13 @@ static const char RCSid[] = "$Id: raytrace.c,v 2.56 20 #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ -unsigned long raynum = 0; /* next unique ray number */ -unsigned long nrays = 0; /* number of calls to localhit */ +RNUMBER raynum = 0; /* next unique ray number */ +RNUMBER nrays = 0; /* number of calls to localhit */ 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 */ @@ -302,12 +304,14 @@ raymixture( /* mix modifiers */ /* foreground */ fr = *r; if (coef > FTINY) { + fr.rweight *= coef; scalecolor(fr.rcoef, coef); foremat = rayshade(&fr, fore); } /* background */ br = *r; if (coef < 1.0-FTINY) { + br.rweight *= 1.0-coef; scalecolor(br.rcoef, 1.0-coef); backmat = rayshade(&br, back); } @@ -357,7 +361,7 @@ raydist( /* compute (cumulative) ray distance */ extern void raycontrib( /* compute (cumulative) ray contribution */ - double rc[3], + RREAL rc[3], const RAY *r, int flags ) @@ -508,14 +512,15 @@ localhit( /* check for hit in the octree */ else if (r->rdir[i] < -1e-7) sflags |= 0x10 << i; } - if (sflags == 0) - error(CONSISTENCY, "zero ray direction in localhit"); + if (!sflags) { + error(WARNING, "zero ray direction in localhit"); + return(0); + } /* start off assuming nothing hit */ if (r->rmax > FTINY) { /* except aft plane if one */ r->ro = &Aftplane; r->rot = r->rmax; - for (i = 0; i < 3; i++) - r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; + VSUM(r->rop, r->rorg, r->rdir, r->rot); } /* find global cube entrance point */ t = 0.0; @@ -538,8 +543,7 @@ localhit( /* check for hit in the octree */ if (t >= r->rot) /* clipped already */ return(0); /* advance position */ - for (i = 0; i < 3; i++) - curpos[i] += r->rdir[i]*t; + VSUM(curpos, curpos, r->rdir, t); if (!incube(scene, curpos)) /* non-intersecting ray */ return(0); @@ -630,9 +634,7 @@ raymove( /* check for hit as we move */ ax = 2; } } - pos[0] += r->rdir[0]*t; - pos[1] += r->rdir[1]*t; - pos[2] += r->rdir[2]*t; + VSUM(pos, pos, r->rdir, t); return(ax); }