--- ray/src/rt/rpict.c 2004/10/23 18:55:53 2.71 +++ ray/src/rt/rpict.c 2005/04/19 01:15:06 2.75 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpict.c,v 2.71 2004/10/23 18:55:53 schorsch Exp $"; +static const char RCSid[] = "$Id: rpict.c,v 2.75 2005/04/19 01:15:06 greg Exp $"; #endif /* * rpict.c - routines and variables for picture generation. @@ -61,6 +61,8 @@ double dstrpix = 0.67; /* square pixel distribution double mblur = 0.; /* motion blur parameter */ +double dblur = 0.; /* depth-of-field blur parameter */ + void (*trace)() = NULL; /* trace call */ int do_irrad = 0; /* compute irradiance? */ @@ -94,7 +96,7 @@ int ambres = 64; /* ambient resolution */ int ambdiv = 512; /* ambient divisions */ int ambssamp = 128; /* ambient super-samples */ int ambounce = 0; /* ambient bounces */ -char *amblist[128]; /* ambient include/exclude list */ +char *amblist[AMBLLEN]; /* ambient include/exclude list */ int ambincl = -1; /* include == 1, exclude == 0 */ int ralrm = 0; /* seconds between reports */ @@ -662,7 +664,8 @@ pixvalue( /* compute pixel value */ { RAY thisray; FVECT lorg, ldir; - double hpos, vpos, lmax; + double hpos, vpos, vdist, lmax; + register int i; /* compute view ray */ hpos = (x+pixjitter())/hres; vpos = (y+pixjitter())/vres; @@ -671,13 +674,13 @@ pixvalue( /* compute pixel value */ setcolor(col, 0.0, 0.0, 0.0); return(0.0); } + vdist = ourview.vdist; samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ /* optional motion blur */ if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, &lastview, hpos, vpos)) >= -FTINY) { - register int i; register double d = mblur*(.5-urand(281+samplendx)); thisray.rmax = (1.-d)*thisray.rmax + d*lmax; @@ -687,9 +690,43 @@ pixvalue( /* compute pixel value */ } if (normalize(thisray.rdir) == 0.0) return(0.0); + vdist = (1.-d)*vdist + d*lastview.vdist; } + /* optional depth-of-field */ + if (dblur > FTINY && vdist > FTINY) { + double vc, dfh, dfv; + /* PI/4. square/circle conv. */ + dfh = PI/4.*dblur*(.5 - frandom()); + dfv = PI/4.*dblur*(.5 - frandom()); + if (ourview.type == VT_PER || ourview.type == VT_PAR) { + dfh /= sqrt(ourview.hn2); + dfv /= sqrt(ourview.vn2); + for (i = 3; i--; ) { + vc = thisray.rorg[i] + vdist*thisray.rdir[i]; + thisray.rorg[i] += dfh*ourview.hvec[i] + + dfv*ourview.vvec[i] ; + thisray.rdir[i] = vc - thisray.rorg[i]; + } + } else { /* non-standard view case */ + double dfd = PI/4.*dblur*(.5 - frandom()); + if (ourview.type != VT_ANG) { + if (ourview.type != VT_CYL) + dfh /= sqrt(ourview.hn2); + dfv /= sqrt(ourview.vn2); + } + for (i = 3; i--; ) { + vc = thisray.rorg[i] + vdist*thisray.rdir[i]; + thisray.rorg[i] += dfh*ourview.hvec[i] + + dfv*ourview.vvec[i] + + dfd*ourview.vdir[i] ; + thisray.rdir[i] = vc - thisray.rorg[i]; + } + } + if (normalize(thisray.rdir) == 0.0) + return(0.0); + } - rayorigin(&thisray, NULL, PRIMARY, 1.0); + rayorigin(&thisray, PRIMARY, NULL, NULL); rayvalue(&thisray); /* trace ray */ @@ -758,7 +795,6 @@ writerr: error(SYSTEM, errmsg); return -1; /* pro forma return */ } - static int pixnumber( /* compute pixel index (brushed) */