NVlabs / nvdiffrec

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

How to define 'visible' in current training views #95

Closed foricee closed 1 year ago

foricee commented 1 year ago

Thank you for your great works! While I have something not clear. Supplemental Material, at the end of the SDF Regularizer part, the paper writes:

Specifically, for a triangular face f extracted from tetrahedron T, if f is not visible in current training views, we encourage the SDFs` at vertices of T to be positive with BCE loss

My question is that how to define 'visible' in current training views. I've read the code, but still can't find the implementation. buffers['occlusion'] in dmtet.py seems like to be relative. But I'm not sure. Could you give me some other supplemental material or advices?

foricee commented 1 year ago

After reading https://nvlabs.github.io/nvdiffrast/, I think I've found the solution

These codes are added in render/render.py, at the end of function render_mesh(), https://github.com/NVlabs/nvdiffrec/blob/main/render/render.py#L251

    rast = layers[0][1] 
    tri_id_col = rast[..., 3]
    visible_tri_id = torch.unique(tri_id_col[tri_id_col > 0]).long() - 1
    visible_tri = mesh.t_pos_idx[visible_tri_id]

Is this the right way to extract all visible triangles?

frankshen07 commented 1 year ago

Thank you for your interest in our work! Yes, the way you extract visible triangles is correct. Another thing you should need is https://github.com/NVIDIAGameWorks/kaolin/blob/6569ea3e89f3f70ec7885ec053d900653ade67f3/kaolin/ops/conversions/tetmesh.py#L105 which maps visible faces to tetrahedra.

foricee commented 1 year ago

Thank you for your interest in our work! Yes, the way you extract visible triangles is correct. Another thing you should need is https://github.com/NVIDIAGameWorks/kaolin/blob/6569ea3e89f3f70ec7885ec053d900653ade67f3/kaolin/ops/conversions/tetmesh.py#L105 which maps visible faces to tetrahedra.

It works. Thank you!