NVlabs / nvdiffrast

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

how to obtain per-pixel mipmap level #179

Closed 07hyx06 closed 6 months ago

07hyx06 commented 6 months ago

Hi, thanks for the great project!

In my project I want to use the mipmap's level of each pixel to weight the photometric loss. I wonder is there a way to obtain the mipmap level for each pixel? I go through the document and find that the code to determine the mipmap level is inside the nvdiffrast.torch.texture function. Did I miss something?

Thanks in advance.

s-laine commented 6 months ago

You're correct; the mipmap level calculation based on the texture coordinate pixel derivatives is an internal computation of the texturing op. Replicating the formula in pytorch would be simplest solution. A more hacky approach would be specifying a manual mipmap stack where the the texel values on each level contain the mip level number, run the texturing op, and read the result. This is probably not as efficient as running a replica of the formula, though, but could be used to validate the solution.

If you want to override the internally computed mipmap level in the texture op with one you have calculated yourself, you can do so via the mip_level_bias parameter.

07hyx06 commented 6 months ago

Thanks!