NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.43k stars 158 forks source link

How to incorporate Cook-Torrance BRDF? #21

Closed nairb2020 closed 3 years ago

nairb2020 commented 3 years ago

Hi awesome people,

I'm curious if there's a way to use ideas https://www.microsoft.com/en-us/research/wp-content/uploads/2009/12/sg.pdf to incorporate Cook-Torrance Gaussian Mixture model as BRDF. It looks like I need to put in my own prefiltered MIPMAP. However, if I do that, I still need to multiply each pixel with the correct Fresnel and Shadow. How do I do that? Is it possible to request an example?

In addition, would gradient be propagated to input MIPMAP if I did that? How do I make sure gradients are propagated back as well?

s-laine commented 3 years ago

Hi nairb2020, and apologies for the delayed answer.

If you specify a custom mipmap stack as a list of tensors in the mip parameter, gradients will be propagated to these individual tensors by the texture op. From there, the gradients will propagate through any code you used to construct these tensors, assuming that was done in Torch/TensorFlow.

I'm not familiar with the specific method you cited, but generally speaking, most shading models require further per-pixel operations to be performed after texture sampling. If you use standard arithmetic operations provided by Torch/Tensorflow to do these, all gradients will propagate as expected.

nairb2020 commented 3 years ago

Thanks!