NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.31k stars 139 forks source link

bary differential code in geometry shader #64

Closed Mirocos closed 2 years ago

Mirocos commented 2 years ago

Hi, I was confused when i read the geometry shader in rasterize.cpp. Also, I read the related issue #49. But I am still confused with some questions:

  1. both d(u/w)dX and d(1/w) are constant over triangle, I can understand a lit why let u = (u/w) / (1/w) by reading the reference thesis showed in #49, but what's the actually formulation?

  2. why dudx = e1.y * ascl.x?

  3. what is ascl?

Those two questions have puzzled me so much that I can't find any helpful reference to get a true answer. So If you have a little bit time, can you help me with it?

Mirocos commented 2 years ago

I finally solved my confusion abount problem 2, But still left with 1 & 3

s-laine commented 2 years ago
  1. I'm not sure I understand the question, but the idea is to have an expression for the per-pixel bary differentials that are only based on the per-pixel barys and w, and factors that are constant over the triangle. These constant factors are computed once per triangle in the geometry shader so that the pixel shader stays as simple as possible.
  2. ascl.x and ascl.y are horizontal/vertical scaling factors for bary differentials, and they depend on both triangle area and viewport resolution. For example, if the viewport resolution is doubled, the bary differentials are halved as they measure change per pixel. The uniform vec2 vp_scale has the global scaling factors due to viewport resolution, and its value is set on line 478.
lishi0927 commented 1 year ago

I finally solved my confusion abount problem 2, But still left with 1 & 3

Could you explain more about question 2?