--- ray/src/rt/rcontrib.c 2012/06/19 00:12:08 2.10 +++ ray/src/rt/rcontrib.c 2012/08/14 22:25:12 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.10 2012/06/19 00:12:08 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.16 2012/08/14 22:25:12 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -7,9 +7,8 @@ static const char RCSid[] = "$Id: rcontrib.c,v 2.10 20 */ #include "rcontrib.h" -#include "source.h" #include "otypes.h" -#include "platform.h" +#include "source.h" char *shm_boundary = NULL; /* boundary of shared memory */ @@ -178,6 +177,8 @@ rcinit() /* set shared memory boundary */ shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY"); } + for (i = 0; i < nsources; i++) /* tracing to sources as well */ + source[i].sflags |= SFOLLOW; if (yres > 0) { /* set up flushing & ray counts */ if (xres > 0) raysleft = (RNUMBER)xres*yres; @@ -188,9 +189,6 @@ rcinit() if ((account = accumulate) > 1) raysleft *= accumulate; waitflush = (yres > 0) & (xres > 1) ? 0 : xres; - /* tracing to sources as well */ - for (i = 0; i < nsources; i++) - source[i].sflags |= SFOLLOW; if (nproc > 1 && in_rchild()) /* forked child? */ return; /* return to main processing loop */ @@ -228,16 +226,19 @@ trace_contrib(RAY *r) if (mp == NULL) /* not in our list? */ return; + /* shadow ray not on source? */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + return; - worldfunc(RCCONTEXT, r); /* get bin number */ + worldfunc(RCCONTEXT, r); /* else get bin number */ bn = (int)(evalue(mp->binv) + .5); if ((bn < 0) | (bn >= mp->nbins)) { error(WARNING, "bad bin number (ignored)"); return; } - raycontrib(contr, r, PRIMARY); + raycontrib(contr, r, PRIMARY); /* compute coefficient */ if (contrib) - multcolor(contr, r->rcol); + multcolor(contr, r->rcol); /* -> contribution */ addcolor(mp->cbin[bn], contr); } @@ -254,8 +255,10 @@ eval_irrad(FVECT org, FVECT dir) thisray.rdir[2] = -dir[2]; thisray.rmax = 0.0; rayorigin(&thisray, PRIMARY, NULL, NULL); - thisray.rot = 1e-5; /* pretend we hit surface */ + /* pretend we hit surface */ + thisray.rt = thisray.rot = 1e-5; thisray.rod = 1.0; + VCOPY(thisray.ron, dir); VSUM(thisray.rop, org, dir, 1e-4); samplendx++; /* compute result */ (*ofun[Lamb.otype].funp)(&Lamb, &thisray); @@ -336,7 +339,7 @@ rcontrib() if (raysleft && !--raysleft) break; /* preemptive EOI */ } - if ((accumulate <= 0) | (account < accumulate)) { + if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) { if (account < accumulate) { error(WARNING, "partial accumulation in final record"); accumulate -= account;