## Introduction

In this section we'll take a look at how Materials are handled within LuxRender. This is not for the faint hearted and certainly not required for general rendering. This is for those people interested in knowing more about how the various materials are defined, and for those interested in being able to contribute new materials.

Materials in LuxRender are physically based, and the way light interacts with the surface is specified by the bidirectional scattering distribution function (BSDF). Given an incoming and outgoing vector, the BSDF determines how much of the incoming light is transmitted in the outgoing direction. Normally the BSDF is split up into two separate components: one handling reflection from the surface (the bidirectional reflection distribution function - BRDF), and one handling light transmitted through the surface (the bidirectional transmission distribution function - BTDF). Thus the BSDF can be thought of as a combination of a BRDF and a BTDF. A BxDF is a short hand way of representing either a BRDF or a BTDF.

Before we can formally define the BSDF however, basic radiometric concepts need to be explained.

### Flux Density (Φ)

You can think of this as either an energy in joules(J), or photons per second.

This is a measure of how much power is arriving/leaving an area, with units of watts per square meter, and so is defined as (Φ / Area)

### Intensity (I)

This is a measure of how much energy per second is travelling into a given solid angle, and is given by (I = Φ / w) where w is the solid angle being emitted into. It has units of watts per steradian. If you think about an isotropic point source, its power is distributed equally in all directions. As you move away from the point source, the irradiance decreases (inverse square law), however the intensity will remain constant.

The radiance is defined in units of watts per unit area per steradian, and is a very closely linked to how we perceive "brightness".

Formally it's defined as $L = {\Phi \over dw. dA. \cos (\theta)}$

Think of a small surface element dA that is radiating energy, and a detector measuring the energy (dD). The detector subtends a solid angle dwout as seen from dA, and θout is the angle between the dA surface normal and the detector direction.

It has the useful property that it is the same at any distance from the surface. If you move the detector back in a straight line, then phi will decrease in proportion to r2, but so does dw - so they cancel out.

One other interesting property is based on the concept of "geometrical extent" which arises in optics. It's also known as "etendue". It's defined as:

$\operatorname{d}^2G = dw. dA . \cos (\theta_{in})$

where dA is the area of our element, θin is the angle between the normal at dA and the direction of dS. dw is the solid angle of dS as seen from dA. Mathematically you can show that the geometric extent of dS from dA is the same as dA from dS, and radiance can be defined as $L=\operatorname{d}^2\Phi /\operatorname{d}^2 G$.

## Bidirectional Reflectance Distribution Function (BRDF)

Ok, so now that we have an idea of radiometric definitions, we can define the BRDF. Technically it is defined as:

$f (\theta_{in},\theta_{out}) \equiv {L_{out}(\theta_{in},\theta_{out}) \over L_{in}(\theta_{in}) . \cos (\theta_{in}) . dw }$

where Li and Lo are the incoming and outgoing radiance respectively. dw needs a bit of explaining. Consider the case where we have a small source emitting light (dS) which strikes our surface element(dA) and gets reflected. dw is the solid angle subtended by dS as seen from dA.

Lets work through what happens to the light as interacts with dA. Assume that we know the incoming radiance from dS = Lin. Now we need to calculate the flux at dA. From the definition of radiance we get:

$\Phi_{in} = L_{in} . G \,$

now in this case its easiest to use the geometrical extent of dS as seen from dA, so we get

$\Phi_{in} = L_{in} . dw. dA. \cos(\theta_{in}) \,$

where dw is the solid angle subtended by dS as seen from dA. For what it's worth we can calculate the incoming irradiance by dividing by dA, leaving Ein = Lin.dw

As the photons strike the surface, they get reflected, and the probability of them being reflected into a small solid angle dwout is pinout).dwout where p is the pdf. The outgoing flux into this same solid angle is

$\Phi_{out} = p(\theta_{in}, \theta_{out}).dw_{out}.\Phi_{in}(\theta_{in})\,$

\begin{align} L_{out} & = {\Phi_{out}\over (geometrical\, extent\, of \,detector\, as\, seen\, by\, dA)}\\ & = {\Phi_{out} \over dA. \cos(theta_{out}). dw_{out}}\\ & = {p(\theta_{in}, \theta_{out}). dw_{out}. \Phi_{in}(\theta_{in}) \over dA . \cos(\theta_{out}). dw_{out} }\\ & = {p(\theta_{in}, \theta_{out}). \Phi_{in}(\theta_{in}) \over dA . \cos (\theta_{out}) }\\ & = {p(\theta_{in}, \theta_{out}) . L_{in}. dw. dA . \cos(\theta_{in}) \over dA . \cos(\theta_{out}) } \\ & = {p(\theta_{in}, \theta_{out}) . L_{in}. dw. \cos(\theta_{in}) \over \cos(\theta_{out}) } \end{align}

now from the definition of the BRDF we get:

\begin{align} f & = {L_{out} \over L_{in}. \cos(\theta_{in}). dw }\\ & ={ p(\theta_{in}, \theta_{out}) . L_{in}. \cos(\theta_{in}) .dw \over \cos (\theta_{out}). L_{in} . \cos (\theta_{in}).dw }\\ & = {p(\theta_{in}, \theta_{out}) \over \cos(\theta_{out})} \end{align}

So the BDRF is related to the probability of an incoming photon being reflected in a certain direction, but with an additional 1 / cos(θout) factor.

## Bidirectional Transmittance Distribution Function (BTDF)

A similar definition exists for the BTDF, although obviously the light is transmitted through the surface, rather than reflected.

## Well-behaved BRDF / BTDFs

So, you have an idea for how you want light to interact with a surface. You can just plug the formula into the BRDF and off you go right? Well, not quite. There are some assumptions about BxDFs that LuxRender assumes to be true (as do most/all physically based renders).

An ideal BRDF satisfies all of these conditions:

### Helmholtz reciprocity

Basically if you reverse the incoming and outgoing directions you should get the same value. This is not valid for all surfaces - but is generally true, and Luxrender expects this principle to be obeyed. If you fail to do so then you'll get unexpected results.

### Conservation of energy

One of those fundamental laws of nature. For our purposes it really means that all of the outgoing energy must be equal to or less than the incoming energy - ie, our surface is not emitting anything, just transporting the incoming light.

Mathematically this is:

$\int\limits_\Omega \, f(\theta_{in}, \theta_{out} ) . \cos (\theta_{out}) . dw \le 1$

This principle can be stretched and you'll still get realistic results - but can lead to fireflies if you push it too far.

## Examples of BRDFs

If you understand everything so far, go to the top of the class. If not, don't worry, it's a very confusing area.

### Lambertian reflector

A Lambertian reflector has the same "brightness" regardless of the viewing angle, hence it has the same radiance irrespective of viewing angle. In reality it's impossible to construct such a material, but nevertheless it's often used as a basic matte material.

From our definition of the outgoing luminance above as :

$L_{out} = p(\theta_{in}, \theta_{out}). L_{in}. dw . \cos(\theta_{in}) \over \cos(\theta_{out})$

we can remove the θout dependence by setting p = k.cos(θout). The BRDF then becomes f= k. To normalise this we use the conservation of energy principle:

$\int\limits_\Omega \, f(\theta_{in}, \theta_{out} ) . \cos (\theta_{out}) . dw = k. \pi$

so k = 1 / π conserves energy, and our final lambertian BDRF is :

f = 1 / π