Unverified Commit 237b85e4 authored by Ruilong Li(李瑞龙)'s avatar Ruilong Li(李瑞龙) Committed by GitHub
Browse files

tiny bug fix for alpha rendering; remove the pipeline function (#38)

* tiny bug fix for alpha rendering; remove the pipeline function

* fix import
parent d1e7ddce
......@@ -8,8 +8,8 @@ project = "nerfacc"
copyright = "2022, Ruilong"
author = "Ruilong"
release = "0.1.1"
version = "0.1.1"
release = "0.1.2"
version = "0.1.2"
# -- General configuration
......
from .contraction import ContractionType, contract, contract_inv
from .grid import Grid, OccupancyGrid
from .pipeline import rendering, volumetric_rendering
from .pipeline import rendering
from .ray_marching import (
ray_aabb_intersect,
ray_marching,
......@@ -26,6 +26,5 @@ __all__ = [
"render_visibility",
"render_weight_from_alpha",
"render_weight_from_density",
"volumetric_rendering",
"rendering",
]
......@@ -2,8 +2,7 @@ from typing import Callable, Optional, Tuple
import torch
from .grid import Grid
from .ray_marching import ray_marching, unpack_to_ray_indices
from .ray_marching import unpack_to_ray_indices
from .vol_rendering import accumulate_along_rays, render_weight_from_density
......@@ -105,112 +104,3 @@ def rendering(
colors = colors + render_bkgd * (1.0 - opacities)
return colors, opacities, depths
def volumetric_rendering(
# radiance field
sigma_fn: Callable,
rgb_sigma_fn: Callable,
# rays
rays_o: torch.Tensor,
rays_d: torch.Tensor,
t_min: Optional[torch.Tensor] = None,
t_max: Optional[torch.Tensor] = None,
# bounding box of the scene
scene_aabb: Optional[torch.Tensor] = None,
# grid for skipping samples
grid: Optional[Grid] = None,
# rendering options
near_plane: Optional[float] = None,
far_plane: Optional[float] = None,
render_step_size: float = 1e-3,
stratified: bool = False,
cone_angle: float = 0.0,
early_stop_eps: float = 1e-4,
render_bkgd: Optional[torch.Tensor] = None,
return_extra_info: bool = False,
) -> Tuple[torch.Tensor, torch.Tensor, int, int]:
"""Differentiable volumetric rendering pipeline.
This function is the integration of those individual functions:
- ray_aabb_intersect: ray AABB intersection.
- ray_marching: ray marching with grid-based skipping.
- compute_weights: compute transmittance and compress samples.
- accumulate_along_rays: accumulate samples along rays to get final per-ray RGB etc.
Args:
sigma_fn: A function that takes in samples {t_starts (N, 1), t_ends (N, 1),
ray indices (N,)} and returns the post-activation density values (N, 1).
rgb_sigma_fn: A function that takes in samples {t_starts (N, 1), t_ends (N, 1),
ray indices (N,)} and returns the post-activation rgb (N, 3) and density
values (N, 1).
rays_o: Ray origins. Tensor with shape (n_rays, 3).
rays_d: Normalized ray directions. Tensor with shape (n_rays, 3).
t_min: Optional. Per-ray minimum distance. Tensor with shape (n_rays).
t_max: Optional. Per-ray maximum distance. Tensor with shape (n_rays).
scene_aabb: Optional. Scene bounding box for computing t_min and t_max.
A tensor with shape (6,) {xmin, ymin, zmin, xmax, ymax, zmax}.
scene_aabb which be ignored if both t_min and t_max are provided.
grid: Optional. Grid for to idicates where to skip during marching.
See :class:`nerfacc.Grid` for details.
near_plane: Optional. Near plane distance. If provided, it will be used
to clip t_min.
far_plane: Optional. Far plane distance. If provided, it will be used
to clip t_max.
render_step_size: Step size for marching. Default: 1e-3.
stratified: Whether to use stratified sampling. Default: False.
cone_angle: Cone angle for linearly-increased step size. 0. means
constant step size. Default: 0.0.
early_stop_eps: Early stop threshold for marching. Default: 1e-4.
render_bkgd: Optional. Background color. If provided, it will be used
to fill the background. Default: None.
return_extra_info: Whether to return extra info. Default: False.
Returns:
Ray colors (n_rays, 3), opacities (n_rays, 1) and depths (n_rays, 1).
If return_extra_info is True, it will also return a dictionary of extra info,
including:
- "n_marching_samples": Total number of samples kept after marching.
- "n_rendering_samples": Total number of samples used for actual rendering.
"""
assert rays_o.shape == rays_d.shape and rays_o.dim() == 2, "Invalid rays."
n_rays = rays_o.shape[0]
rays_o = rays_o.contiguous()
rays_d = rays_d.contiguous()
extra_info = {}
with torch.no_grad():
# Ray marching with skipping.
packed_info, t_starts, t_ends = ray_marching(
rays_o,
rays_d,
t_min=t_min,
t_max=t_max,
scene_aabb=scene_aabb,
grid=grid,
sigma_fn=sigma_fn,
early_stop_eps=early_stop_eps,
near_plane=near_plane,
far_plane=far_plane,
render_step_size=render_step_size,
stratified=stratified,
cone_angle=cone_angle,
)
extra_info["n_rendering_samples"] = len(t_starts)
colors, opacities, depths = rendering(
rgb_sigma_fn,
packed_info=packed_info,
t_starts=t_starts,
t_ends=t_ends,
early_stop_eps=early_stop_eps,
render_bkgd=render_bkgd,
)
if return_extra_info:
return colors, opacities, depths, extra_info
else:
return colors, opacities, depths
......@@ -322,7 +322,7 @@ class _RenderingAlpha(torch.autograd.Function):
alphas,
weights,
) = ctx.saved_tensors
grad_sigmas = _C.rendering_backward(
grad_sigmas = _C.rendering_alphas_backward(
weights,
grad_weights,
packed_info,
......
......@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "nerfacc"
version = "0.1.1"
version = "0.1.2"
authors = [{name = "Ruilong", email = "ruilongli94@gmail.com"}]
license = { text="MIT" }
requires-python = ">=3.8"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment