Closed kwea123 closed 3 years ago
Just noticed that the same concept can be used to compute depth2pts_outside
, just by replacing the norm 1
with norm r
, ie. find t
such that ||o+td||=r
. This implementation is consistently faster than the original one, and probably easier to understand.
This function computes the intersection depth, but there is no explanation either in the paper or in the code. https://github.com/Kai-46/nerfplusplus/blob/57920483846bbab7708f9d30f797f42962b6d6e1/ddp_train_nerf.py#L42-L57
So in case it's not clear for somebody, I intend to provide some insights of how it is calculated, and a faster implementation based on my approach: We have the origin
o
and the directiond
, and we want the intersection depth with the unit sphere. A straightforward method is to findt
such that||o+td|| = 1
. By raising both sides to the square, what we get is a quadratic equation int
such that:Then we can solve
t
using the famous formula. \ It results in the following implementation:which I have verified to yield the same result (epsilon-close) as the original implementation, but 5-10x faster (11ms vs 2ms for 100k rays on my PC, not that significant though).
Another possible code optimization that we can do is possibly normalize
rays_d
from the beginning, that way we can get rid of thed_norm_sq
inintersect_sphere
and also here https://github.com/Kai-46/nerfplusplus/blob/57920483846bbab7708f9d30f797f42962b6d6e1/ddp_model.py#L82-L83