1 |
greg |
2.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id: image.c,v 2.52 2021/02/12 00:47:08 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 |
|
|
double vc, df[2]; |
27 |
|
|
int i; |
28 |
|
|
/* are we even needed? */ |
29 |
|
|
if (dia <= FTINY) |
30 |
|
|
return(1); |
31 |
|
|
/* get random point on disk */ |
32 |
|
|
SDsquare2disk(df, frandom(), frandom()); |
33 |
|
|
df[0] *= .5*dia; |
34 |
|
|
df[1] *= .5*dia; |
35 |
|
|
if ((v->type == VT_PER) | (v->type == VT_PAR)) { |
36 |
|
|
double adj = 1.0; /* basic view cases */ |
37 |
|
|
if (v->type == VT_PER) |
38 |
|
|
adj /= DOT(direc, v->vdir); |
39 |
|
|
df[0] /= sqrt(v->hn2); |
40 |
|
|
df[1] /= sqrt(v->vn2); |
41 |
|
|
for (i = 3; i--; ) { |
42 |
|
|
vc = v->vp[i] + adj*v->vdist*direc[i]; |
43 |
|
|
orig[i] += df[0]*v->hvec[i] + |
44 |
|
|
df[1]*v->vvec[i] ; |
45 |
|
|
direc[i] = vc - orig[i]; |
46 |
|
|
} |
47 |
|
|
} else { /* difficult view cases */ |
48 |
|
|
double dfd = PI/4.*dia*(.5 - frandom()); |
49 |
|
|
if ((v->type != VT_ANG) & (v->type != VT_PLS)) { |
50 |
|
|
if (v->type != VT_CYL) |
51 |
|
|
df[0] /= sqrt(v->hn2); |
52 |
|
|
df[1] /= sqrt(v->vn2); |
53 |
|
|
} |
54 |
|
|
for (i = 3; i--; ) { |
55 |
|
|
vc = v->vp[i] + v->vdist*direc[i]; |
56 |
|
|
orig[i] += df[0]*v->hvec[i] + |
57 |
|
|
df[1]*v->vvec[i] + |
58 |
|
|
dfd*v->vdir[i] ; |
59 |
|
|
direc[i] = vc - orig[i]; |
60 |
|
|
} |
61 |
|
|
} |
62 |
|
|
return(normalize(direc) != 0.0); |
63 |
|
|
} |