NVlabs / nvdiffrec

Official code for the CVPR 2022 (oral) paper "Extracting Triangular 3D Models, Materials, and Lighting From Images".
Other
2.13k stars 223 forks source link

Incompatible vertex normals used in rendering #85

Open pean1128 opened 1 year ago

pean1128 commented 1 year ago

Hi, I found an incompatible issue in the calculation of vertex normal. In the main pipeline, each explicit mesh is extracted and rendered with the following function, which ensures the vertex normal of mesh will be recomputed through weighting face normal.

self.getMesh(opt_material)

However, the above recomputation process is missing in data preparation and lead to incompatible shading result. https://github.com/NVlabs/nvdiffrec/blob/main/dataset/dataset_mesh.py#L48 https://github.com/NVlabs/nvdiffrec/blob/main/dataset/dataset_mesh.py#L92

self.ref_mesh = mesh.compute_tangents(ref_mesh)
.......
img = render.render_mesh(self.glctx, self.ref_mesh, mvp, campos, self.envlight, iter_res, spp=iter_spp,                                num_layers=self.FLAGS.layers, msaa=True, background=None)['shaded']
JHnvidia commented 1 year ago

Hi @pean1128,

This is intentional. For our trained geometry, we're always using smooth normals (because supporting creases etc would be more difficult). We assume that if there's a sharp normal discontiuity it could be handled through the normal/bump map.

For mesh datasets we use the normals loaded from the .obj file instead. These are typically provided by the 3d editing tool. Some meshes (e.g. a box) will have deliberate normal discontinuities. Using auto_normals in the dataset_mesh class would override this and cause the box to be shaded like a sphere.

pean1128 commented 1 year ago

Hi @pean1128,

This is intentional. For our trained geometry, we're always using smooth normals (because supporting creases etc would be more difficult). We assume that if there's a sharp normal discontiuity it could be handled through the normal/bump map.

For mesh datasets we use the normals loaded from the .obj file instead. These are typically provided by the 3d editing tool. Some meshes (e.g. a box) will have deliberate normal discontinuities. Using auto_normals in the dataset_mesh class would override this and cause the box to be shaded like a sphere.

Thanks a lot, I get this point🙂