diff --git a/include/neural-graphics-primitives/common_device.cuh b/include/neural-graphics-primitives/common_device.cuh index 5029cb00d3e3b93402955a1761fbd655795dc070..9a33d7eae5f11d8caebd9651cc1458f88d76c95c 100644 --- a/include/neural-graphics-primitives/common_device.cuh +++ b/include/neural-graphics-primitives/common_device.cuh @@ -266,6 +266,7 @@ inline NGP_HOST_DEVICE Ray pixel_to_ray( const Eigen::Vector2f& screen_center, const Eigen::Vector3f& parallax_shift, bool snap_to_pixel_centers = false, + float near_distance = 0.0f, float focus_z = 1.0f, float aperture_size = 0.0f, const Lens& lens = {}, @@ -303,6 +304,7 @@ inline NGP_HOST_DEVICE Ray pixel_to_ray( Eigen::Vector3f origin = camera_matrix.block<3, 3>(0, 0) * head_pos + camera_matrix.col(3); if (aperture_size == 0.0f) { + origin += dir * near_distance; return {origin, dir}; } @@ -310,6 +312,7 @@ inline NGP_HOST_DEVICE Ray pixel_to_ray( Eigen::Vector2f blur = aperture_size * square2disk_shirley(ld_random_val_2d(spp, (uint32_t)pixel.x() * 19349663 + (uint32_t)pixel.y() * 96925573) * 2.0f - Eigen::Vector2f::Ones()); origin += camera_matrix.block<3, 2>(0, 0) * blur; dir = (lookat - origin) / focus_z; + origin += dir * near_distance; return {origin, dir}; } @@ -371,6 +374,7 @@ inline NGP_HOST_DEVICE Eigen::Vector2f motion_vector_3d( screen_center, parallax_shift, snap_to_pixel_centers, + 0.0f, 1.0f, 0.0f, lens, diff --git a/src/testbed_nerf.cu b/src/testbed_nerf.cu index fdf92a6be1dd1a6b841dd72bb2e1ad73d186363e..7d7eb659e8ec7289c9b8b2dcb67757987c180d84 100644 --- a/src/testbed_nerf.cu +++ b/src/testbed_nerf.cu @@ -1837,6 +1837,7 @@ __global__ void init_rays_with_payload_kernel_nerf( screen_center, parallax_shift, snap_to_pixel_centers, + near_distance, plane_z, aperture_size, lens, @@ -1867,7 +1868,7 @@ __global__ void init_rays_with_payload_kernel_nerf( framebuffer[idx] = read_envmap(envmap_data, envmap_resolution, ray.d); } - float t = fmaxf(render_aabb.ray_intersect(render_aabb_to_local * ray.o, render_aabb_to_local * ray.d).x(), near_distance) + 1e-6f; + float t = fmaxf(render_aabb.ray_intersect(render_aabb_to_local * ray.o, render_aabb_to_local * ray.d).x(), 0.0f) + 1e-6f; if (!render_aabb.contains(render_aabb_to_local * (ray.o + ray.d * t))) { payload.origin = ray.o; diff --git a/src/testbed_sdf.cu b/src/testbed_sdf.cu index bdb11813f91645fa67d12dd62e5088bf1f413101..2e42b3f3e429cad4203efbe6f0e72325156d87c6 100644 --- a/src/testbed_sdf.cu +++ b/src/testbed_sdf.cu @@ -525,7 +525,7 @@ __global__ void init_rays_with_payload_kernel_sdf( aperture_size = 0.0; } - Ray ray = pixel_to_ray(sample_index, {x, y}, resolution, focal_length, camera_matrix, screen_center, parallax_shift, snap_to_pixel_centers, plane_z, aperture_size); + Ray ray = pixel_to_ray(sample_index, {x, y}, resolution, focal_length, camera_matrix, screen_center, parallax_shift, snap_to_pixel_centers, 0.0f, plane_z, aperture_size); distances[idx] = 10000.0f; diff --git a/src/testbed_volume.cu b/src/testbed_volume.cu index f84eb28408e2741222f58233d7f48b1b65aef040..36fa3237114c8fdbc5270d41bad9bc276cdf5423 100644 --- a/src/testbed_volume.cu +++ b/src/testbed_volume.cu @@ -239,7 +239,7 @@ __global__ void init_rays_volume( if (plane_z < 0) { aperture_size = 0.0; } - Ray ray = pixel_to_ray(sample_index, {x, y}, resolution, focal_length, camera_matrix, screen_center, parallax_shift, snap_to_pixel_centers, plane_z, aperture_size); + Ray ray = pixel_to_ray(sample_index, {x, y}, resolution, focal_length, camera_matrix, screen_center, parallax_shift, snap_to_pixel_centers, 0.0f, plane_z, aperture_size); ray.d = ray.d.normalized(); auto box_intersection = aabb.ray_intersect(ray.o, ray.d); float t = max(box_intersection.x(), 0.0f);