NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.42k stars 157 forks source link

depth image render #172

Closed pysmeeatioj closed 6 months ago

pysmeeatioj commented 7 months ago

Is there a way to render depth using nvdiffrast? And can it remain differentiable? What about the normal map?

s-laine commented 7 months ago

Yes, both are possible. For depth, compute per-vertex camera-space depths and use the interpolate op with that as a vertex attribute to get a differentiable depth map. Similarly, to render a normal buffer, construct per-vertex normal vectors in any space you like, and interpolate those to get a per-pixel result.

pysmeeatioj commented 7 months ago

Yes, both are possible. For depth, compute per-vertex camera-space depths and use the interpolate op with that as a vertex attribute to get a differentiable depth map. Similarly, to render a normal buffer, construct per-vertex normal vectors in any space you like, and interpolate those to get a per-pixel result.

Thank you for your prompt reply! Are there any examples or tutorials for reference?

s-laine commented 7 months ago

A comment reply here appears to contain an example of interpolating a depth value, but I haven't tested if it works. For normal vectors, the solution is similar. See, e.g., here for an example of normal buffer computation in a different project built on top of nvdiffrast.

pysmeeatioj commented 7 months ago

image image thinks, it works! I get normal map by the depth gradient. And it is differentiable.

yuhaoliu7456 commented 2 months ago

op of nvd

Can you share your code example for obtaining the normal map?