From 793fca55e61e574abd068ef8d585e3a9425edf53 Mon Sep 17 00:00:00 2001 From: Maxim Bonnaerens Date: Fri, 27 Oct 2023 22:55:39 +0200 Subject: [PATCH] Make resetting the near_plane in NearFarCollider optional. (#2465) * Make resetting the near_plane in NearFarCollider optional. It is not always desired to reset the near plane to 0.0 during inference. Added an optional flag. * no need to change precision * Update scene_colliders.py --------- Co-authored-by: Brent Yi --- nerfstudio/model_components/scene_colliders.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nerfstudio/model_components/scene_colliders.py b/nerfstudio/model_components/scene_colliders.py index 69c073b3b..025a46265 100644 --- a/nerfstudio/model_components/scene_colliders.py +++ b/nerfstudio/model_components/scene_colliders.py @@ -172,16 +172,20 @@ class NearFarCollider(SceneCollider): Args: near_plane: distance to near plane far_plane: distance to far plane + reset_near_plane: whether to reset the near plane to 0.0 during inference. The near plane can be + helpful for reducing floaters during training, but it can cause clipping artifacts during + inference when an evaluation or viewer camera moves closer to the object. """ - def __init__(self, near_plane: float, far_plane: float, **kwargs) -> None: + def __init__(self, near_plane: float, far_plane: float, reset_near_plane: bool = True, **kwargs) -> None: self.near_plane = near_plane self.far_plane = far_plane + self.reset_near_plane = reset_near_plane super().__init__(**kwargs) def set_nears_and_fars(self, ray_bundle: RayBundle) -> RayBundle: ones = torch.ones_like(ray_bundle.origins[..., 0:1]) - near_plane = self.near_plane if self.training else 0 + near_plane = self.near_plane if (self.training or not self.reset_near_plane) else 0 ray_bundle.nears = ones * near_plane ray_bundle.fars = ones * self.far_plane return ray_bundle