nerfstudio-project / nerfacc

A General NeRF Acceleration Toolbox in PyTorch.
https://www.nerfacc.com/
Other
1.37k stars 113 forks source link

Compute sigma distribution (uniform along the ray) #163

Closed KunalMGupta closed 1 year ago

KunalMGupta commented 1 year ago

Thanks for the great repo! I am wondering if it is possible to somehow obtain the entire sigma distribution (uniformly sampled) along a ray? In the naive NeRF case this should be possible but I don't know if it is feasible to do so in the current code. I looked into the shape of sigmas at https://github.com/KAIR-BAIR/nerfacc/blob/cf7ebaf168a3932977e31b258e050c6df0fdd43a/nerfacc/vol_rendering.py#L81

But I don't quite understand its shape. I had hoped that it looked more like (N_rays, N_samples_per_ray) but it is simply some number (M,1). I understand that the code tries to skip as many places as possible but they should simply be returned as zeros right? Plus, to compute weights from density I believe one has to have a uniformly sampled density distribution.

While we are at it, can you also give some intuition about the role of ray_indices parameter, like how is it ustilized in various functions?

Thanks!

liruilong940607 commented 1 year ago

We packed all samples from different rays into a "flatten" tensor, as different rays have various number of samples. In your notation M = \sum(number of samples for each ray). ray_indices has the shape of (M,), which is an 0-index integer that tells you which ray the sample belongs to.

If you want to compute weights, we have function render_weight_from_density to do it. Please check out the function here

KunalMGupta commented 1 year ago

Thanks for the response! I really appreciate you taking the time to answer my query. I ended up figuring it out myself by using a combination of pack_info and unpack_data

https://github.com/KAIR-BAIR/nerfacc/blob/cf7ebaf168a3932977e31b258e050c6df0fdd43a/nerfacc/pack.py#L124

Using these, I can get the entire density distribution.