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

Commit

Permalink
Add uniform cone sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
raywan committed May 29, 2019
1 parent 49e1049 commit 7a07c24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Vec3 cast_ray(World *world, Ray *r, int cur_depth) {
}
indirect_lighting = rwm_v3_scalar_div(indirect_lighting, (float) NUM_PT_SAMPLES * pdf);
#endif // #if USE_GLOBAL_ILLUMINATION
// Finally multiply by lambertian brdf
// Finally multiply by lambertian BRDF
color = (direct_lighting + rwm_v3_scalar_div(indirect_lighting, pdf)) * rwm_v3_scalar_div(ii.material->albedo, PI);
if (ii.material->use_texture) {
color *= get_checkerboard(ii.tex_coord);
Expand Down
11 changes: 11 additions & 0 deletions src/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ Point2 concentric_sample_disk(Point2 u) {
return r * rwm_v2_init(cosf(theta), sinf(theta));
}

Vec3 uniform_sample_cone(Point2 u, float cos_theta_max) {
float cos_theta = (1 - u.e[0]) + u.e[0] * cos_theta_max;
float sin_theta = rwm_sqrt(1 - SQUARE(cos_theta));
float phi = u.e[1] * 2 * PI;
return rwm_v3_init(cosf(phi) * sin_theta, sinf(phi) * sin_theta, cos_theta);
}

float uniform_cone_pdf(float cos_theta_max) {
return 1/(2 * PI * (1 - cos_theta_max));
}

void stratified_sample_1d(float *out_samples, int n_samples, bool jitter) {
float inv_n_samples = 1.0f/n_samples;
for (int i = 0; i < n_samples; i++) {
Expand Down
3 changes: 3 additions & 0 deletions src/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ float cosine_hemisphere_pdf(float cos_theta);
Point2 uniform_sample_disk(Point2 u);
Point2 concentric_sample_disk(Point2 u);

Vec3 uniform_sample_cone(Point2 u, float cos_theta_max);
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);

Expand Down

0 comments on commit 7a07c24

Please sign in to comment.