Shortcuts

nerfacc.unpack_info

nerfacc.unpack_info(packed_info, n_samples)

Unpack packed_info to ray_indices. Useful for converting per ray data to per sample data.

Note

this function is not differentiable to any inputs.

Parameters:
  • packed_info (Tensor) – Stores information on which samples belong to the same ray. See nerfacc.ray_marching() for details. IntTensor with shape (n_rays, 2).

  • n_samples (int) – Total number of samples.

Returns:

Ray index of each sample. LongTensor with shape (n_sample).

Return type:

Tensor

Examples:

rays_o = torch.rand((128, 3), device="cuda:0")
rays_d = torch.randn((128, 3), device="cuda:0")
rays_d = rays_d / rays_d.norm(dim=-1, keepdim=True)
# Ray marching with near far plane.
packed_info, t_starts, t_ends = ray_marching(
    rays_o, rays_d, near_plane=0.1, far_plane=1.0, render_step_size=1e-3
)
# torch.Size([128, 2]) torch.Size([115200, 1]) torch.Size([115200, 1])
print(packed_info.shape, t_starts.shape, t_ends.shape)
# Unpack per-ray info to per-sample info.
ray_indices = unpack_info(packed_info, t_starts.shape[0])
# torch.Size([115200]) torch.int64
print(ray_indices.shape, ray_indices.dtype)