From 46c0e834616f6950d0ed5a9826a49744d8e83f7e Mon Sep 17 00:00:00 2001 From: Steve Branson Date: Thu, 27 Aug 2020 16:42:40 -0700 Subject: [PATCH] Change default settings of clip_barycentric_coords Summary: When raster_settings.clip_barycentric_coords is unspecified, clip_barycentric_coords is turned on if blur_radius is greater than 0. This matches the behavior prior to D21705503 (https://github.com/facebookresearch/pytorch3d/commit/cc70950f4064e3feeb55281b829aa55aa4a7e942). Reviewed By: gkioxari Differential Revision: D23375257 fbshipit-source-id: 4b87588aabb69d4d835d4dcceb11153628121d30 --- pytorch3d/renderer/mesh/rasterizer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pytorch3d/renderer/mesh/rasterizer.py b/pytorch3d/renderer/mesh/rasterizer.py index 424cdb44..04044f5f 100644 --- a/pytorch3d/renderer/mesh/rasterizer.py +++ b/pytorch3d/renderer/mesh/rasterizer.py @@ -37,7 +37,7 @@ class RasterizationSettings: bin_size: Optional[int] = None, max_faces_per_bin: Optional[int] = None, perspective_correct: bool = False, - clip_barycentric_coords: bool = False, + clip_barycentric_coords: Optional[bool] = None, cull_backfaces: bool = False, ): self.image_size = image_size @@ -125,6 +125,14 @@ class MeshRasterizer(nn.Module): """ meshes_screen = self.transform(meshes_world, **kwargs) raster_settings = kwargs.get("raster_settings", self.raster_settings) + + # By default, turn on clip_barycentric_coords if blur_radius > 0. + # When blur_radius > 0, a face can be matched to a pixel that is outside the + # face, resulting in negative barycentric coordinates. + clip_barycentric_coords = raster_settings.clip_barycentric_coords + if clip_barycentric_coords is None: + clip_barycentric_coords = raster_settings.blur_radius > 0.0 + # TODO(jcjohns): Should we try to set perspective_correct automatically # based on the type of the camera? pix_to_face, zbuf, bary_coords, dists = rasterize_meshes( @@ -135,7 +143,7 @@ class MeshRasterizer(nn.Module): bin_size=raster_settings.bin_size, max_faces_per_bin=raster_settings.max_faces_per_bin, perspective_correct=raster_settings.perspective_correct, - clip_barycentric_coords=raster_settings.clip_barycentric_coords, + clip_barycentric_coords=clip_barycentric_coords, cull_backfaces=raster_settings.cull_backfaces, ) return Fragments(