14 |
|
|
15 |
|
#include "platform.h" |
16 |
|
#include "RpictSimulManager.h" |
17 |
+ |
#include "func.h" |
18 |
+ |
#include "ambient.h" |
19 |
+ |
#include "pmapray.h" |
20 |
|
#include "random.h" |
21 |
|
|
22 |
|
extern char *progname; /* argv[0] */ |
38 |
|
|
39 |
|
double dblur = 0.; /* depth-of-field blur parameter */ |
40 |
|
|
41 |
< |
int nproc = 1; /* number of processes to run */ |
41 |
> |
int nproc = 1; /* number of processes to run (-1 in child) */ |
42 |
|
|
43 |
|
RpictSimulManager myRPmanager; // global simulation manager |
44 |
|
|
57 |
|
"AdaptiveShadowTesting\nOutputs=v,l\n" \ |
58 |
|
"OutputCS=RGB,XYZ,prims,spec\n" |
59 |
|
|
60 |
< |
|
60 |
> |
// Exit program |
61 |
|
void |
62 |
|
quit(int code) /* quit program */ |
63 |
|
{ |
64 |
< |
exit(code); |
64 |
> |
exit(code); // don't bother to free data structs |
65 |
|
} |
66 |
|
|
67 |
+ |
/* Set default options */ |
68 |
+ |
static void |
69 |
+ |
default_options(void) |
70 |
+ |
{ |
71 |
+ |
shadthresh = .05; |
72 |
+ |
shadcert = .5; |
73 |
+ |
srcsizerat = .25; |
74 |
+ |
directrelay = 1; |
75 |
+ |
ambacc = 0.2; |
76 |
+ |
ambres = 64; |
77 |
+ |
ambdiv = 512; |
78 |
+ |
ambssamp = 128; |
79 |
+ |
maxdepth = 7; |
80 |
+ |
} |
81 |
|
|
82 |
|
int |
83 |
|
main(int argc, char *argv[]) |
105 |
|
strcat(RFeatureList, RXPIECE_FEATURES); |
106 |
|
if (argc > 1 && !strcmp(argv[1], "-features")) |
107 |
|
return feature_status(argc-2, argv+2); |
108 |
+ |
/* initialize calcomp routines */ |
109 |
+ |
initfunc(); |
110 |
+ |
/* set defaults */ |
111 |
+ |
default_options(); |
112 |
|
/* option city */ |
113 |
|
for (i = 1; i < argc; i++) { |
114 |
|
/* expand arguments */ |
336 |
|
// render tiles |
337 |
|
dtype = rpiece(outfile, dtype, zfile); |
338 |
|
|
339 |
< |
quit(dtype==RDTnone); // clean up and exit |
339 |
> |
ambsync(); // flush ambient cache |
340 |
|
|
341 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
342 |
+ |
|
343 |
+ |
quit(dtype==RDTnone); // status is 1 on failure |
344 |
+ |
|
345 |
|
badopt: |
346 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
347 |
|
error(USER, errmsg); |
357 |
|
const char *s |
358 |
|
) |
359 |
|
{ |
360 |
+ |
if (!erract[WARNING].pf) |
361 |
+ |
return; // warnings were disabled! |
362 |
|
int lasterrno = errno; |
363 |
|
eputs(s); |
364 |
|
errno = lasterrno; |
509 |
|
for (ti[1] = 0; ti[1] < tileGrid[1]; ti[1]++) |
510 |
|
for (ti[0] = 0; ti[0] < tileGrid[0]; ti[0]++) |
511 |
|
cnt += renderable_tile(tile_p(ti)); |
512 |
< |
if (!cnt) { // nothing left to do? |
513 |
< |
error(WARNING, "output appears to be complete, nothing added"); |
487 |
< |
return true; |
488 |
< |
} |
512 |
> |
if (!cnt) |
513 |
> |
return false; // parent can do nothing |
514 |
|
if (cnt < nproc) { |
515 |
|
sprintf(errmsg, "only %d renderable tiles, reducing process count", cnt); |
516 |
|
error(WARNING, errmsg); |
526 |
|
|
527 |
|
if (cpid == 0) { // children render tiles |
528 |
|
sleep(nproc - cnt); // avoid race conditions |
529 |
+ |
nproc = -1; // flag as child |
530 |
|
return false; |
531 |
|
} |
532 |
|
cow_doneshare(); // parent frees memory and waits |
626 |
|
|
627 |
|
const bool newOutput = (access(pout, F_OK) < 0); |
628 |
|
FILE *pdfp[2]; |
629 |
< |
if (!newOutput) { // output exists? |
629 |
> |
if (newOutput) { // new output file? |
630 |
> |
CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1), |
631 |
> |
USER, "bad tiling specification"); |
632 |
> |
} else { |
633 |
|
dt = myRPmanager.ReopenOutput(pdfp, pout, zout); |
634 |
|
if (dt == RDTnone) |
635 |
< |
quit(1); |
635 |
> |
return RDTnone; |
636 |
|
if (!fscnresolu(&hresolu, &vresolu, pdfp[0])) |
637 |
|
error(USER, "missing picture resolution"); |
638 |
+ |
pixaspect = .0; // need to leave this as is |
639 |
|
myRPmanager.NewHeader(pout); // get prev. header info |
640 |
|
const char * tval = myRPmanager.GetHeadStr("TILED="); |
641 |
|
if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]); |
642 |
< |
if (!myRPmanager.GetView()) { |
643 |
< |
sprintf(errmsg, "missing view in picture file '%s'", pout); |
614 |
< |
error(USER, errmsg); |
615 |
< |
} |
642 |
> |
CHECK(myRPmanager.GetView()==NULL, |
643 |
> |
USER, "missing view in picture file"); |
644 |
|
ourview = *myRPmanager.GetView(); |
645 |
|
} |
646 |
|
int hvdim[2] = {hresolu, vresolu}; // set up tiled frame |
662 |
|
myRPmanager.AddHeader(buf); |
663 |
|
dt = myRPmanager.NewOutput(pdfp, pout, dt, zout); |
664 |
|
if (dt == RDTnone) |
665 |
< |
quit(1); |
665 |
> |
return RDTnone; |
666 |
|
fprtresolu(hresolu, vresolu, pdfp[0]); |
667 |
< |
} |
668 |
< |
if (RDTdepthT(dt) == RDTdshort) { |
641 |
< |
if (newOutput) |
667 |
> |
fflush(pdfp[0]); |
668 |
> |
if (RDTdepthT(dt) == RDTdshort) { |
669 |
|
fprtresolu(hresolu, vresolu, pdfp[1]); |
670 |
< |
else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
671 |
< |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu)) |
672 |
< |
error(USER, "mismatched depth file resolution"); |
673 |
< |
} |
670 |
> |
fflush(pdfp[1]); |
671 |
> |
} |
672 |
> |
} else if (RDTdepthT(dt) == RDTdshort && |
673 |
> |
(!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) || |
674 |
> |
(hvdim[0] != hresolu) | (hvdim[1] != vresolu))) |
675 |
> |
error(USER, "mismatched depth file resolution"); |
676 |
|
// prepare (flat) pixel buffer |
677 |
|
const long pdata_beg = ftell(pdfp[0]); |
678 |
|
const size_t pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR) |
683 |
|
if (pmlen&7) pmlen += 8 - (pmlen&7); // 8-byte alignment to be safe |
684 |
|
pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1]; |
685 |
|
// map picture file to memory |
686 |
< |
if (ftruncate(fileno(pdfp[0]), pmlen) < 0) |
686 |
> |
if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0) |
687 |
|
error(SYSTEM, "cannot extend picture buffer"); |
688 |
|
uby8 * pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE, |
689 |
|
MAP_SHARED, fileno(pdfp[0]), 0); |
696 |
|
const size_t zmlen = zdata_beg + zdpSiz*hresolu*vresolu; |
697 |
|
uby8 * zdMap = NULL; |
698 |
|
if (RDTdepthT(dt)) { |
699 |
< |
if (ftruncate(fileno(pdfp[1]), zmlen) < 0) |
699 |
> |
if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0) |
700 |
|
error(SYSTEM, "cannot extend depth buffer"); |
701 |
|
zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE, |
702 |
|
MAP_SHARED, fileno(pdfp[1]), 0); |
711 |
|
if (children_finished()) // work done in children? |
712 |
|
return dt; |
713 |
|
|
714 |
< |
int ti[2]; // else render tiles |
714 |
> |
int ndone = 0; // else render tiles |
715 |
> |
int ti[2]; |
716 |
|
while (nexttile(ti)) { |
717 |
|
const int offset = (tileGrid[1]-1-ti[1])*myRPmanager.GetWidth()*myRPmanager.THeight() + |
718 |
|
(myRPmanager.THeight()-1)*myRPmanager.GetWidth() + |
744 |
|
error(USER, errmsg); |
745 |
|
} |
746 |
|
tile_p(ti)->status = 1; // mark tile completed |
747 |
+ |
ndone++; |
748 |
|
} |
749 |
+ |
if (!ndone) |
750 |
+ |
error(WARNING, "no tiles need rendering, exit"); |
751 |
|
/* |
752 |
|
munmap(pixMap, pmlen); // technically unnecessary... |
753 |
|
if (zdMap) munmap(zdMap, zmlen); |