ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/jitteraperture.c
Revision: 2.3
Committed: Fri Jan 14 22:57:40 2022 UTC (3 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 2.2: +20 -12 lines
Log Message:
fix: added proper handling of fore clipping distance

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.3 static const char RCSid[] = "$Id: jitteraperture.c,v 2.2 2021/12/15 01:38:50 greg Exp $";
3 greg 2.1 #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 greg 2.2 RREAL df[2];
27 greg 2.3 double adj;
28 greg 2.1 int i;
29     /* are we even needed? */
30     if (dia <= FTINY)
31     return(1);
32     /* get random point on disk */
33 greg 2.2 square2disk(df, frandom(), frandom());
34 greg 2.1 df[0] *= .5*dia;
35     df[1] *= .5*dia;
36 greg 2.3
37 greg 2.1 if ((v->type == VT_PER) | (v->type == VT_PAR)) {
38 greg 2.3 adj = 1.0; /* basic view cases */
39 greg 2.1 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 greg 2.3 orig[i] = v->vp[i] + df[0]*v->hvec[i] +
45 greg 2.1 df[1]*v->vvec[i] ;
46 greg 2.3 direc[i] = v->vp[i] + adj*v->vdist*direc[i]
47     - orig[i];
48 greg 2.1 }
49     } else { /* difficult view cases */
50 greg 2.3 adj = PI/4.*dia*(.5 - frandom());
51 greg 2.1 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 greg 2.3 orig[i] = v->vp[i] + df[0]*v->hvec[i] +
58 greg 2.1 df[1]*v->vvec[i] +
59 greg 2.3 adj*v->vdir[i] ;
60     direc[i] = v->vp[i] + v->vdist*direc[i]
61     - orig[i];
62 greg 2.1 }
63     }
64 greg 2.3 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 greg 2.1 }