Skip to content

Commit 46c0e83

Browse files
Steve Bransonfacebook-github-bot
authored andcommitted
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 (cc70950). Reviewed By: gkioxari Differential Revision: D23375257 fbshipit-source-id: 4b87588aabb69d4d835d4dcceb11153628121d30
1 parent c25fd83 commit 46c0e83

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pytorch3d/renderer/mesh/rasterizer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(
3737
bin_size: Optional[int] = None,
3838
max_faces_per_bin: Optional[int] = None,
3939
perspective_correct: bool = False,
40-
clip_barycentric_coords: bool = False,
40+
clip_barycentric_coords: Optional[bool] = None,
4141
cull_backfaces: bool = False,
4242
):
4343
self.image_size = image_size
@@ -125,6 +125,14 @@ def forward(self, meshes_world, **kwargs) -> Fragments:
125125
"""
126126
meshes_screen = self.transform(meshes_world, **kwargs)
127127
raster_settings = kwargs.get("raster_settings", self.raster_settings)
128+
129+
# By default, turn on clip_barycentric_coords if blur_radius > 0.
130+
# When blur_radius > 0, a face can be matched to a pixel that is outside the
131+
# face, resulting in negative barycentric coordinates.
132+
clip_barycentric_coords = raster_settings.clip_barycentric_coords
133+
if clip_barycentric_coords is None:
134+
clip_barycentric_coords = raster_settings.blur_radius > 0.0
135+
128136
# TODO(jcjohns): Should we try to set perspective_correct automatically
129137
# based on the type of the camera?
130138
pix_to_face, zbuf, bary_coords, dists = rasterize_meshes(
@@ -135,7 +143,7 @@ def forward(self, meshes_world, **kwargs) -> Fragments:
135143
bin_size=raster_settings.bin_size,
136144
max_faces_per_bin=raster_settings.max_faces_per_bin,
137145
perspective_correct=raster_settings.perspective_correct,
138-
clip_barycentric_coords=raster_settings.clip_barycentric_coords,
146+
clip_barycentric_coords=clip_barycentric_coords,
139147
cull_backfaces=raster_settings.cull_backfaces,
140148
)
141149
return Fragments(

0 commit comments

Comments
 (0)