Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Add MIS heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
raywan committed May 29, 2019
1 parent 7a07c24 commit 5d6d5b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void stratified_sample_2d(Point2 *out_samples, int nx, int ny, bool jitter) {
for (int x = 0; x < nx; x++) {
float jx = jitter ? unif_01(generator) : 0.5f;
float jy = jitter ? unif_01(generator) : 0.5f;

out_samples->x = MIN((x + jx) * dx, ONE_MINUS_EPSILON);
out_samples->y = MIN((y + jy) * dy, ONE_MINUS_EPSILON);
++out_samples;
Expand All @@ -116,4 +117,15 @@ void latin_hypercube(float *samples, int n_samples, int n_dim) {
std::swap(samples[n_dim * j + i], samples[n_dim * other + i]);
}
}
}
}

// For Multiple Importance Sampling two distributions
float mis_balance_heuristic(int nf, float f_pdf, int ng, float g_pdf) {
return (nf * f_pdf) / (nf * f_pdf + ng * g_pdf);
}

float mis_power_heuristic(int nf, float f_pdf, int ng, float g_pdf) {
float f = nf * f_pdf;
float g = ng * g_pdf;
return SQUARE(f) / (SQUARE(f) + SQUARE(g));
}
6 changes: 5 additions & 1 deletion src/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ float uniform_cone_pdf(float cos_theta_max);
void stratified_sample_1d(float *out_samples, int n_samples, bool jitter);
void stratified_sample_2d(Point2 *out_samples, int nx, int ny, bool jitter);

#endif
// For Multiple Importance Sampling two distributions
float mis_balance_heuristic(int nf, float f_pdf, int ng, float g_pdf);
float mis_power_heuristic(int nf, float f_pdf, int ng, float g_pdf);

#endif

0 comments on commit 5d6d5b2

Please sign in to comment.