mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 11:52:50 +08:00
Bug fix in rendering clipped meshes
Summary: There was a bug when `z_clip_value` is not None but there are no faces which are actually visible in the image due to culling. In `rasterize_meshes.py` a function `convert_clipped_rasterization_to_original_faces` is called to convert the clipped face indices etc back to the unclipped versions, but the case where there is no clipping was not handled correctly. Fixes Github Issue #632 Reviewed By: bottler Differential Revision: D29116150 fbshipit-source-id: fae82a0b4848c84b3ed7c7b04ef5c9848352cf5c
This commit is contained in:
parent
bc8361fa47
commit
c75ca04cf7
@ -638,8 +638,11 @@ def convert_clipped_rasterization_to_original_faces(
|
|||||||
"""
|
"""
|
||||||
faces_clipped_to_unclipped_idx = clipped_faces.faces_clipped_to_unclipped_idx
|
faces_clipped_to_unclipped_idx = clipped_faces.faces_clipped_to_unclipped_idx
|
||||||
|
|
||||||
# If no clipping or culling then return inputs
|
# If no clipping then return inputs
|
||||||
if faces_clipped_to_unclipped_idx is None:
|
if (
|
||||||
|
faces_clipped_to_unclipped_idx is None
|
||||||
|
or faces_clipped_to_unclipped_idx.numel() == 0
|
||||||
|
):
|
||||||
return pix_to_face_clipped, bary_coords_clipped
|
return pix_to_face_clipped, bary_coords_clipped
|
||||||
|
|
||||||
device = pix_to_face_clipped.device
|
device = pix_to_face_clipped.device
|
||||||
|
@ -657,22 +657,30 @@ class TestRenderMeshesClipping(TestCaseMixin, unittest.TestCase):
|
|||||||
|
|
||||||
def test_mesh_outside_frustrum(self):
|
def test_mesh_outside_frustrum(self):
|
||||||
"""
|
"""
|
||||||
Test the case where the mesh is completely outside the view
|
Test cases:
|
||||||
|
1. Where the mesh is completely outside the view
|
||||||
frustrum so all faces are culled and z_clip_value = None.
|
frustrum so all faces are culled and z_clip_value = None.
|
||||||
|
2. Where the part of the mesh is in the view frustrum but
|
||||||
|
the z_clip value = 5.0 so all the visible faces are behind
|
||||||
|
the clip plane so are culled instead of clipped.
|
||||||
"""
|
"""
|
||||||
device = "cuda:0"
|
device = "cuda:0"
|
||||||
mesh = torus(20.0, 85.0, 32, 16, device=device)
|
mesh1 = torus(20.0, 85.0, 32, 16, device=device)
|
||||||
tex = TexturesVertex(verts_features=torch.rand_like(mesh.verts_padded()))
|
mesh2 = torus(2.0, 3.0, 32, 16, device=device)
|
||||||
mesh.textures = tex
|
for (mesh, z_clip) in [(mesh1, None), (mesh2, 5.0)]:
|
||||||
raster_settings = RasterizationSettings(image_size=512, cull_to_frustum=True)
|
tex = TexturesVertex(verts_features=torch.rand_like(mesh.verts_padded()))
|
||||||
R, T = look_at_view_transform(1.0, 0.0, 0.0)
|
mesh.textures = tex
|
||||||
cameras = PerspectiveCameras(device=device, R=R, T=T)
|
raster_settings = RasterizationSettings(
|
||||||
renderer = MeshRenderer(
|
image_size=512, cull_to_frustum=True, z_clip_value=z_clip
|
||||||
rasterizer=MeshRasterizer(cameras=cameras, raster_settings=raster_settings),
|
)
|
||||||
shader=SoftPhongShader(cameras=cameras, device=device),
|
R, T = look_at_view_transform(3.0, 0.0, 0.0)
|
||||||
)
|
cameras = PerspectiveCameras(device=device, R=R, T=T)
|
||||||
images = renderer(mesh)
|
renderer = MeshRenderer(
|
||||||
|
rasterizer=MeshRasterizer(
|
||||||
# Mesh is completely outside the view frustrum
|
cameras=cameras, raster_settings=raster_settings
|
||||||
# The image should be white.
|
),
|
||||||
self.assertClose(images[0, ..., :3], torch.ones_like(images[0, ..., :3]))
|
shader=SoftPhongShader(cameras=cameras, device=device),
|
||||||
|
)
|
||||||
|
images = renderer(mesh)
|
||||||
|
# The image should be white.
|
||||||
|
self.assertClose(images[0, ..., :3], torch.ones_like(images[0, ..., :3]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user