-
Hi, The book is great and it allows me to both refresh my maths & and my C#. I can’t however understand mathematically the explanation given to obtain a diffuse scattering following the Lambert cosine law. This law states that the probability of reflection follows a cosine law centered on the normal: there is more probability that the reflected ray is close to the normal (if angle theta between the normal and this vector ~ 0 -> probability ~1) than close to the tangent plane (angle ~90 -> probability ~0). It is indeed a cosine. The implementation proposed advocates the use of a random unit vector added to the normal (N) to define the direction of the reflected ray (R). I don’t see how statistically a cosine law would apply: in my opinion, the probability of drawing the unit ray is the same in all directions, and therefore follows a linear law. If we restrict the analysis to a 2D space, it is easy to model it by calculating the angle of each resulting ray with the normal: they have the same probabilities of occurence. I found on the internet this page https://www.particleincell.com/2015/cosine-distribution/ that explains how to obtain a cosine law. By remodeling it in Excel and using a online 3D viewer, it works correctly. The probability of drawing is higher around the normal. The implementation of the code is relatively simple. What is troubling, however, is that the resulting image is very similar to the one obtained by the book method. I wonder if differences would only appear with a more complex world. Can you tell me where I went wrong in my reasoning? Lambertian simulation: (3D online viewer : https://miabellaai.net) C# code for the method:
(I used a french / english translator software ) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'll try to give an intuitive answer to your question without going too deep into the math (at least based on my understanding of the topic). It's true that the samples are spread uniformly on the surface of the unit sphere but this doesn't directly represent the distribution of ray directions and offsetting the vectors by the normal vector introduces a bias to the overall distribution of scattering directions. I think it's more intuitive to think about the integral over all scattering directions as a hemisphere centered at the point of intersection and aligned to the normal vector, such that all points on the surface of the hemisphere are equally distant from the intersection point: Here the orange circle represents the sampled (and offset) unit sphere and the black semi-circle represents the hemisphere of ray directions. If you project the uniformly distributed set of points on the sphere (orange in the figure above) onto the hemisphere, you'll find that their overall distribution looks a lot like the picture you posted above. I put together a Python script and created a plot to demonstrate this:
The point of intersection is located at The blue dome corresponds to a biased (cosine-weighted) BRDF. I tried to provide a visual intuition but there is quite a bit of theory behind why the hemisphere makes sense for the reflectance model and how the cosine-weighted bias relates to the cosine term in the rendering equation. I recommend the following as further reading on the general theory behind this:
I hope this helps! P.S.:Higher-density plots of the projected points (showing both hemispheres for clarity): Looking down the normal vector: |
Beta Was this translation helpful? Give feedback.
I'll try to give an intuitive answer to your question without going too deep into the math (at least based on my understanding of the topic). It's true that the samples are spread uniformly on the surface of the unit sphere but this doesn't directly represent the distribution of ray directions and offsetting the vectors by the normal vector introduces a bias to the overall distribution of scattering directions. I think it's more intuitive to think about the integral over all scattering directions as a hemisphere centered at the point of intersection and aligned to the normal vector, such that all points on the surface of the hemisphere are equally distant from the intersection point:
Her…