Difference between revisions of "Physically-based BRDF"

From KlayGE
Jump to: navigation, search
(Created page with "== Introduction == Physically based rendering have been known for many years, but the "ad-hoc" rendering models (such as Phong) are still widely used in game. These "ad-hoc" mo...")
 
Line 9: Line 9:
 
The most common used rendering model in game describes only reflectance, not including terms such as SSS. The reflectance equation is:
 
The most common used rendering model in game describes only reflectance, not including terms such as SSS. The reflectance equation is:
  
<math>L_0(\mathbf{v})=\int_{\Omega} \rho(\mathbf{l},\mathbf{v}) \otimes L_i(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i</math>
+
<center><math>L_0(\mathbf{v})=\int_{\Omega} \rho(\mathbf{l},\mathbf{v}) \otimes L_i(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i</math></center>
  
 
Here <math>\rho(\mathbf{l},\mathbf{v})</math> is BRDF, <math>L_i(\mathbf{l})</math> is the contribution from light source, <math>(\mathbf{n} \cdot \mathbf{l})</math> is the angle between light and surface normal. This integration results the sum of all light sources contribute to a surface point.
 
Here <math>\rho(\mathbf{l},\mathbf{v})</math> is BRDF, <math>L_i(\mathbf{l})</math> is the contribution from light source, <math>(\mathbf{n} \cdot \mathbf{l})</math> is the angle between light and surface normal. This integration results the sum of all light sources contribute to a surface point.
Line 17: Line 17:
 
The simplest BRDF is the Lambert. The well-known Lambertian BRDF in game is present as <math>(\mathbf{n} \cdot \mathbf{l})</math>. However, it is part of reflectance equation, and lambertian term is actually a constant value:
 
The simplest BRDF is the Lambert. The well-known Lambertian BRDF in game is present as <math>(\mathbf{n} \cdot \mathbf{l})</math>. However, it is part of reflectance equation, and lambertian term is actually a constant value:
  
<math>\rho_{lambert}(\mathbf{l},\mathbf{v})=\frac{\mathbf{c}_{diff}}{\pi}</math>
+
<center><math>\rho_{lambert}(\mathbf{l},\mathbf{v})=\frac{\mathbf{c}_{diff}}{\pi}</math></center>
 +
 
 +
== Punctual Light Sources ==
 +
 
 +
These are classic point, directional, and spot lights in compute games. These local light source can be abstracted to a concept named "''punctual light sources''". They are infinitely small light with centain direction. Since what we want is the lighting reach a surface point, we don't need to consider the attenuation. A punctual light source are parameterized by the light color <math>\mathbf{c}_{light}</math> and the light direction vector <math>\mathbf{l_c}</math>. The light color <math>\mathbf{c}_{light}</math> is specified as the color a white Lambertian surface would have when illuminated by the light from a direction parallel to the surface normal (<math>\mathbf{l_c}=\mathbf{n}</math>).
 +
 
 +
How to calculate the contribution from this light source to a point? Here we will start by defining a tiny area light source centered on <math>\mathbf{l_c}</math>, with a small angular extent <math>\varepsilon</math>. This tiny area light illuminates a shaded surface point with the incoming radiance function <math>L_{tiny}(\mathbf{l})</math>. The incoming radiance function has the following two properties:
 +
 
 +
<center><math>\forall\mathbf{l}|\angle(\mathbf{l}, \mathbf{l_c})>\varepsilon, L_{tiny}(\mathbf{l})=0</math></center>
 +
 
 +
<center><math>if \mathbf{l_c}=\mathbf{n}, \mathbf{c}_{light}=\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i</math></center>
 +
 
 +
The first property says that no light is incoming for any light directions which form an angle greater than <math>\varepsilon</math> with <math>\mathbf{l_c}</math>. The second property follows from the definition of <math>\mathbf{c}_{light}</math>. Since the surface is white, <math>\mathbf{c}_{diff}=1</math>. Applying reflectance equation and Lambert from last article, there's the second property. Because <math>\mathbf{c}_{light}</math> requires <math>\mathbf{l_c}=\mathbf{n}</math>, it is the limit as <math>\varepsilon</math> goes to 0:
 +
 
 +
<center><math>if \mathbf{l_c}=\mathbf{n}, \mathbf{c}_{light}=\lim_{\varepsilon \to 0}(\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i)</math></center>
 +
 
 +
Since <math>\mathbf{l_c}=\mathbf{n}</math> and <math>\varepsilon \to 0</math>, we can assume <math>\mathbf{n} \cdot \mathbf{l}=1</math>, which gives us:
 +
 
 +
<center><math>\mathbf{c}_{light}=\lim_{\varepsilon \to 0}(\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i)</math></center>
 +
 
 +
That is:
 +
 
 +
<center><math>\lim_{\varepsilon \to 0}(\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i) = \pi \mathbf{c}_{light}</math></center>
 +
 
 +
Now we shall apply our tiny area light to a general BRDF, and look at its behavior in the limit as goes to 0:
 +
 
 +
<center><math>L_0(\mathbf{v})=\lim_{\varepsilon \to 0}(\int_{\Omega} \rho(\mathbf{l},\mathbf{v}) \otimes L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i)=\rho(\mathbf{l_c}, \mathbf{v}) \otimes \lim_{\varepsilon \to 0}(\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i)(\mathbf{n} \cdot \mathbf{l_c})</math></center>
 +
 
 +
So
 +
 
 +
<center><math>L_0(\mathbf{v})=\pi \rho(\mathbf{l_c}, \mathbf{v}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})</math></center>
 +
 
 +
As you see, the tiny area light source term disappears. The remaining of our equation is what we familar with.
  
 
[[zh:基于物理的BRDF]]
 
[[zh:基于物理的BRDF]]

Revision as of 01:08, 29 December 2010

Introduction

Physically based rendering have been known for many years, but the "ad-hoc" rendering models (such as Phong) are still widely used in game. These "ad-hoc" models require laborious tweaking to produce high-quality images. However, physically based, energy-conserving rendering models easily create materials that hold up under a variety of lighting environments.

Surprisingly, physically based models are not more difficult to implement or evaluate than the traditional "ad-hoc" ones.

Reflectance equation

The most common used rendering model in game describes only reflectance, not including terms such as SSS. The reflectance equation is:

LaTeX: L_0(\mathbf{v})=\int_{\Omega} \rho(\mathbf{l},\mathbf{v}) \otimes L_i(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i

Here LaTeX: \rho(\mathbf{l},\mathbf{v}) is BRDF, LaTeX: L_i(\mathbf{l}) is the contribution from light source, LaTeX: (\mathbf{n} \cdot \mathbf{l}) is the angle between light and surface normal. This integration results the sum of all light sources contribute to a surface point.

Diffuse term

The simplest BRDF is the Lambert. The well-known Lambertian BRDF in game is present as LaTeX: (\mathbf{n} \cdot \mathbf{l}). However, it is part of reflectance equation, and lambertian term is actually a constant value:

LaTeX: \rho_{lambert}(\mathbf{l},\mathbf{v})=\frac{\mathbf{c}_{diff}}{\pi}

Punctual Light Sources

These are classic point, directional, and spot lights in compute games. These local light source can be abstracted to a concept named "punctual light sources". They are infinitely small light with centain direction. Since what we want is the lighting reach a surface point, we don't need to consider the attenuation. A punctual light source are parameterized by the light color LaTeX: \mathbf{c}_{light} and the light direction vector LaTeX: \mathbf{l_c}. The light color LaTeX: \mathbf{c}_{light} is specified as the color a white Lambertian surface would have when illuminated by the light from a direction parallel to the surface normal (LaTeX: \mathbf{l_c}=\mathbf{n}).

How to calculate the contribution from this light source to a point? Here we will start by defining a tiny area light source centered on LaTeX: \mathbf{l_c}, with a small angular extent LaTeX: \varepsilon. This tiny area light illuminates a shaded surface point with the incoming radiance function LaTeX: L_{tiny}(\mathbf{l}). The incoming radiance function has the following two properties:

LaTeX: \forall\mathbf{l}|\angle(\mathbf{l}, \mathbf{l_c})>\varepsilon, L_{tiny}(\mathbf{l})=0
LaTeX: if \mathbf{l_c}=\mathbf{n}, \mathbf{c}_{light}=\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i

The first property says that no light is incoming for any light directions which form an angle greater than LaTeX: \varepsilon with LaTeX: \mathbf{l_c}. The second property follows from the definition of LaTeX: \mathbf{c}_{light}. Since the surface is white, LaTeX: \mathbf{c}_{diff}=1. Applying reflectance equation and Lambert from last article, there's the second property. Because LaTeX: \mathbf{c}_{light} requires LaTeX: \mathbf{l_c}=\mathbf{n}, it is the limit as LaTeX: \varepsilon goes to 0:

LaTeX: if \mathbf{l_c}=\mathbf{n}, \mathbf{c}_{light}=\lim_{\varepsilon \to 0}(\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i)

Since LaTeX: \mathbf{l_c}=\mathbf{n} and LaTeX: \varepsilon \to 0, we can assume LaTeX: \mathbf{n} \cdot \mathbf{l}=1, which gives us:

LaTeX: \mathbf{c}_{light}=\lim_{\varepsilon \to 0}(\frac{1}{\pi}\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i)

That is:

LaTeX: \lim_{\varepsilon \to 0}(\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i) = \pi \mathbf{c}_{light}

Now we shall apply our tiny area light to a general BRDF, and look at its behavior in the limit as goes to 0:

LaTeX: L_0(\mathbf{v})=\lim_{\varepsilon \to 0}(\int_{\Omega} \rho(\mathbf{l},\mathbf{v}) \otimes L_{tiny}(\mathbf{l}) (\mathbf{n} \cdot \mathbf{l}) d\omega_i)=\rho(\mathbf{l_c}, \mathbf{v}) \otimes \lim_{\varepsilon \to 0}(\int_{\Omega} L_{tiny}(\mathbf{l}) d\omega_i)(\mathbf{n} \cdot \mathbf{l_c})

So

LaTeX: L_0(\mathbf{v})=\pi \rho(\mathbf{l_c}, \mathbf{v}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})

As you see, the tiny area light source term disappears. The remaining of our equation is what we familar with.