|
30 | 30 | HardFlatShader,
|
31 | 31 | HardGouraudShader,
|
32 | 32 | HardPhongShader,
|
| 33 | + SoftPhongShader, |
33 | 34 | SoftSilhouetteShader,
|
34 | 35 | TexturedSoftPhongShader,
|
35 | 36 | )
|
@@ -981,3 +982,63 @@ def test_texture_map_atlas(self):
|
981 | 982 | )
|
982 | 983 |
|
983 | 984 | self.assertClose(rgb, image_ref, atol=0.05)
|
| 985 | + |
| 986 | + def test_simple_sphere_outside_zfar(self): |
| 987 | + """ |
| 988 | + Test output when rendering a sphere that is beyond zfar with a SoftPhongShader. |
| 989 | + This renders a sphere of radius 500, with the camera at x=1500 for different |
| 990 | + settings of zfar. This is intended to check 1) setting cameras.zfar propagates |
| 991 | + to the blender and that the rendered sphere is (soft) clipped if it is beyond |
| 992 | + zfar, 2) make sure there are no numerical precision/overflow errors associated |
| 993 | + with larger world coordinates |
| 994 | + """ |
| 995 | + device = torch.device("cuda:0") |
| 996 | + |
| 997 | + # Init mesh |
| 998 | + sphere_mesh = ico_sphere(5, device) |
| 999 | + verts_padded = sphere_mesh.verts_padded() * 500 |
| 1000 | + faces_padded = sphere_mesh.faces_padded() |
| 1001 | + feats = torch.ones_like(verts_padded, device=device) |
| 1002 | + textures = TexturesVertex(verts_features=feats) |
| 1003 | + sphere_mesh = Meshes(verts=verts_padded, faces=faces_padded, textures=textures) |
| 1004 | + |
| 1005 | + R, T = look_at_view_transform(1500, 0.0, 0.0) |
| 1006 | + |
| 1007 | + # Init shader settings |
| 1008 | + materials = Materials(device=device) |
| 1009 | + lights = PointLights(device=device) |
| 1010 | + lights.location = torch.tensor([0.0, 0.0, +1000.0], device=device)[None] |
| 1011 | + |
| 1012 | + raster_settings = RasterizationSettings( |
| 1013 | + image_size=256, blur_radius=0.0, faces_per_pixel=1 |
| 1014 | + ) |
| 1015 | + for zfar in (10000.0, 100.0): |
| 1016 | + cameras = FoVPerspectiveCameras( |
| 1017 | + device=device, R=R, T=T, aspect_ratio=1.0, fov=60.0, zfar=zfar |
| 1018 | + ) |
| 1019 | + rasterizer = MeshRasterizer( |
| 1020 | + cameras=cameras, raster_settings=raster_settings |
| 1021 | + ) |
| 1022 | + blend_params = BlendParams(1e-4, 1e-4, (0, 0, 1.0)) |
| 1023 | + |
| 1024 | + shader = SoftPhongShader( |
| 1025 | + lights=lights, |
| 1026 | + cameras=cameras, |
| 1027 | + materials=materials, |
| 1028 | + blend_params=blend_params, |
| 1029 | + ) |
| 1030 | + renderer = MeshRenderer(rasterizer=rasterizer, shader=shader) |
| 1031 | + images = renderer(sphere_mesh) |
| 1032 | + rgb = images[0, ..., :3].squeeze().cpu() |
| 1033 | + |
| 1034 | + filename = "test_simple_sphere_outside_zfar_%d.png" % int(zfar) |
| 1035 | + |
| 1036 | + # Load reference image |
| 1037 | + image_ref = load_rgb_image(filename, DATA_DIR) |
| 1038 | + |
| 1039 | + if DEBUG: |
| 1040 | + Image.fromarray((rgb.numpy() * 255).astype(np.uint8)).save( |
| 1041 | + DATA_DIR / ("DEBUG_" + filename) |
| 1042 | + ) |
| 1043 | + |
| 1044 | + self.assertClose(rgb, image_ref, atol=0.05) |
0 commit comments