Why is cos() in the denominator in the reflectance equation and in the numerator in the shading equation? Background: I'm reading https://learnopengl.com/PBR to learn about PBR. In the theory slide (https://learnopengl.com/PBR/Theory), the author has the reflectant equation as



The theta (the angle between normal vector and the incoming light) is in the denominator. However, on the lighting slide (https://learnopengl.com/PBR/Lighting) he has the familiar code for the radiance of a light source, which makes the $\cos(\theta)$ on the numerator.

vec3  lightColor  = vec3(23.47, 21.31, 20.79);
vec3  wi          = normalize(lightPos - fragPos);
float cosTheta    = max(dot(N, Wi), 0.0);
float attenuation = calculateAttenuation(fragPos, lightPos);
float radiance    = lightColor * attenuation * cosTheta;


Can someone explain this fine point to me?
The first is a definition of radiance in terms of the flux - it's a the derivative of flux with respect to both area and direction. It's simply a relation between $\Phi$ and $L$. It simply says that if you integrate radiance over the area of some surface, and for each point you integrate over all possible directions, then you will get the flux arriving/leaving that surface.
The second part comes from the restriction of the rendering equation to a single point light source.
Remember that:
$$L(x,\omega_o) = L_e(x,\omega_o) + \int_{\Omega}{f(\omega_o,x,\omega_i)L_i(x,\omega_i)\cos\theta_i \,d\omega_i}$$
Where $x$ is a point on some surface, and $L(x,\omega_o)$ gives you the radiance incoming from $x$ in the direction $\omega_o$. This radiance is the sum of emitted radiance from $x$ in direction $\omega_o$: $L_e(x,\omega_o)$, and the scattered radiance by $x$ in direction $\omega_o$. The integral is necessary, since light may arrive from any direction at $x$, so you need to integrate over all directions. $f$ is the brdf, which really tells you how much of the light arriving from direction $\omega_i$ is reflected towards $\omega_o$ at $x$. $L_i(x,\omega_i)$ is the incoming radiance from direction $\omega_i$ at $x$, and the cosine is there to account for Lambert's law. What happens when you evaluate only direct lighting from a point light is that the integral is over a domain that is a single point, so you get only the integrand part, which you have in your code. Note that this is just an intuitive explanation, there are various issues with radiance not being defined for point lights.