# 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?

• The Colour of a 60w light source can be any colour, it depends on its wavelengths. For a white colour light source "it cannot consist solely of the green light to which the eye's image-forming visual photoreceptors are most sensitive, but must include a generous mixture of red and blue wavelengths, to which they are much less sensitive." – ali Aug 30 '17 at 20:56

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

• Thank you for the long explanation. "try it in your scene and if you then think it's too bright, lower the values until you're satisfied": The whole purpose of PBR is to not just look good, but follow the laws of physic to get the result. I am looking for (linear) RGB values and intensities, which I can use to display a scene with daylight, or with lamps. But at the moment I can not put lights in that scene, because I have no idea, which color and intensity values would be realistic in the radiance = lightColor * intensity * attenuation equation – Iter Ator Aug 4 '17 at 21:42
• @IterAtor, sorry, I assumed you were looking to understand the rendering method rather than a translation of the real world to simulation (or as close as possible). As far as I can see it, the color (in PBR) is usually determined by the luminous intensity and the temperature. Chapter 4 in the Frostbite notes explains this. Note that this is perception based. Another way to get the color is with CIE color matching and the spectral emission of the light. I really advice to look into the Frostbite notes, I don't think I can give you a better explanation than they delivered already. – Tare Aug 6 '17 at 8:45

You need to convert luminous flux (lumens, $lm$) to luminance ($\frac{lm}{m^2sr}$) for the rendering equation. For that you need to know the physical properties of the light source. For example luminance $L$ of spherical light source of radius $r$ radiating over $4\pi$ solid angle and luminous flux $\phi$ has luminance: $$L = \frac{\phi}{4\pi^2r^2}$$ I think it's better to define lights straight using luminance instead of luminous flux though since you can simply measure luminance with spot meter instead of using cumbersome special equipment or be limited by values provided by manufacturers in illuminant packaging.

Regarding distance attenuation, all lights in PBR should be area lights and there's no explicit attenuation formula for lights because the distance attenuation emerges naturally from the rendering equation.

It's also better use photometric units instead of radiometric units for RGB-rendering (not spectral/monochromatic rendering). In photometric units the extraterrestrial sun luminance is ~1.9B cd/m^2 (don't try to measure sun with spot meter though!). If you want to use radiometric units, you need to take the spectral power distribution of the sun and integrate that with CIE color matching functions to get any reasonable values rendering.