|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import imageio |
|
import numpy as np |
|
import torch |
|
import nvdiffrast.torch as dr |
|
|
|
def tensor(*args, **kwargs): |
|
return torch.tensor(*args, device='cuda', **kwargs) |
|
|
|
pos = tensor([[[-0.8, -0.8, 0, 1], [0.8, -0.8, 0, 1], [-0.8, 0.8, 0, 1]]], dtype=torch.float32) |
|
col = tensor([[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], dtype=torch.float32) |
|
tri = tensor([[0, 1, 2]], dtype=torch.int32) |
|
|
|
glctx = dr.RasterizeGLContext() |
|
rast, _ = dr.rasterize(glctx, pos, tri, resolution=[256, 256]) |
|
out, _ = dr.interpolate(col, rast, tri) |
|
|
|
img = out.cpu().numpy()[0, ::-1, :, :] |
|
img = np.clip(np.rint(img * 255), 0, 255).astype(np.uint8) |
|
|
|
print("Saving to 'tri.png'.") |
|
imageio.imsave('tri.png', img) |
|
|