|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import imageio |
|
import logging |
|
import os |
|
import numpy as np |
|
import tensorflow as tf |
|
import nvdiffrast.tensorflow as dr |
|
|
|
|
|
logging.getLogger('tensorflow').setLevel(logging.ERROR) |
|
os.environ.setdefault('TF_CPP_MIN_LOG_LEVEL', '1') |
|
|
|
pos = tf.convert_to_tensor([[[-0.8, -0.8, 0, 1], [0.8, -0.8, 0, 1], [-0.8, 0.8, 0, 1]]], dtype=tf.float32) |
|
col = tf.convert_to_tensor([[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], dtype=tf.float32) |
|
tri = tf.convert_to_tensor([[0, 1, 2]], dtype=tf.int32) |
|
|
|
rast, _ = dr.rasterize(pos, tri, resolution=[256, 256]) |
|
out, _ = dr.interpolate(col, rast, tri) |
|
|
|
with tf.Session() as sess: |
|
img = sess.run(out) |
|
|
|
img = img[0, ::-1, :, :] |
|
img = np.clip(np.rint(img * 255), 0, 255).astype(np.uint8) |
|
|
|
print("Saving to 'tri.png'.") |
|
imageio.imsave('tri.png', img) |
|
|