--- ray/src/rt/rcontrib.c 2012/06/10 05:25:42 2.2 +++ ray/src/rt/rcontrib.c 2012/06/15 00:57:40 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.2 2012/06/10 05:25:42 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.6 2012/06/15 00:57:40 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -25,7 +25,7 @@ void (*trace)() = trace_contrib; int do_irrad = 0; /* compute irradiance? */ -int rand_samp = 0; /* pure Monte Carlo sampling? */ +int rand_samp = 1; /* pure Monte Carlo sampling? */ double dstrsrc = 0.0; /* square source distribution */ double shadthresh = .03; /* shadow threshold */ @@ -45,8 +45,8 @@ double specjitter = 1.; /* specular sampling jitter * int backvis = 1; /* back face visibility */ -int maxdepth = 8; /* maximum recursion depth */ -double minweight = 5e-4; /* minimum ray weight */ +int maxdepth = -10; /* maximum recursion depth */ +double minweight = 2e-3; /* minimum ray weight */ char *ambfile = NULL; /* ambient file name */ COLOR ambval = BLKCOLOR; /* ambient value */ @@ -63,66 +63,15 @@ int account; /* current accumulation count */ RNUMBER raysleft; /* number of rays left to trace */ long waitflush; /* how long until next flush */ -int lastray = 0; /* last ray number sent */ -int lastdone = 0; /* last ray output */ +RNUMBER lastray = 0; /* last ray number sent */ +RNUMBER lastdone = 0; /* last ray output */ -/* Close output stream and free record */ -static void -closestream(void *p) -{ - STREAMOUT *sop = (STREAMOUT *)p; - int status = 0; - if (sop->outpipe) - status = pclose(sop->ofp); - else if (sop->ofp != stdout) - status = fclose(sop->ofp); - if (status) - error(SYSTEM, "error closing output stream"); - free(p); -} - -LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ - -#define OF_MODIFIER 01 -#define OF_BIN 02 - static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); } LUTAB modconttab = LU_SINIT(NULL,mcfree); /* modifier lookup table */ -static OBJECT traset[MAXTSET+1]={0}; /* trace include set */ - /************************** INITIALIZATION ROUTINES ***********************/ -void -tranotify( /* record new modifier */ - OBJECT obj -) -{ - static int hitlimit = 0; - OBJREC *o = objptr(obj); - int i; - - if (obj == OVOID) { /* starting over */ - traset[0] = 0; - hitlimit = 0; - return; - } - if (hitlimit || !ismodifier(o->otype)) - return; - for (i = nmods; i-- > 0; ) - if (!strcmp(o->oname, modname[i])) { - if (traset[0] >= MAXTSET) { - error(WARNING, "too many same-named modifiers"); - hitlimit++; - return; /* should this be fatal? */ - } - insertelem(traset, obj); - break; - } -} - - char * formstr( /* return format identifier */ int f @@ -232,14 +181,6 @@ rcinit() if ((nproc > 1) & (accumulate <= 0)) put_zero_record(0); /* prime our queue to accumulate */ - if (recover) { /* recover previous output? */ - if (accumulate <= 0) { - reload_output(); - if (nproc > 1) - queue_modifiers(); - } else - recover_output(); - } if (yres > 0) { /* set up flushing & ray counts */ if (xres > 0) raysleft = (RNUMBER)xres*yres; @@ -254,9 +195,20 @@ rcinit() for (i = 0; i < nsources; i++) source[i].sflags |= SFOLLOW; - if (nproc == 1 || in_rchild()) /* single process or child */ + if (nproc > 1 && in_rchild()) /* forked child? */ return; /* return to main processing loop */ + if (recover) { /* recover previous output? */ + if (accumulate <= 0) { + reload_output(); + if (nproc > 1) + queue_modifiers(); + } else + recover_output(); + } + if (nproc == 1) /* single process? */ + return; + parental_loop(); /* else run controller */ quit(0); /* parent musn't return! */ } @@ -271,13 +223,13 @@ trace_contrib(RAY *r) int bn; RREAL contr[3]; - if (r->ro == NULL || !inset(traset, r->ro->omod)) + if (r->ro == NULL || r->ro->omod == OVOID) return; mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data; - if (mp == NULL) - error(CONSISTENCY, "unexpected modifier in trace_contrib()"); + if (mp == NULL) /* not in our list? */ + return; worldfunc(RCCONTEXT, r); /* get bin number */ bn = (int)(evalue(mp->binv) + .5); @@ -370,7 +322,7 @@ rcontrib() #endif while (getvec(orig) == 0 && getvec(direc) == 0) { d = normalize(direc); - if ((d == 0.0) & (accumulate != 1)) { + if (nchild != -1 && (d == 0.0) & (accumulate != 1)) { if (!ignore_warning_given++) error(WARNING, "dummy ray(s) ignored during accumulation\n"); @@ -382,6 +334,7 @@ rcontrib() if (d == 0.0) { /* zero ==> flush */ if ((yres <= 0) | (xres <= 0)) waitflush = 1; /* flush right after */ + account = 1; } else { /* else compute */ eval_ray(orig, direc, lim_dist ? d : 0.0); } @@ -390,7 +343,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;