diff --git a/pytorch3d/renderer/mesh/textures.py b/pytorch3d/renderer/mesh/textures.py index 67abf2ef..5f134635 100644 --- a/pytorch3d/renderer/mesh/textures.py +++ b/pytorch3d/renderer/mesh/textures.py @@ -995,9 +995,13 @@ class TexturesUV(TexturesBase): # is the left-top pixel of input, and values x = 1, y = 1 is the # right-bottom pixel of input. - pixel_uvs = pixel_uvs * 2.0 - 1.0 + # map to a range of [-1, 1] and flip the y axis + pixel_uvs = torch.lerp( + pixel_uvs.new_tensor([-1.0, 1.0]), + pixel_uvs.new_tensor([1.0, -1.0]), + pixel_uvs, + ) - texture_maps = torch.flip(texture_maps, [2]) # flip y axis of the texture map if texture_maps.device != pixel_uvs.device: texture_maps = texture_maps.to(pixel_uvs.device) texels = F.grid_sample( @@ -1035,8 +1039,12 @@ class TexturesUV(TexturesBase): texture_maps = self.maps_padded() # NxHxWxC texture_maps = texture_maps.permute(0, 3, 1, 2) # NxCxHxW - faces_verts_uvs = faces_verts_uvs * 2.0 - 1.0 - texture_maps = torch.flip(texture_maps, [2]) # flip y axis of the texture map + # map to a range of [-1, 1] and flip the y axis + faces_verts_uvs = torch.lerp( + faces_verts_uvs.new_tensor([-1.0, 1.0]), + faces_verts_uvs.new_tensor([1.0, -1.0]), + faces_verts_uvs, + ) textures = F.grid_sample( texture_maps, diff --git a/tests/test_render_meshes.py b/tests/test_render_meshes.py index f6b91a93..61fe4641 100644 --- a/tests/test_render_meshes.py +++ b/tests/test_render_meshes.py @@ -932,7 +932,7 @@ class TestRenderMeshes(TestCaseMixin, unittest.TestCase): ) ).save(DATA_DIR / f"DEBUG_test_joinuvs{i}_map3.png") - self.assertClose(output, merged) + self.assertClose(output, merged, atol=0.005) self.assertClose(output, image_ref, atol=0.005) self.assertClose(mesh.textures.maps_padded()[0].cpu(), map_ref, atol=0.05)