in utils/renderer.py [0:0]
def render(self, verts: th.Tensor):
"""
:param verts: B x V x 3 tensor containing a batch of face vertex positions to be rendered
:return: B x 640 x 480 x 4 tensor containing the rendered images
"""
R, T = look_at_view_transform(7.5, 0, 20)
focal = th.tensor([5.0], dtype=th.float32).to(self.device)
princpt = th.tensor([0.1, 0.1], dtype=th.float32).to(self.device).unsqueeze(0)
cameras = PerspectiveCameras(device=self.device, focal_length=focal, R=R, T=T, principal_point=princpt)
raster_settings = RasterizationSettings(
image_size=[640, 480],
blur_radius=0.0,
faces_per_pixel=1,
)
lights = PointLights(device=self.device, location=[[0.0, 0.0, 10.0]])
verts = verts * 0.01
textures = Textures(verts_rgb=self.verts_rgb.expand(verts.shape[0], -1, -1))
mesh = Meshes(
verts=verts.to(self.device),
faces=self.faces.expand(verts.shape[0], -1, -1),
textures=textures
)
with th.no_grad():
renderer = MeshRenderer(
rasterizer=MeshRasterizer(
cameras=cameras,
raster_settings=raster_settings
),
shader=SoftPhongShader(
device=self.device,
cameras=cameras,
lights=lights
)
)
images = renderer(mesh)
return images