48 |
|
CUBE thescene; /* our scene */ |
49 |
|
OBJECT nsceneobjs; /* number of objects in our scene */ |
50 |
|
|
51 |
+ |
extern RGBPRIMP out_prims; /* output color primitives (NULL if spectral) */ |
52 |
+ |
|
53 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
54 |
|
int ndims = 0; /* number of sampling dimensions */ |
55 |
|
int samplendx; /* sample index number */ |
94 |
|
int backvis = 1; /* back face visibility */ |
95 |
|
|
96 |
|
int maxdepth = 7; /* maximum recursion depth */ |
97 |
< |
double minweight = 1e-3; /* minimum ray weight */ |
97 |
> |
double minweight = 1e-4; /* minimum ray weight */ |
98 |
|
|
99 |
|
char *ambfile = NULL; /* ambient file name */ |
100 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
119 |
|
|
120 |
|
int hres, vres; /* resolution for this frame */ |
121 |
|
|
122 |
+ |
extern void sskip_ray(RAY *r, double h, double v); |
123 |
+ |
|
124 |
|
static VIEW lastview; /* the previous view input */ |
125 |
|
|
126 |
|
static void report(int); |
138 |
|
|
139 |
|
|
140 |
|
|
137 |
– |
#ifdef RHAS_STAT |
138 |
– |
#include <sys/types.h> |
139 |
– |
#include <sys/stat.h> |
140 |
– |
int |
141 |
– |
file_exists(fname) /* ordinary file exists? */ |
142 |
– |
char *fname; |
143 |
– |
{ |
144 |
– |
struct stat sbuf; |
145 |
– |
if (stat(fname, &sbuf) < 0) return(0); |
146 |
– |
return((sbuf.st_mode & S_IFREG) != 0); |
147 |
– |
} |
148 |
– |
#else |
149 |
– |
#define file_exists(f) (access(f,F_OK)==0) |
150 |
– |
#endif |
151 |
– |
|
152 |
– |
|
141 |
|
void |
142 |
< |
quit(code) /* quit program */ |
155 |
< |
int code; |
142 |
> |
quit(int code) /* quit program */ |
143 |
|
{ |
144 |
|
if (code) /* report status */ |
145 |
|
report(0); |
289 |
|
do { |
290 |
|
if (seq && nextview(stdin) == EOF) |
291 |
|
break; |
292 |
+ |
lastview.type *= seq > 1; |
293 |
|
pctdone = 0.0; |
294 |
|
if (pout != NULL) { |
295 |
+ |
int myfd; |
296 |
+ |
close(1); /* reassign stdout */ |
297 |
|
sprintf(fbuf, pout, seq); |
298 |
< |
if (file_exists(fbuf)) { |
299 |
< |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
298 |
> |
tryagain: |
299 |
> |
errno = 0; /* exclusive open */ |
300 |
> |
if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) { |
301 |
> |
if ((errno != EEXIST) | (prvr != NULL) || |
302 |
> |
!strcmp(fbuf, pout)) { |
303 |
|
sprintf(errmsg, |
304 |
< |
"output file \"%s\" exists", |
304 |
> |
"cannot open output file \"%s\"", |
305 |
|
fbuf); |
306 |
< |
error(USER, errmsg); |
306 |
> |
error(SYSTEM, errmsg); |
307 |
|
} |
308 |
|
setview(&ourview); |
309 |
|
continue; /* don't clobber */ |
310 |
|
} |
311 |
< |
if (freopen(fbuf, "w", stdout) == NULL) { |
312 |
< |
sprintf(errmsg, |
313 |
< |
"cannot open output file \"%s\"", fbuf); |
321 |
< |
error(SYSTEM, errmsg); |
311 |
> |
if (myfd != 1) { |
312 |
> |
unlink(fbuf); |
313 |
> |
goto tryagain; /* leave it open */ |
314 |
|
} |
315 |
< |
SET_FILE_BINARY(stdout); |
315 |
> |
SET_FD_BINARY(1); |
316 |
|
dupheader(); |
317 |
|
} |
318 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
345 |
|
if ((pa < .99) | (pa > 1.01)) |
346 |
|
fputaspect(pa, stdout); |
347 |
|
fputnow(stdout); |
348 |
< |
fputformat(COLRFMT, stdout); |
349 |
< |
putchar('\n'); |
348 |
> |
if (out_prims == xyzprims) { |
349 |
> |
fputformat(CIEFMT, stdout); |
350 |
> |
} else { |
351 |
> |
fputprims(out_prims, stdout); |
352 |
> |
fputformat(COLRFMT, stdout); |
353 |
> |
} |
354 |
> |
putchar('\n'); /* close header */ |
355 |
|
if (zout != NULL) |
356 |
|
sprintf(cp=fbuf, zout, seq); |
357 |
|
else |
387 |
|
char *oldfile |
388 |
|
) |
389 |
|
{ |
390 |
+ |
const int srcdrawing = /* manually draw tiny light sources? */ |
391 |
+ |
(directvis && dblur <= FTINY && (mblur <= FTINY) | !lastview.type); |
392 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
393 |
|
float *zbar[MAXDIV+1]; /* z values */ |
394 |
|
char *sampdens; /* previous sample density */ |
455 |
|
signal(SIGCONT, report); |
456 |
|
#endif |
457 |
|
ypos = vres-1 - i; /* initialize sampling */ |
458 |
< |
if (directvis) |
458 |
> |
if (srcdrawing) |
459 |
|
init_drawsources(psample); |
460 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
461 |
|
/* compute scanlines */ |
476 |
|
hres, ypos, hstep); |
477 |
|
/* fill bar */ |
478 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
479 |
< |
if (directvis) /* add bitty sources */ |
480 |
< |
drawsources(scanbar, zbar, 0, hres, ypos, ystep); |
479 |
> |
if (srcdrawing) /* add bitty sources */ |
480 |
> |
drawsources((COLORV **)scanbar, out_prims, zbar, 0, hres, ypos, ystep); |
481 |
|
/* write it out */ |
482 |
|
#ifdef SIGCONT |
483 |
|
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
671 |
|
int y |
672 |
|
) |
673 |
|
{ |
675 |
– |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
674 |
|
RAY thisray; |
675 |
|
FVECT lorg, ldir; |
676 |
< |
double hpos, vpos, vdist, lmax; |
676 |
> |
double hpos, vpos, lmax; |
677 |
|
int i; |
678 |
|
/* compute view ray */ |
679 |
|
setcolor(col, 0.0, 0.0, 0.0); |
682 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
683 |
|
&ourview, hpos, vpos)) < -FTINY) |
684 |
|
return(0.0); |
687 |
– |
|
688 |
– |
vdist = ourview.vdist; |
685 |
|
/* set pixel index */ |
686 |
|
samplendx = pixnumber(x,y,hres,vres); |
687 |
|
/* optional motion blur */ |
696 |
|
} |
697 |
|
if (normalize(thisray.rdir) == 0.0) |
698 |
|
return(0.0); |
703 |
– |
vdist = (1.-d)*vdist + d*lastview.vdist; |
699 |
|
} |
700 |
< |
/* optional depth-of-field */ |
701 |
< |
if (dblur > FTINY) { |
702 |
< |
double vc, df[2]; |
708 |
< |
/* random point on disk */ |
709 |
< |
SDsquare2disk(df, frandom(), frandom()); |
710 |
< |
df[0] *= .5*dblur; |
711 |
< |
df[1] *= .5*dblur; |
712 |
< |
if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) { |
713 |
< |
double adj = 1.0; |
714 |
< |
if (ourview.type == VT_PER) |
715 |
< |
adj /= DOT(thisray.rdir, ourview.vdir); |
716 |
< |
df[0] /= sqrt(ourview.hn2); |
717 |
< |
df[1] /= sqrt(ourview.vn2); |
718 |
< |
for (i = 3; i--; ) { |
719 |
< |
vc = ourview.vp[i] + adj*vdist*thisray.rdir[i]; |
720 |
< |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
721 |
< |
df[1]*ourview.vvec[i] ; |
722 |
< |
thisray.rdir[i] = vc - thisray.rorg[i]; |
723 |
< |
} |
724 |
< |
} else { /* non-standard view case */ |
725 |
< |
double dfd = PI/4.*dblur*(.5 - frandom()); |
726 |
< |
if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) { |
727 |
< |
if (ourview.type != VT_CYL) |
728 |
< |
df[0] /= sqrt(ourview.hn2); |
729 |
< |
df[1] /= sqrt(ourview.vn2); |
730 |
< |
} |
731 |
< |
for (i = 3; i--; ) { |
732 |
< |
vc = ourview.vp[i] + vdist*thisray.rdir[i]; |
733 |
< |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
734 |
< |
df[1]*ourview.vvec[i] + |
735 |
< |
dfd*ourview.vdir[i] ; |
736 |
< |
thisray.rdir[i] = vc - thisray.rorg[i]; |
737 |
< |
} |
738 |
< |
} |
739 |
< |
if (normalize(thisray.rdir) == 0.0) |
740 |
< |
return(0.0); |
741 |
< |
} |
700 |
> |
/* depth-of-field */ |
701 |
> |
if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur)) |
702 |
> |
return(0.0); |
703 |
|
|
704 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
705 |
|
|
706 |
|
rayvalue(&thisray); /* trace ray */ |
707 |
< |
|
708 |
< |
copycolor(col, thisray.rcol); /* return color */ |
707 |
> |
/* -> color */ |
708 |
> |
scolor_out(col, out_prims, thisray.rcol); |
709 |
|
|
710 |
|
return(raydistance(&thisray)); /* return distance */ |
711 |
|
} |