13
13
14
14
15
15
def rendering (
16
- # radiance field
17
- rgb_sigma_fn : Callable ,
18
16
# ray marching results
19
17
packed_info : torch .Tensor ,
20
18
t_starts : torch .Tensor ,
21
19
t_ends : torch .Tensor ,
20
+ # radiance field
21
+ rgb_sigma_fn : Optional [Callable ] = None ,
22
+ rgb_alpha_fn : Optional [Callable ] = None ,
22
23
# rendering options
23
24
early_stop_eps : float = 1e-4 ,
24
25
alpha_thre : float = 0.0 ,
@@ -33,12 +34,17 @@ def rendering(
33
34
This function is not differentiable to `t_starts`, `t_ends`.
34
35
35
36
Args:
36
- rgb_sigma_fn: A function that takes in samples {t_starts (N, 1), t_ends (N, 1), \
37
- ray indices (N,)} and returns the post-activation rgb (N, 3) and density \
38
- values (N, 1).
39
37
packed_info: Packed ray marching info. See :func:`ray_marching` for details.
40
38
t_starts: Per-sample start distance. Tensor with shape (n_samples, 1).
41
39
t_ends: Per-sample end distance. Tensor with shape (n_samples, 1).
40
+ rgb_sigma_fn: A function that takes in samples {t_starts (N, 1), t_ends (N, 1), \
41
+ ray indices (N,)} and returns the post-activation rgb (N, 3) and density \
42
+ values (N, 1). At least one of `rgb_sigma_fn` and `rgb_alpha_fn` should be \
43
+ specified.
44
+ rgb_alpha_fn: A function that takes in samples {t_starts (N, 1), t_ends (N, 1), \
45
+ ray indices (N,)} and returns the post-activation rgb (N, 3) and opacity \
46
+ values (N, 1). At least one of `rgb_sigma_fn` and `rgb_alpha_fn` should be \
47
+ specified.
42
48
early_stop_eps: Early stop threshold during trasmittance accumulation. Default: 1e-4.
43
49
alpha_thre: Alpha threshold for skipping empty space. Default: 0.0.
44
50
render_bkgd: Optional. Background color. Tensor with shape (3,).
@@ -76,22 +82,47 @@ def rgb_sigma_fn(t_starts, t_ends, ray_indices):
76
82
print(colors.shape, opacities.shape, depths.shape)
77
83
78
84
"""
85
+ if callable (packed_info ):
86
+ raise RuntimeError (
87
+ "You maybe want to use the nerfacc<=0.2.1 version. For nerfacc>0.2.1, "
88
+ "The first argument of `rendering` should be the packed ray packed info. "
89
+ "See the latest documentation for details: "
90
+ "https://www.nerfacc.com/en/latest/apis/rendering.html#nerfacc.rendering"
91
+ )
92
+
93
+ if rgb_sigma_fn is None and rgb_alpha_fn is None :
94
+ raise ValueError (
95
+ "At least one of `rgb_sigma_fn` and `rgb_alpha_fn` should be specified."
96
+ )
97
+
79
98
n_rays = packed_info .shape [0 ]
80
99
ray_indices = unpack_info (packed_info )
81
100
82
- # Query sigma and color with gradients
83
- rgbs , sigmas = rgb_sigma_fn (t_starts , t_ends , ray_indices .long ())
84
- assert rgbs .shape [- 1 ] == 3 , "rgbs must have 3 channels, got {}" .format (
85
- rgbs .shape
86
- )
87
- assert (
88
- sigmas .shape == t_starts .shape
89
- ), "sigmas must have shape of (N, 1)! Got {}" .format (sigmas .shape )
90
-
91
- # Rendering: compute weights and ray indices.
92
- weights = render_weight_from_density (
93
- packed_info , t_starts , t_ends , sigmas , early_stop_eps , alpha_thre
94
- )
101
+ # Query sigma/alpha and color with gradients
102
+ if rgb_sigma_fn is not None :
103
+ rgbs , sigmas = rgb_sigma_fn (t_starts , t_ends , ray_indices .long ())
104
+ assert rgbs .shape [- 1 ] == 3 , "rgbs must have 3 channels, got {}" .format (
105
+ rgbs .shape
106
+ )
107
+ assert (
108
+ sigmas .shape == t_starts .shape
109
+ ), "sigmas must have shape of (N, 1)! Got {}" .format (sigmas .shape )
110
+ # Rendering: compute weights and ray indices.
111
+ weights = render_weight_from_density (
112
+ packed_info , t_starts , t_ends , sigmas , early_stop_eps , alpha_thre
113
+ )
114
+ elif rgb_alpha_fn is not None :
115
+ rgbs , alphas = rgb_alpha_fn (t_starts , t_ends , ray_indices .long ())
116
+ assert rgbs .shape [- 1 ] == 3 , "rgbs must have 3 channels, got {}" .format (
117
+ rgbs .shape
118
+ )
119
+ assert (
120
+ alphas .shape == t_starts .shape
121
+ ), "alphas must have shape of (N, 1)! Got {}" .format (alphas .shape )
122
+ # Rendering: compute weights and ray indices.
123
+ weights = render_weight_from_alpha (
124
+ packed_info , alphas , early_stop_eps , alpha_thre
125
+ )
95
126
96
127
# Rendering: accumulate rgbs, opacities, and depths along the rays.
97
128
colors = accumulate_along_rays (
@@ -244,7 +275,7 @@ def render_weight_from_alpha(
244
275
early_stop_eps : float = 1e-4 ,
245
276
alpha_thre : float = 0.0 ,
246
277
) -> torch .Tensor :
247
- """Compute transmittance weights from density .
278
+ """Compute transmittance weights from opacity .
248
279
249
280
Args:
250
281
packed_info: Stores information on which samples belong to the same ray. \
0 commit comments