-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved depth-of-field sampling to separate module
- Loading branch information
1 parent
ddd5615
commit 7309df8
Showing
5 changed files
with
77 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ set(rtrad_SOURCES | |
instance.c | ||
interp2d.c | ||
invmat4.c | ||
jitteraperture.c | ||
lamps.c | ||
linregr.c | ||
loadbsdf.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef lint | ||
static const char RCSid[] = "$Id: jitteraperture.c,v 2.1 2021/12/03 18:10:48 greg Exp $"; | ||
#endif | ||
/* | ||
* jitteraperture.c - routine to sample depth-of-field | ||
* | ||
* External symbols declared in view.h | ||
*/ | ||
|
||
#include "copyright.h" | ||
|
||
#include <stdio.h> | ||
#include "rtmath.h" | ||
#include "random.h" | ||
#include "view.h" | ||
|
||
|
||
int | ||
jitteraperture( /* random aperture shift for depth-of-field */ | ||
FVECT orig, /* assigned previously by... */ | ||
FVECT direc, /* ...viewray() call */ | ||
VIEW *v, | ||
double dia | ||
) | ||
{ | ||
double vc, df[2]; | ||
int i; | ||
/* are we even needed? */ | ||
if (dia <= FTINY) | ||
return(1); | ||
/* get random point on disk */ | ||
SDsquare2disk(df, frandom(), frandom()); | ||
df[0] *= .5*dia; | ||
df[1] *= .5*dia; | ||
if ((v->type == VT_PER) | (v->type == VT_PAR)) { | ||
double adj = 1.0; /* basic view cases */ | ||
if (v->type == VT_PER) | ||
adj /= DOT(direc, v->vdir); | ||
df[0] /= sqrt(v->hn2); | ||
df[1] /= sqrt(v->vn2); | ||
for (i = 3; i--; ) { | ||
vc = v->vp[i] + adj*v->vdist*direc[i]; | ||
orig[i] += df[0]*v->hvec[i] + | ||
df[1]*v->vvec[i] ; | ||
direc[i] = vc - orig[i]; | ||
} | ||
} else { /* difficult view cases */ | ||
double dfd = PI/4.*dia*(.5 - frandom()); | ||
if ((v->type != VT_ANG) & (v->type != VT_PLS)) { | ||
if (v->type != VT_CYL) | ||
df[0] /= sqrt(v->hn2); | ||
df[1] /= sqrt(v->vn2); | ||
} | ||
for (i = 3; i--; ) { | ||
vc = v->vp[i] + v->vdist*direc[i]; | ||
orig[i] += df[0]*v->hvec[i] + | ||
df[1]*v->vvec[i] + | ||
dfd*v->vdir[i] ; | ||
direc[i] = vc - orig[i]; | ||
} | ||
} | ||
return(normalize(direc) != 0.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters