nerfacc.accumulate_along_rays¶
- nerfacc.accumulate_along_rays(weights, values=None, ray_indices=None, n_rays=None)¶
Accumulate volumetric values along the ray.
This function supports both batched inputs and flattened inputs with ray_indices and n_rays provided.
Note
This function is differentiable to weights and values.
- Parameters:
weights (Tensor) – Weights to be accumulated. If ray_indices not provided, weights must be batched with shape (n_rays, n_samples). Else it must be flattened with shape (all_samples,).
values (Optional[Tensor]) – Values to be accumulated. If ray_indices not provided, values must be batched with shape (n_rays, n_samples, D). Else it must be flattened with shape (all_samples, D). None means we accumulate weights along rays. Default: None.
ray_indices (Optional[Tensor]) – Ray indices of the samples with shape (all_samples,). If provided, weights must be a flattened tensor with shape (all_samples,) and values (if not None) must be a flattened tensor with shape (all_samples, D). Default: None.
n_rays (Optional[int]) – Number of rays. Should be provided together with ray_indices. Default: None.
- Returns:
Accumulated values with shape (n_rays, D). If values is not given we return the accumulated weights, in which case D == 1.
- Return type:
Tensor
Examples:
# Rendering: accumulate rgbs, opacities, and depths along the rays. colors = accumulate_along_rays(weights, rgbs, ray_indices, n_rays) opacities = accumulate_along_rays(weights, None, ray_indices, n_rays) depths = accumulate_along_rays( weights, (t_starts + t_ends)[:, None] / 2.0, ray_indices, n_rays, ) # (n_rays, 3), (n_rays, 1), (n_rays, 1) print(colors.shape, opacities.shape, depths.shape)