Beispiel #1
0
void LightSampler::collect_emitting_triangles(
    const AssemblyInstanceContainer&    assembly_instances,
    const TransformSequence&            parent_transform_seq)
{
    for (const_each<AssemblyInstanceContainer> i = assembly_instances; i; ++i)
    {
        // Retrieve the assembly instance.
        const AssemblyInstance& assembly_instance = *i;

        // Retrieve the assembly.
        const Assembly& assembly = assembly_instance.get_assembly();

        // Compute the cumulated transform sequence of this assembly instance.
        TransformSequence cumulated_transform_seq =
            assembly_instance.transform_sequence() * parent_transform_seq;
        cumulated_transform_seq.prepare();

        // Recurse into child assembly instances.
        collect_emitting_triangles(
            assembly.assembly_instances(),
            cumulated_transform_seq);

        // Collect emitting triangles from this assembly instance.
        collect_emitting_triangles(
            assembly,
            assembly_instance,
            cumulated_transform_seq);
    }
}
LightSampler::LightSampler(const Scene& scene)
  : m_total_emissive_area(0.0)
{
    RENDERER_LOG_INFO("collecting light emitters...");

    // Collect all lights and light-emitting triangles.
    for (const_each<AssemblyInstanceContainer> i = scene.assembly_instances(); i; ++i)
    {
        const AssemblyInstance& assembly_instance = *i;
        const Assembly& assembly = assembly_instance.get_assembly();

        collect_lights(assembly, assembly_instance);

        if (has_emitting_materials(assembly))
            collect_emitting_triangles(assembly, assembly_instance);
    }

    // Precompute some values.
    m_light_count = m_lights.size();
    m_rcp_total_emissive_area = 1.0 / m_total_emissive_area;

    // Prepare the CDFs for sampling.
    if (m_emitter_cdf.valid())
        m_emitter_cdf.prepare();
    if (m_emitting_triangle_cdf.valid())
        m_emitting_triangle_cdf.prepare();

    RENDERER_LOG_INFO(
        "found %s %s, %s emitting %s.",
        pretty_int(m_light_count).c_str(),
        plural(m_light_count, "light").c_str(),
        pretty_int(m_emitting_triangles.size()).c_str(),
        plural(m_emitting_triangles.size(), "triangle").c_str());
}
Beispiel #3
0
LightSampler::LightSampler(const Scene& scene)
  : m_total_emissive_area(0.0)
{
    RENDERER_LOG_INFO("collecting light emitters...");

    // Collect all lights and light-emitting triangles.
    collect_lights(scene);
    collect_emitting_triangles(scene);

    // Precompute some values.
    m_light_count = m_lights.size();
    m_rcp_total_emissive_area = 1.0 / m_total_emissive_area;

    // Prepare the CDFs for sampling.
    if (m_emitter_cdf.valid())
        m_emitter_cdf.prepare();
    if (m_emitting_triangle_cdf.valid())
        m_emitting_triangle_cdf.prepare();

    RENDERER_LOG_INFO(
        "found %s %s, %s emitting %s.",
        pretty_int(m_light_count).c_str(),
        plural(m_light_count, "light").c_str(),
        pretty_int(m_emitting_triangles.size()).c_str(),
        plural(m_emitting_triangles.size(), "triangle").c_str());
}
Beispiel #4
0
void LightSampler::collect_emitting_triangles(const Scene& scene)
{
    for (const_each<AssemblyInstanceContainer> i = scene.assembly_instances(); i; ++i)
    {
        const AssemblyInstance& assembly_instance = *i;

        if (has_emitting_materials(assembly_instance.get_assembly()))
            collect_emitting_triangles(scene, assembly_instance);
    }
}
Beispiel #5
0
LightSampler::LightSampler(const Scene& scene, const ParamArray& params)
  : m_params(params)
  , m_emitting_triangle_hash_table(m_triangle_key_hasher)
{
    RENDERER_LOG_INFO("collecting light emitters...");

    // Collect all non-physical lights.
    collect_non_physical_lights(scene.assembly_instances(), TransformSequence());
    m_non_physical_light_count = m_non_physical_lights.size();

    // Collect all light-emitting triangles.
    collect_emitting_triangles(
        scene.assembly_instances(),
        TransformSequence());

    // Build the hash table of emitting triangles.
    build_emitting_triangle_hash_table();

    // Prepare the CDFs for sampling.
    if (m_non_physical_lights_cdf.valid())
        m_non_physical_lights_cdf.prepare();
    if (m_emitting_triangles_cdf.valid())
        m_emitting_triangles_cdf.prepare();

    // Store the triangle probability densities into the emitting triangles.
    const size_t emitting_triangle_count = m_emitting_triangles.size();
    for (size_t i = 0; i < emitting_triangle_count; ++i)
        m_emitting_triangles[i].m_triangle_prob = m_emitting_triangles_cdf[i].second;

   RENDERER_LOG_INFO(
        "found %s %s, %s emitting %s.",
        pretty_int(m_non_physical_light_count).c_str(),
        plural(m_non_physical_light_count, "non-physical light").c_str(),
        pretty_int(m_emitting_triangles.size()).c_str(),
        plural(m_emitting_triangles.size(), "triangle").c_str());
}