nerfacc.render_weight_from_density¶
- nerfacc.render_weight_from_density(t_starts, t_ends, sigmas, packed_info=None, ray_indices=None, n_rays=None, prefix_trans=None)¶
Compute rendering weights \(w_i\) from density \(\sigma_i\) and interval \(\delta_i\).
\[w_i = T_i(1 - exp(-\sigma_i\delta_i)), \quad\textrm{where}\quad T_i = exp(-\sum_{j=1}^{i-1}\sigma_j\delta_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:
t_starts (Tensor) – The start time of the samples. Tensor with shape (all_samples,) or (n_rays, n_samples).
t_ends (Tensor) – The end time of the samples. Tensor with shape (all_samples,) or (n_rays, n_samples).
sigmas (Tensor) – The density 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, transmittance and opacities, both with the same shape as sigmas.
- Return type:
Tuple[Tensor, Tensor, Tensor]
Examples:
>>> t_starts = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], device="cuda") >>> t_ends = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], device="cuda") >>> sigmas = 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, alphas = render_weight_from_density( >>> t_starts, t_ends, sigmas, ray_indices=ray_indices) weights: [0.33, 0.37, 0.03, 0.55, 0.04, 0.00, 0.59] transmittance: [1.00, 0.67, 0.30, 1.00, 0.45, 1.00, 1.00] alphas: [0.33, 0.55, 0.095, 0.55, 0.095, 0.00, 0.59]