--- ray/src/rt/rcontrib.c 2012/06/22 22:03:02 2.13 +++ ray/src/rt/rcontrib.c 2012/11/15 15:26:52 2.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.13 2012/06/22 22:03:02 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.17 2012/11/15 15:26:52 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -8,6 +8,7 @@ static const char RCSid[] = "$Id: rcontrib.c,v 2.13 20 #include "rcontrib.h" #include "otypes.h" +#include "source.h" char *shm_boundary = NULL; /* boundary of shared memory */ @@ -176,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; @@ -223,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); } @@ -249,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); @@ -308,7 +316,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"); @@ -319,8 +327,9 @@ rcontrib() ++lastray; if (d == 0.0) { /* zero ==> flush */ if ((yres <= 0) | (xres <= 0)) - waitflush = 1; /* flush right after */ - account = 1; + waitflush = 1; /* flush after */ + if (nchild == -1) + account = 1; } else if (imm_irrad) { /* else compute */ eval_irrad(orig, direc); } else {