NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.35k stars 144 forks source link

Support to rasterize a batch of triangles #22

Closed Turlan closed 3 years ago

Turlan commented 3 years ago

Thanks for the code!

I want to use this code to rasterize a batch of meshes with different triangles. However, in your definition, it seems that this implementation only considers a same triangle for a batch. Could you provide an implementation that supports rasterization of a batch of triangles?

https://github.com/NVlabs/nvdiffrast/blob/a4e7a4db7e09695b4efc7641cc6b044ef706f953/nvdiffrast/torch/ops.py#L202

s-laine commented 3 years ago

Hi Turlan! It sounds like you're looking for the range mode for rasterization.

You will need to collect all vertex positions into a single tensor, and similarly for the triangle index triplets — be sure to adjust the vertex indices according to where the positions are in the combined position tensor. Then, you can use the ranges parameter when rasterizing to specify which span of triangles should be rasterized into each element of minibatch.

Turlan commented 3 years ago

Thanks! Yes, that's exactly what I need, I will try it later.

Turlan commented 3 years ago

Thanks! Yes, that's exactly what I need, I will try it later.