--- ray/src/rt/rpict.c 1991/10/21 12:57:57 1.35 +++ ray/src/rt/rpict.c 1992/01/14 16:15:57 2.5 @@ -22,6 +22,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "view.h" +#include "resolu.h" + #include "random.h" int dimlist[MAXDIM]; /* sampling dimensions */ @@ -45,6 +47,9 @@ int vspretest = 512; /* virtual source pretest dens int directinvis = 0; /* sources invisible? */ double srcsizerat = .25; /* maximum ratio source size/dist. */ +double specthresh = .5; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ + int maxdepth = 6; /* maximum recursion depth */ double minweight = 5e-3; /* minimum ray weight */ @@ -68,7 +73,7 @@ extern long tstart; /* starting time */ extern long nrays; /* number of rays traced */ -#define MAXDIV 15 /* maximum sample size */ +#define MAXDIV 16 /* maximum sample size */ #define pixjitter() (.5+dstrpix*(.5-frandom())) @@ -106,11 +111,11 @@ report() /* report progress */ #else report() /* report progress */ { - signal(SIGALRM, report); tlastrept = time((long *)0); sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", nrays, pctdone, (tlastrept-tstart)/3600.0); eputs(errmsg); + signal(SIGALRM, report); } #endif @@ -121,6 +126,7 @@ char *zfile, *oldfile; extern long lseek(); COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ float *zbar[MAXDIV+1]; /* z values */ + char *sampdens; /* previous sample density */ int ypos; /* current scanline */ int ystep; /* current y step size */ int hstep; /* h step size */ @@ -143,6 +149,16 @@ char *zfile, *oldfile; if (scanbar[i] == NULL) goto memerr; } + hstep = (psample*140+49)/99; /* quincunx sampling */ + ystep = (psample*99+70)/140; + if (hstep > 2) { + i = hresolu/hstep + 2; + if ((sampdens = malloc(i)) == NULL) + goto memerr; + while (i--) + sampdens[i] = hstep; + } else + sampdens = NULL; /* open z file */ if (zfile != NULL) { if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { @@ -160,7 +176,7 @@ char *zfile, *oldfile; zbar[i] = NULL; } /* write out boundaries */ - fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); + fprtresolu(hresolu, vresolu, stdout); /* recover file and compute first */ i = salvage(oldfile); if (zfd != -1 && i > 0 && @@ -174,9 +190,7 @@ char *zfile, *oldfile; #endif signal(SIGALRM, report); ypos = vresolu-1 - i; - hstep = (psample*140+49)/99; /* quincunx sampling */ - ystep = (psample*99+70)/140; - fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); + fillscanline(scanbar[0], zbar[0], sampdens, hresolu, ypos, hstep); /* compute scanlines */ for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { /* bottom adjust? */ @@ -191,7 +205,8 @@ char *zfile, *oldfile; zbar[ystep] = zbar[0]; zbar[0] = zptr; /* fill base line */ - fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); + fillscanline(scanbar[0], zbar[0], sampdens, + hresolu, ypos, hstep); /* fill bar */ fillscanbar(scanbar, zbar, hresolu, ypos, ystep); /* write it out */ @@ -232,6 +247,8 @@ char *zfile, *oldfile; goto writerr; for (i = 0; i <= psample; i++) free((char *)scanbar[i]); + if (sampdens != NULL) + free(sampdens); pctdone = 100.0; return; writerr: @@ -241,30 +258,38 @@ memerr: } -fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ +fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ register COLOR *scanline; register float *zline; +register char *sd; int xres, y, xstep; { static int nc = 0; /* number of calls */ - int b = xstep; + int bl = xstep, b = xstep; double z; register int i; z = pixvalue(scanline[0], 0, y); if (zline) zline[0] = z; /* zig-zag start for quincunx pattern */ - for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) { + for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { if (i >= xres) { xstep += xres-1-i; i = xres-1; } z = pixvalue(scanline[i], i, y); if (zline) zline[i] = z; - - b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, - i-xstep, y, xstep, 0, b/2); + if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; + if (i <= xstep) + b = fillsample(scanline, zline, 0, y, i, 0, b/2); + else + b = fillsample(scanline+i-xstep, + zline ? zline+i-xstep : NULL, + i-xstep, y, xstep, 0, b/2); + if (sd) *sd++ = nc & 1 ? bl : b; + bl = b; } + if (sd && nc & 1) *sd = bl; } @@ -398,7 +423,7 @@ char *oldfile; /* discard header */ getheader(fp, NULL); /* get picture size */ - if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { + if (!fscnresolu(&x, &y, fp)) { sprintf(errmsg, "bad recover file \"%s\"", oldfile); error(WARNING, errmsg); fclose(fp);