--- ray/src/rt/rpict.c 2005/01/18 00:33:16 2.73 +++ ray/src/rt/rpict.c 2010/05/15 15:31:30 2.82 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpict.c,v 2.73 2005/01/18 00:33:16 greg Exp $"; +static const char RCSid[] = "$Id: rpict.c,v 2.82 2010/05/15 15:31:30 greg Exp $"; #endif /* * rpict.c - routines and variables for picture generation. @@ -9,20 +9,24 @@ static const char RCSid[] = "$Id: rpict.c,v 2.73 2005/ #include -#ifndef NON_POSIX -#ifdef BSD -#include -#include +#include "platform.h" +#ifdef NON_POSIX + #ifdef MINGW + #include + #endif #else -#include -#include + #ifdef BSD + #include + #include + #else + #include + #include + #endif #endif -#endif #include #include -#include "platform.h" #include "ray.h" #include "paths.h" #include "ambient.h" @@ -67,6 +71,8 @@ void (*trace)() = NULL; /* trace call */ int do_irrad = 0; /* compute irradiance? */ +int rand_samp = 0; /* pure Monte Carlo sampling? */ + double dstrsrc = 0.0; /* square source distribution */ double shadthresh = .05; /* shadow threshold */ double shadcert = .5; /* shadow certainty */ @@ -675,9 +681,8 @@ pixvalue( /* compute pixel value */ return(0.0); } vdist = ourview.vdist; - - samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ - + /* set pixel index */ + samplendx = pixnumber(x,y,hres,vres); /* optional motion blur */ if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, &lastview, hpos, vpos)) >= -FTINY) { @@ -694,20 +699,41 @@ pixvalue( /* compute pixel value */ } /* optional depth-of-field */ if (dblur > FTINY && vdist > FTINY) { - double vc, df[2]; - df[0] = PI/4.*dblur*(.5 - frandom())/sqrt(ourview.hn2); - df[1] = PI/4.*dblur*(.5 - frandom())/sqrt(ourview.vn2); - for (i = 3; i--; ) { - vc = thisray.rorg[i] + vdist*thisray.rdir[i]; - thisray.rorg[i] += df[0]*ourview.hvec[i] + - df[1]*ourview.vvec[i] ; - thisray.rdir[i] = vc - thisray.rorg[i]; + double vc, dfh, dfv; + /* square/circle conv. */ + dfh = vc = 1. - 2.*frandom(); + dfv = 1. - 2.*frandom(); + dfh *= .5*dblur*sqrt(1. - .5*dfv*dfv); + dfv *= .5*dblur*sqrt(1. - .5*vc*vc); + 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 && ourview.type != VT_PLS) { + 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 */