Shortcuts

nerfacc.render_weight_from_alpha

nerfacc.render_weight_from_alpha(alphas, packed_info=None, ray_indices=None, n_rays=None, prefix_trans=None)

Compute rendering weights \(w_i\) from opacity \(\alpha_i\).

\[w_i = T_i\alpha_i, \quad\textrm{where}\quad T_i = \prod_{j=1}^{i-1}(1-\alpha_j)\]

This function supports both batched and flattened input tensor. For flattened input tensor, either (packed_info) or (ray_indices and n_rays) should be provided.

Parameters:
  • alphas (Tensor) – The opacity values of the samples. Tensor with shape (all_samples,) or (n_rays, n_samples).

  • packed_info (Optional[Tensor]) – A tensor of shape (n_rays, 2) that specifies the start and count of each chunk in the flattened samples, with in total n_rays chunks. Useful for flattened input.

  • ray_indices (Optional[Tensor]) – Ray indices of the flattened samples. LongTensor with shape (all_samples).

  • n_rays (Optional[int]) – Number of rays. Only useful when ray_indices is provided.

  • prefix_trans (Optional[Tensor]) – The pre-computed transmittance of the samples. Tensor with shape (all_samples,).

Returns:

The rendering weights and transmittance, both with the same shape as alphas.

Return type:

Tuple[Tensor, Tensor]

Examples:

>>> alphas = torch.tensor([0.4, 0.8, 0.1, 0.8, 0.1, 0.0, 0.9], device="cuda")
>>> ray_indices = torch.tensor([0, 0, 0, 1, 1, 2, 2], device="cuda")
>>> weights, transmittance = render_weight_from_alpha(alphas, ray_indices=ray_indices)
weights: [0.4, 0.48, 0.012, 0.8, 0.02, 0.0, 0.9])
transmittance: [1.00, 0.60, 0.12, 1.00, 0.20, 1.00, 1.00]