| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: jitteraperture.c,v 2.2 2021/12/15 01:38:50 greg Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* jitteraperture.c - routine to sample depth-of-field
|
| 6 |
*
|
| 7 |
* External symbols declared in view.h
|
| 8 |
*/
|
| 9 |
|
| 10 |
#include "copyright.h"
|
| 11 |
|
| 12 |
#include <stdio.h>
|
| 13 |
#include "rtmath.h"
|
| 14 |
#include "random.h"
|
| 15 |
#include "view.h"
|
| 16 |
|
| 17 |
|
| 18 |
int
|
| 19 |
jitteraperture( /* random aperture shift for depth-of-field */
|
| 20 |
FVECT orig, /* assigned previously by... */
|
| 21 |
FVECT direc, /* ...viewray() call */
|
| 22 |
VIEW *v,
|
| 23 |
double dia
|
| 24 |
)
|
| 25 |
{
|
| 26 |
RREAL df[2];
|
| 27 |
double adj;
|
| 28 |
int i;
|
| 29 |
/* are we even needed? */
|
| 30 |
if (dia <= FTINY)
|
| 31 |
return(1);
|
| 32 |
/* get random point on disk */
|
| 33 |
square2disk(df, frandom(), frandom());
|
| 34 |
df[0] *= .5*dia;
|
| 35 |
df[1] *= .5*dia;
|
| 36 |
|
| 37 |
if ((v->type == VT_PER) | (v->type == VT_PAR)) {
|
| 38 |
adj = 1.0; /* basic view cases */
|
| 39 |
if (v->type == VT_PER)
|
| 40 |
adj /= DOT(direc, v->vdir);
|
| 41 |
df[0] /= sqrt(v->hn2);
|
| 42 |
df[1] /= sqrt(v->vn2);
|
| 43 |
for (i = 3; i--; ) {
|
| 44 |
orig[i] = v->vp[i] + df[0]*v->hvec[i] +
|
| 45 |
df[1]*v->vvec[i] ;
|
| 46 |
direc[i] = v->vp[i] + adj*v->vdist*direc[i]
|
| 47 |
- orig[i];
|
| 48 |
}
|
| 49 |
} else { /* difficult view cases */
|
| 50 |
adj = PI/4.*dia*(.5 - frandom());
|
| 51 |
if ((v->type != VT_ANG) & (v->type != VT_PLS)) {
|
| 52 |
if (v->type != VT_CYL)
|
| 53 |
df[0] /= sqrt(v->hn2);
|
| 54 |
df[1] /= sqrt(v->vn2);
|
| 55 |
}
|
| 56 |
for (i = 3; i--; ) {
|
| 57 |
orig[i] = v->vp[i] + df[0]*v->hvec[i] +
|
| 58 |
df[1]*v->vvec[i] +
|
| 59 |
adj*v->vdir[i] ;
|
| 60 |
direc[i] = v->vp[i] + v->vdist*direc[i]
|
| 61 |
- orig[i];
|
| 62 |
}
|
| 63 |
}
|
| 64 |
if (normalize(direc) == 0.0)
|
| 65 |
return(0);
|
| 66 |
if ((adj = v->vfore) <= FTINY)
|
| 67 |
return(1);
|
| 68 |
if (v->type == VT_PER)
|
| 69 |
adj /= DOT(direc, v->vdir);
|
| 70 |
VSUM(orig, orig, direc, adj);
|
| 71 |
return(1);
|
| 72 |
}
|