--- ray/src/rt/rxpiece.cpp 2024/09/17 00:05:11 2.2 +++ ray/src/rt/rxpiece.cpp 2025/04/22 17:12:25 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rxpiece.cpp,v 2.2 2024/09/17 00:05:11 greg Exp $"; +static const char RCSid[] = "$Id: rxpiece.cpp,v 2.11 2025/04/22 17:12:25 greg Exp $"; #endif /* * rxpiece.cpp - main for rxpiece tile rendering program @@ -14,6 +14,9 @@ static const char RCSid[] = "$Id: rxpiece.cpp,v 2.2 20 #include "platform.h" #include "RpictSimulManager.h" +#include "func.h" +#include "ambient.h" +#include "pmapray.h" #include "random.h" extern char *progname; /* argv[0] */ @@ -35,7 +38,7 @@ double mblur = 0.; /* motion blur parameter (unused double dblur = 0.; /* depth-of-field blur parameter */ -int nproc = 1; /* number of processes to run */ +int nproc = 1; /* number of processes to run (-1 in child) */ RpictSimulManager myRPmanager; // global simulation manager @@ -54,13 +57,27 @@ static RenderDataType rpiece(char *pout, RenderDataTyp "AdaptiveShadowTesting\nOutputs=v,l\n" \ "OutputCS=RGB,XYZ,prims,spec\n" - +// Exit program void quit(int code) /* quit program */ { - exit(code); + exit(code); // don't bother to free data structs } +/* Set default options */ +static void +default_options(void) +{ + shadthresh = .05; + shadcert = .5; + srcsizerat = .25; + directrelay = 1; + ambacc = 0.2; + ambres = 64; + ambdiv = 512; + ambssamp = 128; + maxdepth = 7; +} int main(int argc, char *argv[]) @@ -88,6 +105,10 @@ main(int argc, char *argv[]) strcat(RFeatureList, RXPIECE_FEATURES); if (argc > 1 && !strcmp(argv[1], "-features")) return feature_status(argc-2, argv+2); + /* initialize calcomp routines */ + initfunc(); + /* set defaults */ + default_options(); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -315,8 +336,12 @@ main(int argc, char *argv[]) // render tiles dtype = rpiece(outfile, dtype, zfile); - quit(dtype==RDTnone); // clean up and exit + ambsync(); // flush ambient cache + ray_done_pmap(); /* PMAP: free photon maps */ + + quit(dtype==RDTnone); // status is 1 on failure + badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); @@ -332,6 +357,8 @@ wputs( /* warning output function */ const char *s ) { + if (!erract[WARNING].pf) + return; // warnings were disabled! int lasterrno = errno; eputs(s); errno = lasterrno; @@ -499,6 +526,7 @@ children_finished() if (cpid == 0) { // children render tiles sleep(nproc - cnt); // avoid race conditions + nproc = -1; // flag as child return false; } cow_doneshare(); // parent frees memory and waits @@ -598,20 +626,21 @@ rpiece(char *pout, RenderDataType dt, char *zout) const bool newOutput = (access(pout, F_OK) < 0); FILE *pdfp[2]; - if (!newOutput) { // output exists? + if (newOutput) { // new output file? + CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1), + USER, "bad tiling specification"); + } else { dt = myRPmanager.ReopenOutput(pdfp, pout, zout); if (dt == RDTnone) - quit(1); + return RDTnone; if (!fscnresolu(&hresolu, &vresolu, pdfp[0])) error(USER, "missing picture resolution"); pixaspect = .0; // need to leave this as is myRPmanager.NewHeader(pout); // get prev. header info const char * tval = myRPmanager.GetHeadStr("TILED="); if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]); - if (!myRPmanager.GetView()) { - sprintf(errmsg, "missing view in picture file '%s'", pout); - error(USER, errmsg); - } + CHECK(myRPmanager.GetView()==NULL, + USER, "missing view in picture file"); ourview = *myRPmanager.GetView(); } int hvdim[2] = {hresolu, vresolu}; // set up tiled frame @@ -633,16 +662,17 @@ rpiece(char *pout, RenderDataType dt, char *zout) myRPmanager.AddHeader(buf); dt = myRPmanager.NewOutput(pdfp, pout, dt, zout); if (dt == RDTnone) - quit(1); + return RDTnone; fprtresolu(hresolu, vresolu, pdfp[0]); - } - if (RDTdepthT(dt) == RDTdshort) { - if (newOutput) + fflush(pdfp[0]); + if (RDTdepthT(dt) == RDTdshort) { fprtresolu(hresolu, vresolu, pdfp[1]); - else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || - (hvdim[0] != hresolu) | (hvdim[1] != vresolu)) - error(USER, "mismatched depth file resolution"); - } + fflush(pdfp[1]); + } + } else if (RDTdepthT(dt) == RDTdshort && + (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || + (hvdim[0] != hresolu) | (hvdim[1] != vresolu))) + error(USER, "mismatched depth file resolution"); // prepare (flat) pixel buffer const long pdata_beg = ftell(pdfp[0]); const size_t pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR) @@ -653,7 +683,7 @@ rpiece(char *pout, RenderDataType dt, char *zout) if (pmlen&7) pmlen += 8 - (pmlen&7); // 8-byte alignment to be safe pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1]; // map picture file to memory - if (ftruncate(fileno(pdfp[0]), pmlen) < 0) + if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0) error(SYSTEM, "cannot extend picture buffer"); uby8 * pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(pdfp[0]), 0); @@ -666,7 +696,7 @@ rpiece(char *pout, RenderDataType dt, char *zout) const size_t zmlen = zdata_beg + zdpSiz*hresolu*vresolu; uby8 * zdMap = NULL; if (RDTdepthT(dt)) { - if (ftruncate(fileno(pdfp[1]), zmlen) < 0) + if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0) error(SYSTEM, "cannot extend depth buffer"); zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(pdfp[1]), 0); @@ -714,6 +744,7 @@ rpiece(char *pout, RenderDataType dt, char *zout) error(USER, errmsg); } tile_p(ti)->status = 1; // mark tile completed + ndone++; } if (!ndone) error(WARNING, "no tiles need rendering, exit");