--- ray/src/rt/raycalls.c 2009/12/12 05:20:10 2.17 +++ ray/src/rt/raycalls.c 2019/04/19 16:29:10 2.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raycalls.c,v 2.17 2009/12/12 05:20:10 greg Exp $"; +static const char RCSid[] = "$Id: raycalls.c,v 2.25 2019/04/19 16:29:10 greg Exp $"; #endif /* * raycalls.c - interface for running Radiance rendering as a library @@ -94,11 +94,13 @@ static const char RCSid[] = "$Id: raycalls.c,v 2.17 20 #include "ray.h" #include "source.h" +#include "bsdf.h" #include "ambient.h" #include "otypes.h" #include "random.h" #include "data.h" #include "font.h" +#include "pmapray.h" char *progname = "unknown_app"; /* caller sets to argv[0] */ @@ -119,7 +121,7 @@ void (*addobjnotify[8])() = {ambnotify, NULL}; 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 */ @@ -139,7 +141,7 @@ double specjitter = 1.; /* specular sampling jitter * int backvis = 1; /* back face visibility */ -int maxdepth = 8; /* maximum recursion depth */ +int maxdepth = -10; /* maximum recursion depth */ double minweight = 2e-3; /* minimum ray weight */ char *ambfile = NULL; /* ambient file name */ @@ -154,6 +156,19 @@ char *amblist[AMBLLEN+1]; /* ambient include/exclude int ambincl = -1; /* include == 1, exclude == 0 */ +static void +reset_random(void) /* re-initialize random number generator */ +{ + if (rand_samp) { + srandom((long)time(0)); + initurand(0); + } else { + srandom(0L); + initurand(2048); + } +} + + void ray_init( /* initialize ray-tracing calculation */ char *otnm @@ -165,23 +180,20 @@ ray_init( /* initialize ray-tracing calculation */ if (ofun[OBJ_SPHERE].funp == o_default) initotypes(); /* initialize urand */ - if (rand_samp) { - srandom((long)time(0)); - initurand(0); - } else { - srandom(0L); - initurand(2048); - } + reset_random(); /* read scene octree */ readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); nsceneobjs = nobjects; + /* PMAP: Init & load photon maps */ + ray_init_pmap(); /* find and mark sources */ marksources(); /* initialize ambient calculation */ setambient(); - /* ready to go... */ + /* ready to go... (almost) */ } + void ray_trace( /* trace a primary ray */ RAY *r @@ -207,17 +219,20 @@ ray_done( /* free ray-tracing data */ octdone(); thescene.cutree = EMPTY; octname = NULL; + retainfonts = 0; if (freall) { - retainfonts = 0; freefont(NULL); freedata(NULL); + SDfreeCache(NULL); initurand(0); } if (nobjects > 0) { sprintf(errmsg, "%ld objects left after call to ray_done()", - nobjects); + (long)nobjects); error(WARNING, errmsg); } + + ray_done_pmap(); } @@ -231,6 +246,7 @@ ray_save( /* save current parameter settings */ if (rp == NULL) return; rp->do_irrad = do_irrad; + rp->rand_samp = rand_samp; rp->dstrsrc = dstrsrc; rp->shadthresh = shadthresh; rp->shadcert = shadcert; @@ -247,10 +263,11 @@ ray_save( /* save current parameter settings */ rp->backvis = backvis; rp->maxdepth = maxdepth; rp->minweight = minweight; - copycolor(rp->ambval, ambval); - memset(rp->ambfile, '\0', sizeof(rp->ambfile)); if (ambfile != NULL) strncpy(rp->ambfile, ambfile, sizeof(rp->ambfile)-1); + else + memset(rp->ambfile, '\0', sizeof(rp->ambfile)); + copycolor(rp->ambval, ambval); rp->ambvwt = ambvwt; rp->ambacc = ambacc; rp->ambres = ambres; @@ -265,10 +282,14 @@ ray_save( /* save current parameter settings */ if (ndx+len >= sizeof(rp->amblval)) break; strcpy(rp->amblval+ndx, amblist[i]); + rp->amblndx[i] = ndx; ndx += len+1; } while (i <= AMBLLEN) rp->amblndx[i++] = -1; + + /* PMAP: save photon mapping params */ + ray_save_pmap(rp); } @@ -277,7 +298,7 @@ ray_restore( /* restore parameter settings */ RAYPARAMS *rp ) { - register int i; + int i; if (rp == NULL) { /* restore defaults */ RAYPARAMS dflt; @@ -287,6 +308,10 @@ ray_restore( /* restore parameter settings */ } /* restore saved settings */ do_irrad = rp->do_irrad; + if (!rand_samp != !rp->rand_samp) { + rand_samp = rp->rand_samp; + reset_random(); + } dstrsrc = rp->dstrsrc; shadthresh = rp->shadthresh; shadcert = rp->shadcert; @@ -308,6 +333,7 @@ ray_restore( /* restore parameter settings */ ambdiv = rp->ambdiv; ambssamp = rp->ambssamp; ambounce = rp->ambounce; + /* a bit dangerous if not static */ for (i = 0; rp->amblndx[i] >= 0; i++) amblist[i] = rp->amblval + rp->amblndx[i]; while (i <= AMBLLEN) @@ -337,6 +363,9 @@ ray_restore( /* restore parameter settings */ ambres = rp->ambres; ambacc = rp->ambacc; } + + /* PMAP: restore photon mapping params */ + ray_restore_pmap(rp); } @@ -351,6 +380,7 @@ ray_defaults( /* get default parameter values */ return; rp->do_irrad = 0; + rp->rand_samp = 1; rp->dstrsrc = 0.0; rp->shadthresh = .03; rp->shadcert = .75; @@ -365,10 +395,10 @@ ray_defaults( /* get default parameter values */ rp->specthresh = .15; rp->specjitter = 1.; rp->backvis = 1; - rp->maxdepth = 8; + rp->maxdepth = -10; rp->minweight = 2e-3; - setcolor(rp->ambval, 0., 0., 0.); memset(rp->ambfile, '\0', sizeof(rp->ambfile)); + setcolor(rp->ambval, 0., 0., 0.); rp->ambvwt = 0; rp->ambres = 256; rp->ambacc = 0.15; @@ -379,4 +409,7 @@ ray_defaults( /* get default parameter values */ memset(rp->amblval, '\0', sizeof(rp->amblval)); for (i = AMBLLEN+1; i--; ) rp->amblndx[i] = -1; + + /* PMAP: restore photon mapping defaults */ + ray_defaults_pmap(rp); }