--- ray/src/rt/raytrace.c 2005/04/19 01:15:06 2.49 +++ ray/src/rt/raytrace.c 2005/06/21 15:06:50 2.52 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.49 2005/04/19 01:15:06 greg Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.52 2005/06/21 15:06:50 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -13,6 +13,7 @@ static const char RCSid[] = "$Id: raytrace.c,v 2.49 20 #include "source.h" #include "otypes.h" #include "otspecial.h" +#include "random.h" #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ @@ -58,6 +59,7 @@ rayorigin( /* start new ray from old one */ r->crtype = r->rtype = rt; r->rsrc = -1; r->clipset = NULL; + r->revf = raytrace; copycolor(r->cext, cextinction); copycolor(r->albedo, salbedo); r->gecc = seccg; @@ -78,6 +80,7 @@ rayorigin( /* start new ray from old one */ r->clipset = ro->newcset; r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; } + r->revf = ro->revf; copycolor(r->cext, ro->cext); copycolor(r->albedo, ro->albedo); r->gecc = ro->gecc; @@ -94,6 +97,22 @@ rayorigin( /* start new ray from old one */ r->rweight *= exp(-re); } rayclear(r); + if (r->crtype & SHADOW) /* shadow commitment */ + return(0); + if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ + if (minweight <= 0.0) + error(USER, "zero ray weight in Russian roulette"); + if (maxdepth < 0 && r->rlvl > -maxdepth) + return(-1); /* upper reflection limit */ + if (r->rweight >= minweight) + return(0); + 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); } @@ -118,7 +137,7 @@ rayclear( /* clear a ray for (re)evaluation */ extern void -rayvalue( /* trace a ray and compute its value */ +raytrace( /* trace a ray and compute its value */ RAY *r ) { @@ -329,29 +348,27 @@ raydist( /* compute (cumulative) ray distance */ extern void raycontrib( /* compute (cumulative) ray contribution */ - COLOR rc, + double rc[3], const RAY *r, int flags ) { - COLOR eext, ext1; - - setcolor(eext, 0., 0., 0.); - setcolor(rc, 1., 1., 1.); + double eext[3]; + int i; + eext[0] = eext[1] = eext[2] = 0.; + rc[0] = rc[1] = rc[2] = 1.; + while (r != NULL && r->crtype&flags) { - multcolor(rc, r->rcoef); - copycolor(ext1, r->cext); - scalecolor(ext1, r->rot); - addcolor(eext, ext1); + for (i = 3; i--; ) { + rc[i] *= colval(r->rcoef,i); + eext[i] += r->rot * colval(r->cext,i); + } r = r->parent; } - if (intens(eext) > FTINY) { - setcolor(ext1, exp(-colval(eext,RED)), - exp(-colval(eext,GRN)), - exp(-colval(eext,BLU))); - multcolor(rc, ext1); - } + for (i = 3; i--; ) + rc[i] *= (eext[i] <= FTINY) ? 1. : + (eext[i] > 300.) ? 0. : exp(-eext[i]); }