<p>I think the answer is: neither, since this GGX distribution is <strong>NOT sampling the direction for a ray but a microfacet normal</strong>. According to the paper of <a href="https://www.cs.cornell.edu/%7Esrm/publications/EGSR07-btdf.pdf" rel="nofollow noreferrer">GGX: Microfacet Models for Refraction through Rough Surfaces</a>, this distribution is used to sample the normal direction for the microfacet, which you can think of as sampling a new normal direction <strong>with respect to</strong> the original normal direction (macroscopic). Therefore, the coordinate frame is spanned by the original macroscopic normal, for example, we use the macroscopic normal as local z-axis, then the <span class="math-container">$\theta$</span> here is the angle between the newly sampled microfacet normal and the macroscopic normal, as shown in the following figure.</p>
<p>So, how do you get the direction of the light? First, we get the normal we want just by using GGX, to sample a microfacet normal. Then, maybe we will start to sample surface event like whether we evaluate the diffuse part or the specular part. Take evaluating specular part as an example, now we have a incident direction, a microfacet normal, then we can directly calculate the outgoing direction.</p>
<p><a href="https://i.sstatic.net/C9hey.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/C9hey.png" alt="enter image description here" /></a></p>
<blockquote>
<p>Also, can I use this θ directly to calculate the BRDF?</p>
</blockquote>
<p>Yes. Sampling an outgoing direction will also require you to calculate the path throughput. This throughput coefficient is calculated using the parameters you've sampled.</p>
<p>So, in all, sampling a new ray direction is usually pretty local around one specific normal (geometric / shading / sampled microfacet normal), so we will usually set the frame according to the normal. However, this is not the case when you are dealing with medium scattering (phase function). In this case, the sampling is usually done in the frame spanned by original incident ray direction.</p>

CC BY-SA 4.0
2023-07-16T08:57:21.277Z
By light direction I suppose you really mean $\omega_i$, i.e. the direction of the next ray bounce. By incident direction I suppose you mean $-\omega_o$, in a backwards ray-tracer setting, and by specular the reflection of $\omega_o$ around the sampled microfacet normal $m$. I believe one has to also account for a Jacobian for this transform too.
lightxbulb
CC BY-SA 4.0
2023-07-16T10:00:40.253Z
Yes. My answer is just an intuitive illustration for the whole process. To be more rigorous, we should be more careful about these terms and the Jacobian you've mentioned.
Enigmatisms
CC BY-SA 4.0
2023-07-16T10:46:16.763Z
This is just extremely helpful, I've just been completely clueless about what to do with the sampled vector. I had a hunch that it had to be the microfacet normal as if it was the ray direction, then it would have absolutely no correlation to the incident ray, well, the viewing direction, considering that I'm writing a backwards path tracer. There is still the matter of how to handle a ray that reflects into the surface of the object. Intuitively I think that the ray should just terminate, as reflecting into the surface can be interpreted as it being absorbed.
RandomPigYT
CC BY-SA 4.0
2023-07-16T11:47:56.093Z
You terminate if the ray ends up below the surface, the contribution is zero in the rendering equation because n dot w_i becomes negative, i.e. you clamp it to zero. To avoid this and sample until you get a correct direction you would have to have a very specific normalisation computed from an integral not over the hemisphere, but some parts of it, which is probably hard.
lightxbulb
CC BY-SA 4.0
2023-07-16T08:27:04.057Z
2023-07-16T08:27:04.057Z
Enigmatisms
<p>So, I'm attempting to implement a monte carlo path tracer that uses the ggx brdf model. However, I'm rather confused about how to sample the light direction.
I know that theta and phi can be sampled like this:</p>
<p><span class="math-container">$\theta=\arctan\left(\alpha\sqrt\frac{\xi_1}{1-\xi_1}\right)$</span></p>
<p><span class="math-container">$\phi=2\pi\xi_2$</span></p>
<p>But whose coordinates are these? Are they the microfacet normal's (half vector), or are they those of the light direction?</p>
<p>If they are the coordinates of the light direction, how should they be transformed into the world-space coordinates?</p>
<p>Also, can I use this <span class="math-container">$\theta$</span> directly to calculate the BRDF?</p>

<rendering><pathtracing><brdf>
Importance sampling in a path tracer
RandomPigYT
# Importance sampling in a path tracer

(Asked by: username_0 on 2023-07-15)

So, I'm attempting to implement a monte carlo path tracer that uses the ggx brdf model. However, I'm rather confused about how to sample the light direction.
I know that theta and phi can be sampled like this:

$\theta=\arctan\left(\alpha\sqrt\frac{\xi\_1}{1-\xi\_1}\right)$

$\phi=2\pi\xi\_2$

But whose coordinates are these? Are they the microfacet normal's (half vector), or are they those of the light direction?

If they are the coordinates of the light direction, how should they be transformed into the world-space coordinates?

Also, can I use this $\theta$ directly to calculate the BRDF?

**Tags:** rendering, pathtracing, brdf


---

## 1 answers

### Answer by username_1 on 2023-07-16. Score: 3 | Accepted answer

I think the answer is: neither, since this GGX distribution is **NOT sampling the direction for a ray but a microfacet normal**. According to the paper of [GGX: Microfacet Models for Refraction through Rough Surfaces](https://www.cs.cornell.edu/%7Esrm/publications/EGSR07-btdf.pdf), this distribution is used to sample the normal direction for the microfacet, which you can think of as sampling a new normal direction **with respect to** the original normal direction (macroscopic). Therefore, the coordinate frame is spanned by the original macroscopic normal, for example, we use the macroscopic normal as local z-axis, then the $\theta$ here is the angle between the newly sampled microfacet normal and the macroscopic normal, as shown in the following figure.

So, how do you get the direction of the light? First, we get the normal we want just by using GGX, to sample a microfacet normal. Then, maybe we will start to sample surface event like whether we evaluate the diffuse part or the specular part. Take evaluating specular part as an example, now we have a incident direction, a microfacet normal, then we can directly calculate the outgoing direction.

[![enter image description here](https://i.sstatic.net/C9hey.png)](https://i.sstatic.net/C9hey.png)

> Also, can I use this θ directly to calculate the BRDF?

Yes. Sampling an outgoing direction will also require you to calculate the path throughput. This throughput coefficient is calculated using the parameters you've sampled.

So, in all, sampling a new ray direction is usually pretty local around one specific normal (geometric / shading / sampled microfacet normal), so we will usually set the frame according to the normal. However, this is not the case when you are dealing with medium scattering (phase function). In this case, the sampling is usually done in the frame spanned by original incident ray direction.

> **Comments:**
> **username_2**: By light direction I suppose you really mean $\omega_i$, i.e. the direction of the next ray bounce. By incident direction I suppose you mean $-\omega_o$, in a backwards ray-tracer setting, and by specular the reflection of $\omega_o$ around the sampled microfacet normal $m$. I believe one has to also account for a Jacobian for this transform too.  
> **username_1**: Yes. My answer is just an intuitive illustration for the whole process. To be more rigorous, we should be more careful about these terms and the Jacobian you've mentioned.  
> **username_0**: This is just extremely helpful, I've just been completely clueless about what to do with the sampled vector. I had a hunch that it had to be the microfacet normal as if it was the ray direction, then it would have absolutely no correlation to the incident ray, well, the viewing direction, considering that I'm writing a backwards path tracer. There is still the matter of how to handle a ray that reflects into the surface of the object. Intuitively I think that the ray should just terminate, as reflecting into the surface can be interpreted as it being absorbed.  
> **username_2**: You terminate if the ray ends up below the surface, the contribution is zero in the rendering equation because n dot w_i becomes negative, i.e. you clamp it to zero. To avoid this and sample until you get a correct direction you would have to have a very specific normalisation computed from an integral not over the hemisphere, but some parts of it, which is probably hard.  

---

