How to calculate attenuation and radiance in PBR? (point and directional lights) I would like implement physically based rendering, following this tutorial

I was able to find a list of light sources ordered by lumens, but I have no idea how to use it in the calculations.

float attenuation = 1.0 / (distance * distance);
vec3 radiance = lightColor * attenuation;


What should the lightColor be, if the light source is a 60W lightbulb (780 lm) and in my scene one unit is one cm?

How should I define the radiance, if I have a directional light, for example the sun?
How should I define the radiance, if I have a directional light, for example the sun?


The radiance in physics has different definitions in different books. I will use the definition with irradiance and radiant flux here.

Imagine photons having some energy $Q$. Your radiant flux $\Phi$ is the amount of energy $Q$ (and therefore the amount of photons) per unit time $t$. To get the energy for an instant (an infinitesimally short time), you use the change ($\Delta$) of energy over the change of time for $\lim_{t\rightarrow0}$ i.e.

$$\Phi = \lim_{t\rightarrow0} \frac{\Delta Q}{ \Delta t} = \frac{dQ}{dt}$$

Energy is measured in Joules and time in seconds, therefore radiant flux is measured in $\frac{J}{s}$.

This however doesn't say anything about the surface you're measuring the energy at, but if you want to light an object, that needs to be taken into account.
Therefore, you define irradiance $E$ as your radiant flux per area $A$ (note that irradiance usually means energy arriving at an area, whereas radiosity is energy leaving the area, but is otherwise defined exactly the same way). Since some integrations later on are easier to do with infinitesimally small area patches, we go that route again, but I will not rewrite the limes stuff all the time.

$$E = \frac{d\Phi}{dA}$$

Note that it is assumed, that the photons' traveling direction is assumed to be perpendicular to the surface.
Irradiance is thus measured in $\frac{J}{sm^2}$.

To understand radiance, you need to understand solid angles. I will just assume that you do, otherwise read up on it, this is really an important concept for physically based lighting.

The problem with irradiance is, that you cannot take into consideration any directionality of the light. The directionality can be expressed through solid angles $\omega$, where an infinitesimally small solid angle $d\omega$ can be seen as a vector.

Imagine that you have a sheet of paper parallel to another sheet of paper, one emitting and one receiving light, both equal in size. You can express all you need with irradiance. Now let the emitting sheet of paper transform into your light bulb centered at where the emitting sheet of paper was before. All of a sudden, it makes a difference, if you measure the light at the corners of the receiving sheet of paper or at its center.

Therefore, to take directionality into account, you define radiance $L$ as the irradiance per solid angle of the light. $\omega$ is the solid angle and we want to use the infinitessimally small one again, thus $d\omega$.
$$L = \frac{dE}{d\omega}$$
Thus your radiance is measured in $\frac{J}{sm^2sr}$ where sr is the solid angle unit steradians and really is dimensionles. 

Looking at the definitions of Watts it's $W = \frac{J}{s}$ , therefore radiance measurement can be seen as $\frac{W}{m^2sr}$.

Edit 04th of August 2017:
The radiance in the end is exactly what you calculate as a pixel's color, it is what you see. In the real world, it is wave length dependend, but of course in computer graphics it is an RGB color vector. Therefore, you don't define radiance, you calculate it.


  What should the lightColor be, if the light source is a 60W lightbulb (780 lm) and in my scene one unit is one cm?


Light usually uses different wave lengths lambda which determine the color of the light. For example, imagine a photon of red light, i.e. $\lambda=700nm$ , then it has the energy of $\frac{hc}{\lambda}$ where $h$ is Planck's constant and $c$ is the speed of light, leading to about $2.838\times10^{-19}J$ for this red photon.

If your light bulb "uses" just one single wave length and is a $60W=60\frac{J}{s}$ light bulb, then you can calculate the energy, radiant flux, irradiance and finally radiance... If you know the exact spectral emission, you can also calculate this.
However, that is probably not really what you are looking for.

Edited 04th of August 2017:
Therefore, your (or rather the tutorials code) to calculate radiance is an oversimplified way of modeling the lightsource.  It does not take into account the power of the light source directly, it is just modelled by a color vector.



What the tutorial is asking you to do is to think of the color you want your light to be, and write down the RGB value for it. If your light is just white, use an RGB value of (1,1,1), try it in your scene and if you then think it's too bright, lower the values until you're satisfied (or increase them, if it's not bright enough).

Edited 04th of August 2017:
If you want to use the physically based light bulb, then you will need to take more into account and I'd really advice you to read up on this.
A good book for this is Physically Based Rendering (by Matt Pharr et al.). 
As that is expensive and takes a long time to read, you can also try to get along with some of the Physically Based Shading course materials of previous years, to be found on the Selfshadow Blog. Especially, there is some explanation on Sebastien Lagarde's Moving Frostbite to Physically Based Rendering

On a side note, the sun is usually modeled as being so distant to the receiver of the light, that you don't take attenuation into account. Thus you would just multiply by the light color (or set the attenuation to 1).