TEST_CASE_F(TransformToSpectrum_GivenSpectrum_DoesNothing, Fixture)
    {
        ShadingResult result;
        result.m_color_space = ColorSpaceSpectral;
        result.m_color.set(0.0f);

        result.transform_to_spectrum(m_lighting_conditions);

        EXPECT_EQ(ColorSpaceSpectral, result.m_color_space);
        EXPECT_EQ(Spectrum(0.0f), result.m_color);
    }
    TEST_CASE_F(TransformToSpectrum_FromCIEXYZ, Fixture)
    {
        ShadingResult result;
        result.m_color_space = ColorSpaceCIEXYZ;
        result.m_color[0] = result.m_color[1] = result.m_color[2] = 0.0f;

        result.transform_to_spectrum(m_lighting_conditions);

        EXPECT_EQ(ColorSpaceSpectral, result.m_color_space);
        EXPECT_EQ(Spectrum(0.0f), result.m_color);
    }
Ejemplo n.º 3
0
        void apply_aerial_perspective(
            const InputValues&      values,
            const ShadingContext&   shading_context,
            const ShadingPoint&     shading_point,
            ShadingResult&          shading_result) const
        {
            Spectrum sky_color;

            if (m_aerial_persp_mode == AerialPerspSkyColor)
                sky_color = values.m_aerial_persp_sky_color;
            else
            {
                // Retrieve the environment shader of the scene.
                const Scene& scene = shading_point.get_scene();
                const EnvironmentShader* environment_shader =
                    scene.get_environment()->get_environment_shader();

                if (environment_shader)
                {
                    // Execute the environment shader to obtain the sky color in the direction of the ray.
                    InputEvaluator input_evaluator(shading_context.get_texture_cache());
                    const ShadingRay& ray = shading_point.get_ray();
                    const Vector3d direction = normalize(ray.m_dir);
                    ShadingResult sky;
                    environment_shader->evaluate(input_evaluator, direction, sky);
                    sky.transform_to_spectrum(m_lighting_conditions);
                    sky_color = sky.m_main.m_color;
                }
                else sky_color.set(0.0f);
            }

            // Compute the blend factor.
            const double d = shading_point.get_distance() * m_aerial_persp_rcp_distance;
            const double k = m_aerial_persp_intensity * exp(d);
            const double blend = min(k, 1.0);

            // Blend the shading result and the sky color.
            sky_color *= static_cast<float>(blend);
            shading_result.m_main.m_color *= static_cast<float>(1.0 - blend);
            shading_result.m_main.m_color += sky_color;
        }