1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* rpict.c - routines and variables for picture generation. |
7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
– |
#include "ray.h" |
11 |
– |
|
10 |
|
#include <sys/types.h> |
11 |
|
|
12 |
|
#ifndef NON_POSIX |
23 |
|
#include <signal.h> |
24 |
|
|
25 |
|
#include "platform.h" |
26 |
+ |
#include "ray.h" |
27 |
+ |
#include "paths.h" |
28 |
+ |
#include "ambient.h" |
29 |
|
#include "view.h" |
30 |
|
#include "random.h" |
31 |
|
#include "paths.h" |
32 |
+ |
#include "rtmisc.h" /* myhostname() */ |
33 |
|
|
34 |
|
|
35 |
|
#define RFTEMPLATE "rfXXXXXX" |
47 |
|
int ndims = 0; /* number of sampling dimensions */ |
48 |
|
int samplendx; /* sample index number */ |
49 |
|
|
50 |
< |
extern void ambnotify(); |
50 |
> |
//extern void ambnotify(); |
51 |
|
void (*addobjnotify[])() = {ambnotify, NULL}; |
52 |
|
|
53 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
61 |
|
|
62 |
|
double mblur = 0.; /* motion blur parameter */ |
63 |
|
|
64 |
+ |
double dblur = 0.; /* depth-of-field blur parameter */ |
65 |
+ |
|
66 |
|
void (*trace)() = NULL; /* trace call */ |
67 |
|
|
68 |
|
int do_irrad = 0; /* compute irradiance? */ |
85 |
|
|
86 |
|
int backvis = 1; /* back face visibility */ |
87 |
|
|
88 |
< |
int maxdepth = 6; /* maximum recursion depth */ |
89 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
88 |
> |
int maxdepth = 7; /* maximum recursion depth */ |
89 |
> |
double minweight = 4e-3; /* minimum ray weight */ |
90 |
|
|
91 |
|
char *ambfile = NULL; /* ambient file name */ |
92 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
93 |
|
int ambvwt = 0; /* initial weight for ambient value */ |
94 |
|
double ambacc = 0.2; /* ambient accuracy */ |
95 |
< |
int ambres = 32; /* ambient resolution */ |
96 |
< |
int ambdiv = 128; /* ambient divisions */ |
97 |
< |
int ambssamp = 0; /* ambient super-samples */ |
95 |
> |
int ambres = 64; /* ambient resolution */ |
96 |
> |
int ambdiv = 512; /* ambient divisions */ |
97 |
> |
int ambssamp = 128; /* ambient super-samples */ |
98 |
|
int ambounce = 0; /* ambient bounces */ |
99 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
99 |
> |
char *amblist[AMBLLEN]; /* ambient include/exclude list */ |
100 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
101 |
|
|
102 |
|
int ralrm = 0; /* seconds between reports */ |
113 |
|
|
114 |
|
static VIEW lastview; /* the previous view input */ |
115 |
|
|
116 |
< |
extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ |
116 |
> |
//extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ |
117 |
|
|
118 |
< |
void report(); |
118 |
> |
//double pixvalue(); |
119 |
|
|
120 |
< |
double pixvalue(); |
120 |
> |
static void report(int); |
121 |
> |
static int nextview(FILE *fp); |
122 |
> |
static void render(char *zfile, char *oldfile); |
123 |
> |
static void fillscanline(COLOR *scanline, float *zline, char *sd, int xres, |
124 |
> |
int y, int xstep); |
125 |
> |
static void fillscanbar(COLOR *scanbar[], float *zbar[], int xres, |
126 |
> |
int y, int ysize); |
127 |
> |
static int fillsample(COLOR *colline, float *zline, int x, int y, |
128 |
> |
int xlen, int ylen, int b); |
129 |
> |
static double pixvalue(COLOR col, int x, int y); |
130 |
> |
static int salvage(char *oldfile); |
131 |
> |
static int pixnumber(int x, int y, int xres, int yres); |
132 |
|
|
133 |
+ |
|
134 |
+ |
|
135 |
|
#ifdef RHAS_STAT |
136 |
|
#include <sys/types.h> |
137 |
|
#include <sys/stat.h> |
153 |
|
int code; |
154 |
|
{ |
155 |
|
if (code) /* report status */ |
156 |
< |
report(); |
156 |
> |
report(0); |
157 |
|
#ifndef NON_POSIX |
158 |
|
headclean(); /* delete header file */ |
159 |
|
pfclean(); /* clean up persist files */ |
163 |
|
|
164 |
|
|
165 |
|
#ifndef NON_POSIX |
166 |
< |
void |
167 |
< |
report() /* report progress */ |
166 |
> |
static void |
167 |
> |
report(int dummy) /* report progress */ |
168 |
|
{ |
152 |
– |
extern char *myhostname(); |
169 |
|
double u, s; |
170 |
|
#ifdef BSD |
171 |
|
struct rusage rubuf; |
203 |
|
#endif |
204 |
|
} |
205 |
|
#else |
206 |
< |
void |
207 |
< |
report() /* report progress */ |
206 |
> |
static void |
207 |
> |
report(int dummy) /* report progress */ |
208 |
|
{ |
209 |
|
tlastrept = time((time_t *)NULL); |
210 |
|
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
214 |
|
#endif |
215 |
|
|
216 |
|
|
217 |
< |
void |
218 |
< |
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
219 |
< |
int seq; |
220 |
< |
char *pout, *zout, *prvr; |
217 |
> |
extern void |
218 |
> |
rpict( /* generate image(s) */ |
219 |
> |
int seq, |
220 |
> |
char *pout, |
221 |
> |
char *zout, |
222 |
> |
char *prvr |
223 |
> |
) |
224 |
|
/* |
225 |
|
* If seq is greater than zero, then we will render a sequence of |
226 |
|
* images based on view parameter strings read from the standard input. |
262 |
|
setview(&ourview); |
263 |
|
prvr = fbuf; /* mark for renaming */ |
264 |
|
} |
265 |
< |
if (pout != NULL & prvr != NULL) { |
265 |
> |
if ((pout != NULL) & (prvr != NULL)) { |
266 |
|
sprintf(fbuf, pout, seq); |
267 |
|
if (!strcmp(prvr, fbuf)) { /* rename */ |
268 |
|
strcpy(fbuf2, fbuf); |
272 |
|
cp--; |
273 |
|
strcpy(cp, RFTEMPLATE); |
274 |
|
prvr = mktemp(fbuf2); |
275 |
< |
if (rename(fbuf, prvr) < 0) |
275 |
> |
if (rename(fbuf, prvr) < 0) { |
276 |
|
if (errno == ENOENT) { /* ghost file */ |
277 |
|
sprintf(errmsg, |
278 |
|
"new output file \"%s\"", |
285 |
|
fbuf, prvr); |
286 |
|
error(SYSTEM, errmsg); |
287 |
|
} |
288 |
+ |
} |
289 |
|
} |
290 |
|
} |
291 |
|
npicts = 0; /* render sequence */ |
314 |
|
dupheader(); |
315 |
|
} |
316 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
317 |
< |
if (prvr != NULL) |
318 |
< |
if (viewfile(prvr, &ourview, &rs) <= 0 |
299 |
< |
|| rs.rt != PIXSTANDARD) { |
317 |
> |
if (prvr != NULL) { |
318 |
> |
if (viewfile(prvr, &ourview, &rs) <= 0) { |
319 |
|
sprintf(errmsg, |
320 |
|
"cannot recover view parameters from \"%s\"", prvr); |
321 |
|
error(WARNING, errmsg); |
324 |
|
hres = scanlen(&rs); |
325 |
|
vres = numscans(&rs); |
326 |
|
} |
327 |
+ |
} |
328 |
|
if ((cp = setview(&ourview)) != NULL) |
329 |
|
error(USER, cp); |
330 |
|
normaspect(viewaspect(&ourview), &pa, &hres, &vres); |
342 |
|
putchar('\n'); |
343 |
|
if (pa < .99 || pa > 1.01) |
344 |
|
fputaspect(pa, stdout); |
345 |
< |
fputnow(); |
345 |
> |
fputnow(stdout); |
346 |
|
fputformat(COLRFMT, stdout); |
347 |
|
putchar('\n'); |
348 |
|
if (zout != NULL) |
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
< |
nextview(fp) /* get next view from fp */ |
363 |
< |
FILE *fp; |
362 |
> |
static int |
363 |
> |
nextview( /* get next view from fp */ |
364 |
> |
FILE *fp |
365 |
> |
) |
366 |
|
{ |
367 |
|
char linebuf[256]; |
368 |
|
|
369 |
< |
copystruct(&lastview, &ourview); |
369 |
> |
lastview = ourview; |
370 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
371 |
|
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
372 |
|
return(0); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
render(zfile, oldfile) /* render the scene */ |
378 |
< |
char *zfile, *oldfile; |
377 |
> |
static void |
378 |
> |
render( /* render the scene */ |
379 |
> |
char *zfile, |
380 |
> |
char *oldfile |
381 |
> |
) |
382 |
|
{ |
383 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
384 |
|
float *zbar[MAXDIV+1]; /* z values */ |
436 |
|
if (i >= vres) |
437 |
|
goto alldone; |
438 |
|
if (zfd != -1 && i > 0 && |
439 |
< |
lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) |
439 |
> |
lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0) |
440 |
|
error(SYSTEM, "z-file seek error in render"); |
441 |
|
pctdone = 100.0*i/vres; |
442 |
|
if (ralrm > 0) /* report init stats */ |
443 |
< |
report(); |
443 |
> |
report(0); |
444 |
|
#ifdef SIGCONT |
445 |
|
else |
446 |
|
signal(SIGCONT, report); |
486 |
|
/* record progress */ |
487 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
488 |
|
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
489 |
< |
report(); |
489 |
> |
report(0); |
490 |
|
#ifdef SIGCONT |
491 |
|
else |
492 |
|
signal(SIGCONT, report); |
515 |
|
free(sampdens); |
516 |
|
pctdone = 100.0; |
517 |
|
if (ralrm > 0) |
518 |
< |
report(); |
518 |
> |
report(0); |
519 |
|
#ifdef SIGCONT |
520 |
|
signal(SIGCONT, SIG_DFL); |
521 |
|
#endif |
527 |
|
} |
528 |
|
|
529 |
|
|
530 |
< |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
531 |
< |
register COLOR *scanline; |
532 |
< |
register float *zline; |
533 |
< |
register char *sd; |
534 |
< |
int xres, y, xstep; |
530 |
> |
static void |
531 |
> |
fillscanline( /* fill scan at y */ |
532 |
> |
register COLOR *scanline, |
533 |
> |
register float *zline, |
534 |
> |
register char *sd, |
535 |
> |
int xres, |
536 |
> |
int y, |
537 |
> |
int xstep |
538 |
> |
) |
539 |
|
{ |
540 |
|
static int nc = 0; /* number of calls */ |
541 |
|
int bl = xstep, b = xstep; |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
< |
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
570 |
< |
register COLOR *scanbar[]; |
571 |
< |
register float *zbar[]; |
572 |
< |
int xres, y, ysize; |
569 |
> |
static void |
570 |
> |
fillscanbar( /* fill interior */ |
571 |
> |
register COLOR *scanbar[], |
572 |
> |
register float *zbar[], |
573 |
> |
int xres, |
574 |
> |
int y, |
575 |
> |
int ysize |
576 |
> |
) |
577 |
|
{ |
578 |
|
COLOR vline[MAXDIV+1]; |
579 |
|
float zline[MAXDIV+1]; |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
< |
int |
603 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
604 |
< |
register COLOR *colline; |
605 |
< |
register float *zline; |
606 |
< |
int x, y; |
607 |
< |
int xlen, ylen; |
608 |
< |
int b; |
602 |
> |
static int |
603 |
> |
fillsample( /* fill interior points */ |
604 |
> |
register COLOR *colline, |
605 |
> |
register float *zline, |
606 |
> |
int x, |
607 |
> |
int y, |
608 |
> |
int xlen, |
609 |
> |
int ylen, |
610 |
> |
int b |
611 |
> |
) |
612 |
|
{ |
613 |
|
double ratio; |
614 |
|
double z; |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
< |
double |
659 |
< |
pixvalue(col, x, y) /* compute pixel value */ |
660 |
< |
COLOR col; /* returned color */ |
661 |
< |
int x, y; /* pixel position */ |
658 |
> |
static double |
659 |
> |
pixvalue( /* compute pixel value */ |
660 |
> |
COLOR col, /* returned color */ |
661 |
> |
int x, /* pixel position */ |
662 |
> |
int y |
663 |
> |
) |
664 |
|
{ |
665 |
|
RAY thisray; |
666 |
|
FVECT lorg, ldir; |
667 |
< |
double hpos, vpos, lmax, d; |
667 |
> |
double hpos, vpos, vdist, lmax; |
668 |
> |
register int i; |
669 |
|
/* compute view ray */ |
670 |
|
hpos = (x+pixjitter())/hres; |
671 |
|
vpos = (y+pixjitter())/vres; |
674 |
|
setcolor(col, 0.0, 0.0, 0.0); |
675 |
|
return(0.0); |
676 |
|
} |
677 |
+ |
vdist = ourview.vdist; |
678 |
|
|
679 |
|
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
680 |
|
|
681 |
|
/* optional motion blur */ |
682 |
|
if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, |
683 |
|
&lastview, hpos, vpos)) >= -FTINY) { |
644 |
– |
register int i; |
684 |
|
register double d = mblur*(.5-urand(281+samplendx)); |
685 |
|
|
686 |
|
thisray.rmax = (1.-d)*thisray.rmax + d*lmax; |
690 |
|
} |
691 |
|
if (normalize(thisray.rdir) == 0.0) |
692 |
|
return(0.0); |
693 |
+ |
vdist = (1.-d)*vdist + d*lastview.vdist; |
694 |
|
} |
695 |
+ |
/* optional depth-of-field */ |
696 |
+ |
if (dblur > FTINY && vdist > FTINY) { |
697 |
+ |
double vc, df[2]; |
698 |
+ |
df[0] = PI/4.*dblur*(.5 - frandom())/sqrt(ourview.hn2); |
699 |
+ |
df[1] = PI/4.*dblur*(.5 - frandom())/sqrt(ourview.vn2); |
700 |
+ |
for (i = 3; i--; ) { |
701 |
+ |
vc = thisray.rorg[i] + vdist*thisray.rdir[i]; |
702 |
+ |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
703 |
+ |
df[1]*ourview.vvec[i] ; |
704 |
+ |
thisray.rdir[i] = vc - thisray.rorg[i]; |
705 |
+ |
} |
706 |
+ |
if (normalize(thisray.rdir) == 0.0) |
707 |
+ |
return(0.0); |
708 |
+ |
} |
709 |
|
|
710 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
711 |
|
|
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
< |
int |
721 |
< |
salvage(oldfile) /* salvage scanlines from killed program */ |
722 |
< |
char *oldfile; |
720 |
> |
static int |
721 |
> |
salvage( /* salvage scanlines from killed program */ |
722 |
> |
char *oldfile |
723 |
> |
) |
724 |
|
{ |
725 |
|
COLR *scanline; |
726 |
|
FILE *fp; |
774 |
|
writerr: |
775 |
|
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
776 |
|
error(SYSTEM, errmsg); |
777 |
+ |
return -1; /* pro forma return */ |
778 |
|
} |
779 |
|
|
780 |
< |
|
781 |
< |
int |
782 |
< |
pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ |
783 |
< |
register int x, y; |
784 |
< |
int xres, yres; |
780 |
> |
static int |
781 |
> |
pixnumber( /* compute pixel index (brushed) */ |
782 |
> |
register int x, |
783 |
> |
register int y, |
784 |
> |
int xres, |
785 |
> |
int yres |
786 |
> |
) |
787 |
|
{ |
788 |
|
x -= y; |
789 |
|
while (x < 0) |