Exemplo n.º 1
0
void FrozenDisplayRenderer::capture()
{
    SamplingContext::RNGType rng;
    SamplingContext sampling_context(
        rng,
        m_sampling_mode,
        2,                  // number of dimensions
        0,                  // number of samples -- unknown
        0);                 // initial instance number

    size_t point_index = 0;

    for (size_t ty = 0; ty < m_frame_props.m_tile_count_y; ++ty)
    {
        for (size_t tx = 0; tx < m_frame_props.m_tile_count_x; ++tx)
        {
            const Tile& color_tile = m_color_image.tile(tx, ty);
            const Tile& depth_tile = m_depth_image.tile(tx, ty);
            const size_t tile_width = color_tile.get_width();
            const size_t tile_height = color_tile.get_height();

            for (size_t py = 0; py < tile_height; ++py)
            {
                for (size_t px = 0; px < tile_width; ++px)
                {
                    // Compute film point in NDC.
                    const Vector2d ndc =
                        m_frame.get_sample_position(
                            tx, ty,
                            px, py,
                            0.5, 0.5);

                    // Retrieve pixel depth.
                    const float depth = depth_tile.get_component<float>(px, py, 0);

                    if (depth >= 0.0f)
                    {
                        // Generate a world space ray going through that film point.
                        ShadingRay ray;
                        m_camera.spawn_ray(sampling_context, Dual2d(ndc), ray);

                        // Retrieve pixel color.
                        Color4f pixel;
                        color_tile.get_pixel(px, py, pixel);

                        // Compute and store world space point and color.
                        RenderPoint point;
                        point.m_position = Vector3f(ray.point_at(depth));
                        point.m_color = pixel.rgb();
                        m_points[point_index++] = point;
                    }
                }
            }
        }
    }
}
Exemplo n.º 2
0
ScenePicker::PickingResult ScenePicker::pick(const Vector2d& ndc) const
{
    SamplingContext::RNGType rng;
    SamplingContext sampling_context(rng);

    const Scene& scene = impl->m_trace_context.get_scene();
    const Camera* camera = scene.get_camera();

    ShadingRay ray;
    camera->generate_ray(
        sampling_context,
        ndc,
        ray);

    ShadingPoint shading_point;
    impl->m_intersector.trace(ray, shading_point);

    const bool hit = shading_point.hit();

    PickingResult result;
    result.m_hit = hit;
    result.m_distance =
        hit
            ? shading_point.get_distance() * norm(ray.m_dir)
            : shading_point.get_distance();
    result.m_primitive_type = shading_point.get_primitive_type();
    result.m_camera = camera;
    result.m_assembly_instance = hit ? &shading_point.get_assembly_instance() : 0;
    result.m_assembly = hit ? &shading_point.get_assembly() : 0;
    result.m_object_instance = hit ? &shading_point.get_object_instance() : 0;
    result.m_object = hit ? &shading_point.get_object() : 0;
    result.m_material = 0;
    result.m_surface_shader = 0;
    result.m_bsdf = 0;
    result.m_edf = 0;

    if (hit)
    {
        const size_t pa_index = shading_point.get_primitive_attribute_index();

        if (pa_index != Triangle::None)
        {
            const char* material_name =
                result.m_object_instance->get_material_name(pa_index, shading_point.get_side());

            if (material_name)
            {
                result.m_material =
                    InputBinder::find_entity<Material>(
                        material_name,
                        result.m_object_instance->get_parent());
            }
        }
    }

    if (result.m_material)
    {
        const Entity* parent = result.m_material->get_parent();

        const char* ss_name = result.m_material->get_surface_shader_name();
        result.m_surface_shader = ss_name ? InputBinder::find_entity<SurfaceShader>(ss_name, parent) : 0;

        const char* bsdf_name = result.m_material->get_bsdf_name();
        result.m_bsdf = bsdf_name ? InputBinder::find_entity<BSDF>(bsdf_name, parent) : 0;

        const char* edf = result.m_material->get_edf_name();
        result.m_edf = edf ? InputBinder::find_entity<EDF>(edf, parent) : 0;
    }

    return result;
}