Skip to content
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

Closed
MouseChannel opened this issue May 21, 2023 · 7 comments
Closed

confusion about Path_tracing cosine distributed Pdf #54

MouseChannel opened this issue May 21, 2023 · 7 comments

Comments

@MouseChannel
Copy link
Contributor

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

@Nbickford
Copy link

Nbickford commented May 21, 2023 via email

@Nbickford
Copy link

Nbickford commented May 21, 2023 via email

@MouseChannel
Copy link
Contributor Author

MouseChannel commented May 22, 2023

maybe I did not make my question clear
p = 1/PI here represent the pdf of importance sampling pdf (which there is cos_weight_sampling)
line 111

vec3 rayDirection = samplingHemisphere(prd.seed, tangent, bitangent, world_normal);

show the out-going ray sampling strategy, and using cos_weight importance sampling
$$L_r =\int_{H^2} Li* BRDF *(indir \cdot normal) dw_i $$
$$L_r=\frac{ Li * BDRF * (indir \cdot normal)}{pdf} $$
here the pdf of cos_weight imporance sampling is $$p = pdf = \frac{cosTheta}{Pi}$$ just like you mentioned

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).

and here you said

and
so always had cos(n, out) BRDF(in, out)/PDF(in, out) == 1.

$$\frac{cos(n, out) BRDF(in, out)} {PDF(in, out)} = \frac{cosTheta*1{/}Pi}{cosTheta/Pi} = 1$$

So if p represent pdf of cos_weight sampling here ,why should not be cosTheta/ Pi?
I worry about that latex may not be rendered if you read it from mail, and thanks to your reply.

@MouseChannel
Copy link
Contributor Author

and if p = 1/Pi as the pdf of sampling , in hemisphere the integral of p is not 1

@Nbickford
Copy link

Ah, I see! Sorry about that - thank you for following up! Since samplingHemisphere() is cosine-weighted, this line of code was incorrect -- it should have been const float p = cos_theta / M_PI. (As a result, you might notice that running the current code under the white furnace test renders a sphere that is too dark.) We'll put in a fix. Thanks!

@MouseChannel
Copy link
Contributor Author

:)

@NBickford-NV
Copy link
Contributor

Fixed in #56 and 80e00ca; closing. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants