JoeyDeVries / LearnOpenGL

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com
https://learnopengl.com
Other
11k stars 2.8k forks source link

2.1.2.ibl_irradiance #129

Open dsfdeeeg opened 5 years ago

dsfdeeeg commented 5 years ago

2.1.2.irradiance_convolution.fs
irradiance = PI irradiance (1.0 / float(nrSamples));

why not 1/PI?

2.1.2.pbr.fs for(int i = 0; i < 4; ++i) { ........ Lo += (kD albedo / PI + specular) radiance NdotL; } why not 1/4?

xqms commented 5 years ago

why not 1/PI?

I arrived at this question myself. In the end I think the code is correct, but the derivation on https://learnopengl.com/PBR/IBL/Diffuse-irradiance contains a wrong final equation. The Riemann sum approximation of the integral introduces additional factors (2*pi)/n1 and (0.5*pi)/n2, but the equations only show 1/(n1*n2). If you simplify further, you get pi as the resulting factor - which is what the code is doing.