mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-22 23:30:35 +08:00
Barycentric clipping in the renderer and flat shading
Summary: Updates to the Renderer to enable barycentric clipping. This is important when there is blurring in the rasterization step. Also added support for flat shading. Reviewed By: jcjohnson Differential Revision: D19934259 fbshipit-source-id: 036e48636cd80d28a04405d7a29fcc71a2982904
This commit is contained in:
committed by
Facebook Github Bot
parent
f358b9b14d
commit
ff19c642cb
24
tests/test_mesh_rendering_utils.py
Normal file
24
tests/test_mesh_rendering_utils.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
|
||||
|
||||
import unittest
|
||||
import torch
|
||||
|
||||
from pytorch3d.renderer.mesh.utils import _clip_barycentric_coordinates
|
||||
|
||||
|
||||
class TestMeshRenderingUtils(unittest.TestCase):
|
||||
def test_bary_clip(self):
|
||||
N = 10
|
||||
bary = torch.randn(size=(N, 3))
|
||||
# randomly make some values negative
|
||||
bary[bary < 0.3] *= -1.0
|
||||
# randomly make some values be greater than 1
|
||||
bary[bary > 0.8] *= 2.0
|
||||
negative_mask = bary < 0.0
|
||||
positive_mask = bary > 1.0
|
||||
clipped = _clip_barycentric_coordinates(bary)
|
||||
self.assertTrue(clipped[negative_mask].sum() == 0)
|
||||
self.assertTrue(clipped[positive_mask].gt(1.0).sum() == 0)
|
||||
self.assertTrue(torch.allclose(clipped.sum(dim=-1), torch.ones(N)))
|
||||
Reference in New Issue
Block a user