1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
6 |
|
|
7 |
|
/* |
8 |
|
* rpict.c - routines and variables for picture generation. |
9 |
– |
* |
10 |
– |
* 8/14/85 |
9 |
|
*/ |
10 |
|
|
11 |
|
#include "ray.h" |
18 |
|
#include <sys/resource.h> |
19 |
|
#else |
20 |
|
#include <sys/times.h> |
23 |
– |
#include <sys/utsname.h> |
21 |
|
#include <unistd.h> |
22 |
|
#endif |
23 |
|
#endif |
61 |
|
int directvis = 1; /* sources visible? */ |
62 |
|
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
63 |
|
|
64 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
65 |
+ |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
66 |
+ |
double seccg = 0.; /* global scattering eccentricity */ |
67 |
+ |
double ssampdist = 0.; /* scatter sampling distance */ |
68 |
+ |
|
69 |
|
double specthresh = .15; /* specular sampling threshold */ |
70 |
|
double specjitter = 1.; /* specular sampling jitter */ |
71 |
|
|
72 |
+ |
int backvis = 1; /* back face visibility */ |
73 |
+ |
|
74 |
|
int maxdepth = 6; /* maximum recursion depth */ |
75 |
|
double minweight = 5e-3; /* minimum ray weight */ |
76 |
|
|
77 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
78 |
+ |
int ambvwt = 0; /* initial weight for ambient value */ |
79 |
|
double ambacc = 0.2; /* ambient accuracy */ |
80 |
|
int ambres = 32; /* ambient resolution */ |
81 |
|
int ambdiv = 128; /* ambient divisions */ |
102 |
|
|
103 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
104 |
|
|
105 |
< |
static int hres, vres; /* resolution for this frame */ |
105 |
> |
int hres, vres; /* resolution for this frame */ |
106 |
|
|
107 |
|
extern char *mktemp(); |
108 |
|
|
138 |
|
#ifndef NIX |
139 |
|
report() /* report progress */ |
140 |
|
{ |
141 |
+ |
extern char *myhostname(); |
142 |
|
double u, s; |
143 |
|
#ifdef BSD |
138 |
– |
char hostname[257]; |
144 |
|
struct rusage rubuf; |
145 |
|
#else |
146 |
|
struct tms tbuf; |
142 |
– |
struct utsname nambuf; |
147 |
|
double period; |
144 |
– |
#define hostname nambuf.nodename |
148 |
|
#endif |
149 |
|
|
150 |
|
tlastrept = time((time_t *)NULL); |
155 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
156 |
|
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
157 |
|
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
155 |
– |
gethostname(hostname, sizeof(hostname)); |
158 |
|
#else |
159 |
|
times(&tbuf); |
160 |
|
#ifdef _SC_CLK_TCK |
164 |
|
#endif |
165 |
|
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
166 |
|
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
165 |
– |
uname(&nambuf); |
167 |
|
#endif |
168 |
|
|
169 |
|
sprintf(errmsg, |
170 |
|
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
171 |
|
nrays, pctdone, u/3600., s/3600., |
172 |
< |
(tlastrept-tstart)/3600., hostname); |
172 |
> |
(tlastrept-tstart)/3600., myhostname()); |
173 |
|
eputs(errmsg); |
174 |
|
#ifndef BSD |
175 |
|
signal(SIGCONT, report); |
175 |
– |
#undef hostname |
176 |
|
#endif |
177 |
|
} |
178 |
|
#else |
391 |
|
fprtresolu(hres, vres, stdout); |
392 |
|
/* recover file and compute first */ |
393 |
|
i = salvage(oldfile); |
394 |
+ |
if (i >= vres) |
395 |
+ |
goto alldone; |
396 |
|
if (zfd != -1 && i > 0 && |
397 |
|
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
398 |
|
error(SYSTEM, "z-file seek error in render"); |
403 |
|
else |
404 |
|
#endif |
405 |
|
signal(SIGCONT, report); |
406 |
< |
ypos = vres-1 - i; |
406 |
> |
ypos = vres-1 - i; /* initialize sampling */ |
407 |
> |
init_drawsources(psample); |
408 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
409 |
|
/* compute scanlines */ |
410 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
424 |
|
hres, ypos, hstep); |
425 |
|
/* fill bar */ |
426 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
427 |
+ |
/* add bitty sources */ |
428 |
+ |
drawsources(scanbar, zbar, 0, hres, ypos, ystep); |
429 |
|
/* write it out */ |
430 |
|
#ifndef BSD |
431 |
|
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
451 |
|
} |
452 |
|
/* clean up */ |
453 |
|
signal(SIGCONT, SIG_IGN); |
454 |
< |
if (zfd != -1) { |
450 |
< |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
454 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float)) |
455 |
|
< hres*sizeof(float)) |
456 |
< |
goto writerr; |
456 |
> |
goto writerr; |
457 |
> |
fwritescan(scanbar[0], hres, stdout); |
458 |
> |
if (fflush(stdout) == EOF) |
459 |
> |
goto writerr; |
460 |
> |
alldone: |
461 |
> |
if (zfd != -1) { |
462 |
|
if (close(zfd) == -1) |
463 |
|
goto writerr; |
464 |
|
for (i = 0; i <= psample; i++) |
465 |
|
free((char *)zbar[i]); |
466 |
|
} |
458 |
– |
fwritescan(scanbar[0], hres, stdout); |
459 |
– |
if (fflush(stdout) == EOF) |
460 |
– |
goto writerr; |
467 |
|
for (i = 0; i <= psample; i++) |
468 |
|
free((char *)scanbar[i]); |
469 |
|
if (sampdens != NULL) |
490 |
|
int bl = xstep, b = xstep; |
491 |
|
double z; |
492 |
|
register int i; |
493 |
< |
|
493 |
> |
|
494 |
|
z = pixvalue(scanline[0], 0, y); |
495 |
|
if (zline) zline[0] = z; |
496 |
|
/* zig-zag start for quincunx pattern */ |
524 |
|
float zline[MAXDIV+1]; |
525 |
|
int b = ysize; |
526 |
|
register int i, j; |
527 |
< |
|
527 |
> |
|
528 |
|
for (i = 0; i < xres; i++) { |
523 |
– |
|
529 |
|
copycolor(vline[0], scanbar[0][i]); |
530 |
|
copycolor(vline[ysize], scanbar[ysize][i]); |
531 |
|
if (zbar[0]) { |
532 |
|
zline[0] = zbar[0][i]; |
533 |
|
zline[ysize] = zbar[ysize][i]; |
534 |
|
} |
530 |
– |
|
535 |
|
b = fillsample(vline, zbar[0] ? zline : (float *)NULL, |
536 |
|
i, y, 0, ysize, b/2); |
537 |
< |
|
537 |
> |
|
538 |
|
for (j = 1; j < ysize; j++) |
539 |
|
copycolor(scanbar[j][i], vline[j]); |
540 |
|
if (zbar[0]) |
557 |
|
COLOR ctmp; |
558 |
|
int ncut; |
559 |
|
register int len; |
560 |
< |
|
560 |
> |
|
561 |
|
if (xlen > 0) /* x or y length is zero */ |
562 |
|
len = xlen; |
563 |
|
else |
564 |
|
len = ylen; |
565 |
< |
|
565 |
> |
|
566 |
|
if (len <= 1) /* limit recursion */ |
567 |
|
return(0); |
568 |
< |
|
569 |
< |
if (b > 0 |
570 |
< |
|| (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
568 |
> |
|
569 |
> |
if (b > 0 || |
570 |
> |
(zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
571 |
|
|| bigdiff(colline[0], colline[len], maxdiff)) { |
572 |
< |
|
572 |
> |
|
573 |
|
z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1)); |
574 |
|
if (zline) zline[len>>1] = z; |
575 |
|
ncut = 1; |
572 |
– |
|
576 |
|
} else { /* interpolate */ |
574 |
– |
|
577 |
|
copycolor(colline[len>>1], colline[len]); |
578 |
|
ratio = (double)(len>>1) / len; |
579 |
|
scalecolor(colline[len>>1], ratio); |
587 |
|
} |
588 |
|
/* recurse */ |
589 |
|
ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); |
590 |
< |
|
590 |
> |
|
591 |
|
ncut += fillsample(colline+(len>>1), |
592 |
|
zline ? zline+(len>>1) : (float *)NULL, |
593 |
|
x+(xlen>>1), y+(ylen>>1), |
617 |
|
rayvalue(&thisray); /* trace ray */ |
618 |
|
|
619 |
|
copycolor(col, thisray.rcol); /* return color */ |
620 |
< |
|
620 |
> |
|
621 |
|
return(thisray.rt); /* return distance */ |
622 |
|
} |
623 |
|
|