facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.81k stars 1.32k forks source link

How to render between two z-planes #1898

Closed danielgordon10 closed 1 week ago

danielgordon10 commented 1 month ago

❓ Questions on how to use PyTorch3D

I would like to call the render function and only render triangles that fall between znear and zfar planes. However when I try to use those values when setting up the camera, they seem to have no effect on the final image. This is not what I'd expect based on my understanding of OpenGL definition of these terms, but maybe here they mean something different.

Is this something Pytorch3d supports? I cannot really understand what the znear and zfar parameters are being used for. Based on the docs it just sounds like it is rescaling output coordinates rather than actually defining render planes.

bottler commented 1 week ago

If you use SoftPhongShader or SoftGouraudShader then znear and zfar will be used in the blending calculation, which may be what you want.

Also znear will in only some cases cause a z_clip_value in rasterization: see the logic in https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/renderer/mesh/rasterizer.py#L236 .

Otherwise they do not universally affect rendering. The rasterizer itself does not have a notion of a far plane.