-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
confusion about Path_tracing cosine distributed Pdf #54
Comments
Here's one way of thinking about the 1/pi term: imagine a diffuse, white
plane. If I shine light on this plane, the amount of light reflected -
summing over all directions it might scatter to - should be the same as the
incoming amount of light. In other words, the material model should be
energy-conserving.
Mathematically, 1/pi is the right factor to make this hold for the
Lambertian normal distribution function; if we multiplied by a greater
number, the material would reflect more light than it received, and if it
was smaller, the material would appear darker than it should be. (The white
furnace test is one way to verify that one's normalization factor for a
material model is correct.)
In more detail, energy conservation requires that for any incoming light
direction (above the surface), the integral over all outgoing light
directions of
max(0, dot(outgoing light direction, normal)) * brdf(incoming light
direction, outgoing light direction)
is 1. (The dot product comes from
https://en.m.wikipedia.org/wiki/Rendering_equation. See also
https://en.m.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function#Physically_based_BRDFs).
The Lambertian BRDF corresponds to BRDF(incoming, outgoing) := 1/pi.
In practice, we'd like to have an algorithm to estimate the integral in the
rendering equation. For perfect material sampling, we'd choose outgoing
light directions with a probability density function equal to the integrand
(ignoring the visibility and lighting factors^1). This is possible for the
Lambertian BRDF, and the algorithm in the code chooses outgoing directions
with pdf = cos theta/pi (where cos theta is the dot product in the equation
above).
However, with more complex BRDFs (e.g. GGX), perfectly sampling the BRDF
like this isn't always possible. So, usually material model code implements
* A function to evaluate the BRDF
* An algorithm to produce samples that match the BRDF relatively well
* A function that returns the probability density function of that
algorithm choosing a certain direction.
Then when choosing samples, we weight them by cos(n, out) BRDF(in,
out)/PDF(in, out). This method is known as importance sampling:
https://en.m.wikipedia.org/wiki/Importance_sampling .
Finally, if you've read through vk_mini_path_tracer, you might have noticed
that vk_mini_path_tracer never mentions PDFs. This is because I hid this
detail: I always chose material models that could be perfectly sampled, and
so always had `cos(n, out) BRDF(in, out)/PDF(in, out) == 1`. (Ray Tracing
in One Weekend uses the same idea in Book 1, and introduces PDFs in Book
3.) Vk_raytracing_tutorial_KHR gives more of the story around material
models, in this sense.
[^1]: Ignoring these visibility and lighting factors makes sampling the
BRDF easy - but means that our sampling pattern won't match the true value
of the rendering equation's integrand. The results will still be correct,
but they'll be noisy (if we could somehow sample the integrand perfectly,
we'd have no noise, but this is usually impossible except for the simplest
of scenes). Techniques like ReSTIR incorporate visibility terms, and
lighting terms are often used in sampling in combined techniques like
*multiple importance sampling*.
…--Neil
On Sun, May 21, 2023, 00:35 莫成莫成你最棒 ***@***.***> wrote:
https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/blob/8d4ba64b1816ef020bebe33298d496b305df2aca/ray_tracing_gltf/shaders/pathtrace.rchit#LL114C8-L114C9
the cosine_weight important sampling' pdf is cos_theta / PI
why here is 1/PI
really Confused
—
Reply to this email directly, view it on GitHub
<#54>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIFUVPRKKRKIUQZ5OIUMMLXHHATHANCNFSM6AAAAAAYJHJV7M>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I forgot to mention:
https://sakibsaikia.github.io/graphics/2019/09/10/Deriving-Lambertian-BRDF-From-First-Principles.html
is another excellent explanation of where the division by pi in the
Lambertian BRDF comes from.
…--Neil
On Sun, May 21, 2023, 01:15 Neil Bickford ***@***.***> wrote:
Here's one way of thinking about the 1/pi term: imagine a diffuse, white
plane. If I shine light on this plane, the amount of light reflected -
summing over all directions it might scatter to - should be the same as the
incoming amount of light. In other words, the material model should be
energy-conserving.
Mathematically, 1/pi is the right factor to make this hold for the
Lambertian normal distribution function; if we multiplied by a greater
number, the material would reflect more light than it received, and if it
was smaller, the material would appear darker than it should be. (The white
furnace test is one way to verify that one's normalization factor for a
material model is correct.)
In more detail, energy conservation requires that for any incoming light
direction (above the surface), the integral over all outgoing light
directions of
max(0, dot(outgoing light direction, normal)) * brdf(incoming light
direction, outgoing light direction)
is 1. (The dot product comes from
https://en.m.wikipedia.org/wiki/Rendering_equation. See also
https://en.m.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function#Physically_based_BRDFs).
The Lambertian BRDF corresponds to BRDF(incoming, outgoing) := 1/pi.
In practice, we'd like to have an algorithm to estimate the integral in
the rendering equation. For perfect material sampling, we'd choose outgoing
light directions with a probability density function equal to the integrand
(ignoring the visibility and lighting factors^1). This is possible for the
Lambertian BRDF, and the algorithm in the code chooses outgoing directions
with pdf = cos theta/pi (where cos theta is the dot product in the equation
above).
However, with more complex BRDFs (e.g. GGX), perfectly sampling the BRDF
like this isn't always possible. So, usually material model code implements
* A function to evaluate the BRDF
* An algorithm to produce samples that match the BRDF relatively well
* A function that returns the probability density function of that
algorithm choosing a certain direction.
Then when choosing samples, we weight them by cos(n, out) BRDF(in,
out)/PDF(in, out). This method is known as importance sampling:
https://en.m.wikipedia.org/wiki/Importance_sampling .
Finally, if you've read through vk_mini_path_tracer, you might have
noticed that vk_mini_path_tracer never mentions PDFs. This is because I hid
this detail: I always chose material models that could be perfectly
sampled, and so always had `cos(n, out) BRDF(in, out)/PDF(in, out) == 1`.
(Ray Tracing in One Weekend uses the same idea in Book 1, and introduces
PDFs in Book 3.) Vk_raytracing_tutorial_KHR gives more of the story around
material models, in this sense.
[^1]: Ignoring these visibility and lighting factors makes sampling the
BRDF easy - but means that our sampling pattern won't match the true value
of the rendering equation's integrand. The results will still be correct,
but they'll be noisy (if we could somehow sample the integrand perfectly,
we'd have no noise, but this is usually impossible except for the simplest
of scenes). Techniques like ReSTIR incorporate visibility terms, and
lighting terms are often used in sampling in combined techniques like
*multiple importance sampling*.
--Neil
On Sun, May 21, 2023, 00:35 莫成莫成你最棒 ***@***.***> wrote:
>
> https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/blob/8d4ba64b1816ef020bebe33298d496b305df2aca/ray_tracing_gltf/shaders/pathtrace.rchit#LL114C8-L114C9
>
> the cosine_weight important sampling' pdf is cos_theta / PI
> why here is 1/PI
> really Confused
>
> —
> Reply to this email directly, view it on GitHub
> <#54>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAIFUVPRKKRKIUQZ5OIUMMLXHHATHANCNFSM6AAAAAAYJHJV7M>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
|
maybe I did not make my question clear
show the out-going ray sampling strategy, and using cos_weight importance sampling here the pdf of cos_weight imporance sampling is
and here you said
So if p represent pdf of cos_weight sampling here ,why should not be cosTheta/ Pi? |
and if p = 1/Pi as the pdf of sampling , in hemisphere the integral of p is not 1 |
Ah, I see! Sorry about that - thank you for following up! Since |
:) |
https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/blob/8d4ba64b1816ef020bebe33298d496b305df2aca/ray_tracing_gltf/shaders/pathtrace.rchit#LL114C8-L114C9
the cosine_weight important sampling' pdf is cos_theta / PI
why here is 1/PI
really Confused
The text was updated successfully, but these errors were encountered: