Base on the answer of scurest, I can get the following result(top: Geometry Parametric, bottom: triangle face index), you can check pixel-level correspondence in tev:


To distinguish from the background, I add an offset to face index: uvs[2 * loopi] = poly.index + 1, and I shuffled the face index to make it easier to visualize(the colors of adjacent faces may be almost the same under 256 different colors):
import cv2
import numpy as np
path_img_idx = "UVMap_TriFaceIndex_01.exr"
img_idx = cv2.imread(path_img_idx, -1)
img_idx = img_idx[:, :, 0].astype(np.int32)
max_idx = np.max(img_idx)
lut = np.arange(1, max_idx + 1)
np.random.shuffle(lut)
lut = np.array([0, *lut]).astype(np.int32) # 0 for background
img_idx = lut[img_idx] # https://stackoverflow.com/a/67765996/10636347
img_idx = (img_idx / max_idx * 255).astype(np.uint8)
img_idx_vis = cv2.applyColorMap(img_idx, cv2.COLORMAP_JET)
cv2.imwrite(path_img_idx[:-4] + "_vis.png", img_idx_vis)
For example, when rendering a depth map, each pixel records the distance in the z-direction to the nearest surface to form a depth map. Can the index of the nearest surface be recorded to form a new image for other purposes?
– LogWell Nov 20 '21 at 15:30I can generate a UV face index based on texture coordinates and treat it as a texture map to render. I will try to do this later.
– LogWell Nov 20 '21 at 16:46I need to render the mesh from different angles, and do some calculations according to the attributes of the face corresponding to the pixel.
So I hope to be able to render the index of the face and perform subsequent calculations along with Parametric in Geometry Node.
– LogWell Nov 20 '21 at 16:46