--- ray/src/rt/rcontrib.c 2012/06/16 17:09:49 2.8 +++ ray/src/rt/rcontrib.c 2014/07/19 00:07:03 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.8 2012/06/16 17:09:49 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.19 2014/07/19 00:07:03 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -7,9 +7,8 @@ static const char RCSid[] = "$Id: rcontrib.c,v 2.8 201 */ #include "rcontrib.h" -#include "source.h" #include "otypes.h" -#include "platform.h" +#include "source.h" char *shm_boundary = NULL; /* boundary of shared memory */ @@ -137,7 +136,7 @@ addmodifier(char *modn, char *outf, char *binv, int bi } -/* add modifiers from a file list */ +/* Add modifiers from a file list */ void addmodfile(char *fname, char *outf, char *binv, int bincnt) { @@ -159,7 +158,7 @@ quit( /* quit program */ ) { if (nchild > 0) /* close children if any */ - end_children(); + end_children(code != 0); exit(code); } @@ -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 */ @@ -218,6 +216,7 @@ static void trace_contrib(RAY *r) { MODCONT *mp; + double bval; int bn; RREAL contr[3]; @@ -228,16 +227,20 @@ 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 */ - bn = (int)(evalue(mp->binv) + .5); - if ((bn < 0) | (bn >= mp->nbins)) { + worldfunc(RCCONTEXT, r); /* else get bin number */ + if ((bval = evalue(mp->binv)) <= -.5) + return; /* silently ignore */ + if ((bn = (int)(bval + .5)) >= 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 +257,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); @@ -313,7 +318,7 @@ rcontrib() #endif while (getvec(orig) == 0 && getvec(direc) == 0) { d = normalize(direc); - if (nchild != -1 && (d == 0.0) & (accumulate != 1)) { + if (nchild != -1 && (d == 0.0) & (accumulate == 0)) { if (!ignore_warning_given++) error(WARNING, "dummy ray(s) ignored during accumulation\n"); @@ -323,9 +328,10 @@ rcontrib() lastray = lastdone = 0; ++lastray; if (d == 0.0) { /* zero ==> flush */ - if ((yres <= 0) | (xres <= 0)) - waitflush = 1; /* flush right after */ - account = 1; + if ((yres <= 0) | (xres <= 1)) + waitflush = 1; /* flush after */ + if (nchild == -1) + account = 1; } else if (imm_irrad) { /* else compute */ eval_irrad(orig, direc); } else { @@ -336,7 +342,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; @@ -344,7 +350,7 @@ rcontrib() account = 1; /* output accumulated totals */ done_contrib(); } + lu_done(&ofiletab); /* close output files */ if (raysleft) error(USER, "unexpected EOF on input"); - lu_done(&ofiletab); /* close output files */ }