ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/jitteraperture.c
Revision: 2.2
Committed: Wed Dec 15 01:38:50 2021 UTC (2 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +4 -3 lines
Log Message:
refactor: removed prefix from SDdisk2square() and SDsquare2disk() & made consistent

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.2 static const char RCSid[] = "$Id: jitteraperture.c,v 2.1 2021/12/03 18:10:48 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     double vc;
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     if ((v->type == VT_PER) | (v->type == VT_PAR)) {
37     double adj = 1.0; /* basic view cases */
38     if (v->type == VT_PER)
39     adj /= DOT(direc, v->vdir);
40     df[0] /= sqrt(v->hn2);
41     df[1] /= sqrt(v->vn2);
42     for (i = 3; i--; ) {
43     vc = v->vp[i] + adj*v->vdist*direc[i];
44     orig[i] += df[0]*v->hvec[i] +
45     df[1]*v->vvec[i] ;
46     direc[i] = vc - orig[i];
47     }
48     } else { /* difficult view cases */
49     double dfd = PI/4.*dia*(.5 - frandom());
50     if ((v->type != VT_ANG) & (v->type != VT_PLS)) {
51     if (v->type != VT_CYL)
52     df[0] /= sqrt(v->hn2);
53     df[1] /= sqrt(v->vn2);
54     }
55     for (i = 3; i--; ) {
56     vc = v->vp[i] + v->vdist*direc[i];
57     orig[i] += df[0]*v->hvec[i] +
58     df[1]*v->vvec[i] +
59     dfd*v->vdir[i] ;
60     direc[i] = vc - orig[i];
61     }
62     }
63     return(normalize(direc) != 0.0);
64     }