Kai-46 / PhySG

Code for PhySG: Inverse Rendering with Spherical Gaussians for Physics-based Relighting and Material Editing
MIT License
221 stars 24 forks source link

The lobe of fs is wr rather than normal? #17

Closed yihua7 closed 2 years ago

yihua7 commented 2 years ago

Hi Kai, I really appreciate your excellent work! I just have a question about the implementation of sg rendering code: here

final_lobes, final_lambdas, final_mus = lambda_trick(lgtSGLobes, lgtSGLambdas, lgtSGMus, warpBrdfSGLobes, warpBrdfSGLambdas, warpBrdfSGMus)

warpBrdfSGLobes here is the reflection direction of views, rather than surface normals. But in the paper, Eq(8) tells that the Gaussian is aligned with surface normal. Is this a little bug or something I misunderstand?

Screenshot from 2022-10-17 23-43-22

By the way, I am looking forward to your future works!

Kai-46 commented 2 years ago

Here's an intuitive way to think about the spherical warping of the brdf lobe.

Imagine we want to render the color for a specific viewing direction w_o; then the rendering equation says that we need to sum up the contributions of light coming from all directions w_i that lies on the hemisphere centered around surface normal n.

Of course this is going to be a weighted sum given the surface BRDF, as light from the reflected viewing direction is likely to contribute most (think about mirror reflection)

Hence, in spherical Gaussian model, we place a spherical Gaussian around the reflected viewing direction to model the contribution strength of lights coming from different directions.

To read more about the mathematical derivations, please check Eq. 16 of this SG paper: https://www.microsoft.com/en-us/research/wp-content/uploads/2009/12/sg.pdf

This blog also has nice explanations of the SG-based rendering: https://therealmjp.github.io/posts/sg-series-part-4-specular-lighting-from-an-sg-light-source/

yihua7 commented 2 years ago

Thanks Kai! The answer is really clear and makes sense.