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; } } } } } }
void SphereObject::intersect( const ShadingRay& ray, IntersectionResult& result) const { result.m_hit = intersect_sphere_unit_direction( ray, impl->m_center, impl->m_radius, result.m_distance); if (result.m_hit) { const Vector3d n = normalize(ray.point_at(result.m_distance)); result.m_geometric_normal = n; result.m_shading_normal = n; const Vector3f p(ray.point_at(result.m_distance) * impl->m_rcp_radius); result.m_uv[0] = atan2(-p.z, p.x) * RcpTwoPi<float>(); result.m_uv[1] = 1.0f - (acos(p.y) * RcpPi<float>()); result.m_material_slot = 0; } }