--- ray/src/rt/raycalls.c 2018/01/23 23:37:11 2.23 +++ ray/src/rt/raycalls.c 2023/02/02 18:55:09 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raycalls.c,v 2.23 2018/01/23 23:37:11 greg Exp $"; +static const char RCSid[] = "$Id: raycalls.c,v 2.28 2023/02/02 18:55:09 greg Exp $"; #endif /* * raycalls.c - interface for running Radiance rendering as a library @@ -119,9 +119,11 @@ void (*trace)() = NULL; /* trace call */ void (*addobjnotify[8])() = {ambnotify, NULL}; +int castonly = 0; /* only doing ray-casting? */ + 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 */ @@ -141,8 +143,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 = 1e-4; /* minimum ray weight */ char *ambfile = NULL; /* ambient file name */ COLOR ambval = BLKCOLOR; /* ambient value */ @@ -156,6 +158,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 @@ -167,25 +182,24 @@ 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); - } - /* read scene octree */ - readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); + reset_random(); + + octname = savqstr(otnm); /* read scene octree */ + readoct(octname, ~(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... (almost) */ + + if (!castonly) { /* any actual ray traversal to do? */ + + ray_init_pmap(); /* PMAP: set up & load photon maps */ + + marksources(); /* find and mark sources */ + + setambient(); /* initialize ambient calculation */ + } else + distantsources(); /* else mark only distant sources */ } + void ray_trace( /* trace a primary ray */ RAY *r @@ -210,7 +224,7 @@ ray_done( /* free ray-tracing data */ donesets(); octdone(); thescene.cutree = EMPTY; - octname = NULL; + freeqstr(octname); octname = NULL; retainfonts = 0; if (freall) { freefont(NULL); @@ -238,6 +252,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; @@ -254,10 +269,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; @@ -288,7 +304,7 @@ ray_restore( /* restore parameter settings */ RAYPARAMS *rp ) { - register int i; + int i; if (rp == NULL) { /* restore defaults */ RAYPARAMS dflt; @@ -298,6 +314,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; @@ -319,6 +339,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) @@ -365,9 +386,10 @@ 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; + rp->shadthresh = 0.03; + rp->shadcert = 0.75; rp->directrelay = 2; rp->vspretest = 512; rp->directvis = 1; @@ -376,16 +398,16 @@ ray_defaults( /* get default parameter values */ setcolor(rp->salbedo, 0., 0., 0.); rp->seccg = 0.; rp->ssampdist = 0.; - rp->specthresh = .15; + rp->specthresh = 0.15; rp->specjitter = 1.; rp->backvis = 1; - rp->maxdepth = 8; - rp->minweight = 2e-3; - setcolor(rp->ambval, 0., 0., 0.); + rp->maxdepth = -10; + rp->minweight = 1e-4; memset(rp->ambfile, '\0', sizeof(rp->ambfile)); + setcolor(rp->ambval, 0., 0., 0.); rp->ambvwt = 0; rp->ambres = 256; - rp->ambacc = 0.15; + rp->ambacc = 0.1; rp->ambdiv = 1024; rp->ambssamp = 512; rp->ambounce = 0;