Skip to content

Commit

Permalink
fixed assertion, renamed some methods, tweaked code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dictoon committed Aug 22, 2015
1 parent a7715c3 commit 3200e81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Expand Up @@ -384,8 +384,8 @@ namespace
const double light_sample_count = max(m_params.m_dl_light_sample_count, 1.0);
const double mis_weight =
mis_power2(
1.0 * vertex.get_bsdf_point_prob(),
light_sample_count * vertex.get_light_point_prob(m_light_sampler));
1.0 * vertex.get_prev_prob_area(),
light_sample_count * vertex.get_light_prob_area(m_light_sampler));
emitted_radiance *= static_cast<float>(mis_weight);
}

Expand Down
7 changes: 4 additions & 3 deletions src/appleseed/renderer/kernel/lighting/pathtracer.h
Expand Up @@ -403,10 +403,10 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(
sampling_context.split_in_place(3, 1);
const foundation::Vector3d s = sampling_context.next_vector2<3>();

// Select one incoming point at random.
// Select one of the incoming points at random.
const size_t sample_index = foundation::truncate<size_t>(s[0] * visitor.m_sample_count);
const ShadingPoint& incoming_point = visitor.m_incoming_points[sample_index];
const double probability = visitor.m_probabilities[sample_index] / visitor.m_sample_count;
const double probability = visitor.m_probabilities[sample_index];
const double eta = visitor.m_etas[sample_index];

// Compute Fresnel coefficient at outgoing point.
Expand All @@ -415,7 +415,7 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(
if (outgoing_fresnel <= 0.0)
break;

// Pick an incoming direction.
// Pick an incoming direction at random.
foundation::Vector3d incoming_vector =
foundation::sample_hemisphere_cosine(foundation::Vector2d(s[1], s[2]));
const double cos_in = incoming_vector.y;
Expand Down Expand Up @@ -447,6 +447,7 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(
* incoming_fresnel
* outgoing_fresnel
* cos_in
* visitor.m_sample_count
/ (probability * incoming_prob);
value = rd;
value *= static_cast<float>(weight);
Expand Down
14 changes: 6 additions & 8 deletions src/appleseed/renderer/kernel/lighting/pathvertex.h
Expand Up @@ -107,10 +107,10 @@ class PathVertex
Spectrum& radiance) const;

// Return the probability density wrt. surface area mesure of reaching this vertex via BSDF sampling.
double get_bsdf_point_prob() const;
double get_prev_prob_area() const;

// Return the probability density wrt. surface area mesure of reaching this vertex via light sampling.
double get_light_point_prob(const LightSampler& light_sampler) const;
double get_light_prob_area(const LightSampler& light_sampler) const;
};


Expand Down Expand Up @@ -163,20 +163,18 @@ inline const Material* PathVertex::get_material() const
return m_shading_point->get_material();
}

inline double PathVertex::get_bsdf_point_prob() const
inline double PathVertex::get_prev_prob_area() const
{
// Make sure we're coming from a valid BSDF scattering event.
assert(m_prev_mode == ScatteringMode::Diffuse ||
m_prev_mode == ScatteringMode::Glossy ||
m_prev_mode == ScatteringMode::Specular);
// Make sure we're coming from a valid scattering event.
assert(m_prev_mode != ScatteringMode::Absorption);
assert(m_prev_prob > 0.0);

// Veach: 8.2.2.2 eq. 8.10.
const double d = m_shading_point->get_distance();
return m_prev_prob * m_cos_on / (d * d);
}

inline double PathVertex::get_light_point_prob(const LightSampler& light_sampler) const
inline double PathVertex::get_light_prob_area(const LightSampler& light_sampler) const
{
return light_sampler.evaluate_pdf(*m_shading_point);
}
Expand Down
Expand Up @@ -935,8 +935,8 @@ namespace
const double light_sample_count = max(m_params.m_dl_light_sample_count, 1.0);
const double mis_weight =
mis_power2(
1.0 * vertex.get_bsdf_point_prob(),
light_sample_count * vertex.get_light_point_prob(m_light_sampler));
1.0 * vertex.get_prev_prob_area(),
light_sample_count * vertex.get_light_prob_area(m_light_sampler));
emitted_radiance *= static_cast<float>(mis_weight);
}

Expand Down

0 comments on commit 3200e81

Please sign in to comment.