--- ray/src/util/vwrays.c 2021/12/03 17:22:28 3.22 +++ ray/src/util/vwrays.c 2024/01/12 17:29:10 3.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: vwrays.c,v 3.22 2021/12/03 17:22:28 greg Exp $"; +static const char RCSid[] = "$Id: vwrays.c,v 3.25 2024/01/12 17:29:10 greg Exp $"; #endif /* * Compute rays corresponding to a given picture or view. @@ -27,6 +27,8 @@ double pa = 1.; double pj = 0.; +double pd = 0.; + int zfd = -1; int fromstdin = 0; @@ -77,7 +79,7 @@ main( fprintf(stderr, "%s: no view in file\n", argv[i]); - exit(1); + return(1); } break; } @@ -94,7 +96,7 @@ main( if (rs.xr <= 0) { fprintf(stderr, "%s: bad x resolution\n", progname); - exit(1); + return(1); } break; case 'y': /* y resolution */ @@ -102,17 +104,20 @@ main( if (rs.yr <= 0) { fprintf(stderr, "%s: bad y resolution\n", progname); - exit(1); + return(1); } break; case 'c': /* repeat count */ repeatcnt = atoi(argv[++i]); + if (repeatcnt < 1) repeatcnt = 1; break; case 'p': /* pixel aspect or jitter */ if (argv[i][2] == 'a') pa = atof(argv[++i]); else if (argv[i][2] == 'j') pj = atof(argv[++i]); + else if (argv[i][2] == 'd') + pd = atof(argv[++i]); else goto userr; break; @@ -131,35 +136,37 @@ main( rval = viewfile(argv[i], &vw, &rs); if (rval <= 0) { fprintf(stderr, "%s: no view in picture\n", argv[i]); - exit(1); + return(1); } if (!getdim & (i+1 < argc)) { zfd = open_float_depth(argv[i+1], (long)rs.xr*rs.yr); if (zfd < 0) - exit(1); + return(1); } } if ((err = setview(&vw)) != NULL) { fprintf(stderr, "%s: %s\n", progname, err); - exit(1); + return(1); } if (i == argc) normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr); if (getdim) { - printf("-x %d -y %d -ld%c\n", rs.xr, rs.yr, - (i+1 == argc) & (vw.vaft > FTINY) ? '+' : '-'); - exit(0); + printf("-x %d -y %d%s\n", rs.xr, rs.yr, + (vw.vaft > FTINY) ? " -ld+" : ""); + return(0); } + if ((repeatcnt > 1) & (pj > FTINY)) + initurand(1024); if (fromstdin) pix2rays(stdin); else putrays(); - exit(0); + return(0); userr: fprintf(stderr, "Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n", progname); - exit(1); + return(1); } @@ -168,10 +175,20 @@ jitterloc( RREAL loc[2] ) { - if (pj > FTINY) { - loc[0] += pj*(.5 - frandom())/rs.xr; - loc[1] += pj*(.5 - frandom())/rs.yr; - } + static int nsamp; + double xyr[2]; + + if (pj <= FTINY) + return; + + if (repeatcnt == 1) { + xyr[0] = frandom(); + xyr[1] = frandom(); + } else /* stratify samples */ + multisamp(xyr, 2, urand(nsamp++)); + + loc[0] += pj*(.5 - xyr[0])/rs.xr; + loc[1] += pj*(.5 - xyr[1])/rs.yr; } @@ -212,7 +229,7 @@ pix2rays( for (c = repeatcnt; c-- > 0; ) { jitterloc(loc); d = viewray(rorg, rdir, &vw, loc[0], loc[1]); - if (d < -FTINY) + if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd)) rorg[0] = rorg[1] = rorg[2] = rdir[0] = rdir[1] = rdir[2] = 0.; else if (zfd >= 0) @@ -269,7 +286,7 @@ putrays(void) pix2loc(loc, &rs, si, sc); jitterloc(loc); d = viewray(rorg, rdir, &vw, loc[0], loc[1]); - if (d < -FTINY) + if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd)) rorg[0] = rorg[1] = rorg[2] = rdir[0] = rdir[1] = rdir[2] = 0.; else if (zfd >= 0)