Пример #1
0
void LightSampler::sample(
    const Vector3d&         s,
    LightSample&            sample) const
{
    assert(m_emitter_cdf.valid());

    const EmitterCDF::ItemWeightPair result = m_emitter_cdf.sample(s[0]);
    const size_t emitter_index = result.first;
    const double emitter_prob = result.second;

    if (emitter_index < m_light_count)
    {
        sample.m_triangle = 0;
        sample_light(
            Vector2d(s[1], s[2]),
            emitter_index,
            emitter_prob,
            sample);
    }
    else
    {
        sample.m_light = 0;
        sample_emitting_triangle(
            Vector2d(s[1], s[2]),
            emitter_index - m_light_count,
            emitter_prob,
            sample);
    }

    assert(sample.m_triangle || sample.m_light);
    assert(sample.m_triangle == 0 || sample.m_triangle->m_edf);
    assert(sample.m_probability > 0.0);
}
Пример #2
0
void LightSampler::sample_emitting_triangles(
    const ShadingRay::Time&             time,
    const Vector3d&                     s,
    LightSample&                        light_sample) const
{
    assert(m_emitting_triangles_cdf.valid());

    const EmitterCDF::ItemWeightPair result = m_emitting_triangles_cdf.sample(s[0]);
    const size_t emitter_index = result.first;
    const double emitter_prob = result.second;

    light_sample.m_light = 0;
    sample_emitting_triangle(
        time,
        Vector2d(s[1], s[2]),
        emitter_index,
        emitter_prob,
        light_sample);

    assert(light_sample.m_triangle);
    assert(light_sample.m_probability > 0.0);
}