Last active
September 20, 2022 15:26
-
-
Save ventusff/e9c9e395427c8a367e3c0763d5900b18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ray_sphere_intersection_rough( | |
rays_o: torch.Tensor, rays_d: torch.Tensor, *, | |
r=1.0, keepdim=True, t_min_cons: float=0.0, t_max_cons: float=None) -> Tuple[torch.Tensor, torch.Tensor]: | |
""" | |
NOTE: Modified from https://github.com/Totoro97/NeuS | |
rays_o: camera center's coordinate | |
rays_d: camera rays' directions. already normalized. | |
""" | |
dir_scale = rays_d.norm(dim=-1, keepdim=keepdim).clamp_min_(1e-10) | |
# NOTE: (minus) the length of the line projected from [the line from camera to sphere center] to [the line of camera rays] | |
# scale: In the scaled space. | |
mid = -torch.sum(rays_o * rays_d / dir_scale, dim=-1, keepdim=keepdim) | |
# NOTE: a convservative approximation of the half chord length from ray intersections with the sphere. | |
# all half chord length < r | |
# scale: In the original un-scaled space. | |
near, far = ((mid - r)/dir_scale).clamp_min_(t_min_cons), ((mid + r)/dir_scale).clamp_(r/dir_scale, t_max_cons) | |
return near, far |
XiaohangYang829
commented
Sep 20, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment