void DirectLightingIntegrator::compute_outgoing_radiance_combined_sampling_low_variance(
    SamplingContext&            sampling_context,
    const Dual3d&               outgoing,
    Spectrum&                   radiance,
    SpectrumStack&              aovs) const
{
    compute_outgoing_radiance_bsdf_sampling(
        sampling_context,
        MISPower2,
        outgoing,
        radiance,
        aovs);

    Spectrum radiance_light_sampling;
    SpectrumStack aovs_light_sampling(aovs.size());

    compute_outgoing_radiance_light_sampling_low_variance(
        sampling_context,
        MISPower2,
        outgoing,
        radiance_light_sampling,
        aovs_light_sampling);

    radiance += radiance_light_sampling;
    aovs += aovs_light_sampling;
}
Beispiel #2
0
        void add_back_lighting(
            const InputValues&      values,
            SamplingContext&        sampling_context,
            const PixelContext&     pixel_context,
            const ShadingContext&   shading_context,
            const ShadingPoint&     shading_point,
            Spectrum&               radiance,
            SpectrumStack&          aovs) const
        {
            const Vector3d& p = shading_point.get_point();
            const Vector3d& n = shading_point.get_original_shading_normal();
            const Vector3d& d = shading_point.get_ray().m_dir;

            // Construct a ray perpendicular to the other side of the surface.
            ShadingRay back_ray(shading_point.get_ray());
            back_ray.m_tmax *= norm(d);
            back_ray.m_dir = dot(d, n) > 0.0 ? -n : n;
            back_ray.m_org = p - back_ray.m_tmax * back_ray.m_dir;

            ShadingPoint back_shading_point(shading_point);
            back_shading_point.set_ray(back_ray);

            Spectrum back_radiance(0.0f);
            SpectrumStack back_aovs(aovs.size(), 0.0f);

            // Compute back lighting.
            for (size_t i = 0; i < m_back_lighting_samples; ++i)
            {
                shading_context.get_lighting_engine()->compute_lighting(
                    sampling_context,
                    pixel_context,
                    shading_context,
                    back_shading_point,
                    back_radiance,
                    back_aovs);
            }

            // Apply translucency factor.
            back_radiance *= values.m_translucency;
            back_aovs *= values.m_translucency;

            // Divide by the number of samples.
            const float rcp_sample_count = 1.0f / static_cast<float>(m_back_lighting_samples);
            back_radiance *= rcp_sample_count;
            back_aovs *= rcp_sample_count;

            // Add back lighting contribution.
            radiance += back_radiance;
            aovs += back_aovs;
        }
void DirectLightingIntegrator::sample_bsdf_and_lights_low_variance(
    SamplingContext&            sampling_context,
    Spectrum&                   radiance,
    SpectrumStack&              aovs)
{
    sample_bsdf(
        sampling_context,
        DirectLightingIntegrator::mis_power2,
        radiance,
        aovs);

    Spectrum radiance_light_sampling;
    SpectrumStack aovs_light_sampling(aovs.size());

    sample_lights_low_variance(
        sampling_context,
        DirectLightingIntegrator::mis_power2,
        radiance_light_sampling,
        aovs_light_sampling);

    radiance += radiance_light_sampling;
    aovs += aovs_light_sampling;
}